rs_spatial_adapter 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +197 -0
- data/VERSION +1 -0
- data/lib/spatial_adapter.rb +41 -0
- data/lib/spatial_adapter/common/raw_geom_info.rb +23 -0
- data/lib/spatial_adapter/common/schema_definitions.rb +11 -0
- data/lib/spatial_adapter/common/schema_dumper.rb +136 -0
- data/lib/spatial_adapter/common/spatial_column.rb +70 -0
- data/lib/spatial_adapter/common/table_definition.rb +14 -0
- data/lib/spatial_adapter/mysql.rb +98 -0
- data/lib/spatial_adapter/mysql2.rb +97 -0
- data/lib/spatial_adapter/postgresql.rb +388 -0
- data/lib/spatial_adapter/railtie.rb +13 -0
- data/rails/init.rb +11 -0
- data/spec/README.txt +22 -0
- data/spec/db/mysql2_raw.rb +70 -0
- data/spec/db/mysql_raw.rb +70 -0
- data/spec/db/postgis_raw.rb +190 -0
- data/spec/models/common.rb +65 -0
- data/spec/mysql/connection_adapter_spec.rb +106 -0
- data/spec/mysql/migration_spec.rb +64 -0
- data/spec/mysql/models_spec.rb +65 -0
- data/spec/mysql/schema_dumper_spec.rb +56 -0
- data/spec/mysql2/connection_adapter_spec.rb +106 -0
- data/spec/mysql2/migration_spec.rb +64 -0
- data/spec/mysql2/models_spec.rb +65 -0
- data/spec/mysql2/schema_dumper_spec.rb +56 -0
- data/spec/postgresql/connection_adapter_spec.rb +227 -0
- data/spec/postgresql/migration_spec.rb +365 -0
- data/spec/postgresql/models_spec.rb +221 -0
- data/spec/postgresql/schema_dumper_spec.rb +79 -0
- data/spec/shared_examples.rb +43 -0
- data/spec/spec_helper.rb +90 -0
- metadata +131 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
module SpatialAdapter
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "spatial_adapter.load_current_database_adapter" do
|
4
|
+
adapter = Rails.configuration.database_configuration[Rails.env]['adapter']
|
5
|
+
begin
|
6
|
+
require "spatial_adapter/#{adapter}"
|
7
|
+
rescue LoadError
|
8
|
+
raise SpatialAdapter::NotCompatibleError.new("spatial_adapter does not currently support the #{adapter} database.")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/rails/init.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Rails initialization (for Rails 2.x)
|
2
|
+
#
|
3
|
+
# This will load the adapter for the currently used database configuration, if
|
4
|
+
# it exists.
|
5
|
+
|
6
|
+
begin
|
7
|
+
adapter = ActiveRecord::Base.configurations[RAILS_ENV]['adapter']
|
8
|
+
require "spatial_adapter/#{adapter}"
|
9
|
+
rescue LoadError
|
10
|
+
raise SpatialAdapter::NotCompatibleError.new("spatial_adapter does not currently support the #{adapter} database.")
|
11
|
+
end
|
data/spec/README.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= Running Tests
|
2
|
+
|
3
|
+
You will need to set up empty databases for each adapter you want to test.
|
4
|
+
|
5
|
+
== PostgreSQL
|
6
|
+
|
7
|
+
Create an empty database "spatial_adapter" and ensure that the PostGIS extensions are loaded.
|
8
|
+
|
9
|
+
run "rake spec:postgresql" to run the specs
|
10
|
+
|
11
|
+
== MySQL
|
12
|
+
|
13
|
+
Create an empty database "spatial_adapter" - the spatial extensions are already available.
|
14
|
+
|
15
|
+
run "rake spec:mysql" to run the specs
|
16
|
+
|
17
|
+
== MySQL2
|
18
|
+
|
19
|
+
Create an empty database "spatial_adapter" - the spatial extensions are already available.
|
20
|
+
|
21
|
+
run "rake spec:mysql2" to run the specs
|
22
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
mysql2_connection
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define() do
|
4
|
+
execute "drop table if exists point_models"
|
5
|
+
execute "create table point_models
|
6
|
+
(
|
7
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
8
|
+
extra varchar(255),
|
9
|
+
more_extra varchar(255),
|
10
|
+
geom point not null
|
11
|
+
) ENGINE=MyISAM"
|
12
|
+
execute "create spatial index index_point_models_on_geom on point_models (geom)"
|
13
|
+
execute "create index index_point_models_on_extra on point_models (extra, more_extra)"
|
14
|
+
|
15
|
+
execute "drop table if exists line_string_models"
|
16
|
+
execute "create table line_string_models
|
17
|
+
(
|
18
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
19
|
+
extra varchar(255),
|
20
|
+
geom linestring
|
21
|
+
) ENGINE=MyISAM"
|
22
|
+
|
23
|
+
execute "drop table if exists polygon_models"
|
24
|
+
execute "create table polygon_models
|
25
|
+
(
|
26
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
27
|
+
extra varchar(255),
|
28
|
+
geom polygon
|
29
|
+
) ENGINE=MyISAM"
|
30
|
+
|
31
|
+
execute "drop table if exists multi_point_models"
|
32
|
+
execute "create table multi_point_models
|
33
|
+
(
|
34
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
35
|
+
extra varchar(255),
|
36
|
+
geom multipoint
|
37
|
+
) ENGINE=MyISAM"
|
38
|
+
|
39
|
+
execute "drop table if exists multi_line_string_models"
|
40
|
+
execute "create table multi_line_string_models
|
41
|
+
(
|
42
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
43
|
+
extra varchar(255),
|
44
|
+
geom multilinestring
|
45
|
+
) ENGINE=MyISAM"
|
46
|
+
|
47
|
+
execute "drop table if exists multi_polygon_models"
|
48
|
+
execute "create table multi_polygon_models
|
49
|
+
(
|
50
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
51
|
+
extra varchar(255),
|
52
|
+
geom multipolygon
|
53
|
+
) ENGINE=MyISAM"
|
54
|
+
|
55
|
+
execute "drop table if exists geometry_collection_models"
|
56
|
+
execute "create table geometry_collection_models
|
57
|
+
(
|
58
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
59
|
+
extra varchar(255),
|
60
|
+
geom geometrycollection
|
61
|
+
) ENGINE=MyISAM"
|
62
|
+
|
63
|
+
execute "drop table if exists geometry_models"
|
64
|
+
execute "create table geometry_models
|
65
|
+
(
|
66
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
67
|
+
extra varchar(255),
|
68
|
+
geom geometry
|
69
|
+
) ENGINE=MyISAM"
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
mysql_connection
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define() do
|
4
|
+
execute "drop table if exists point_models"
|
5
|
+
execute "create table point_models
|
6
|
+
(
|
7
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
8
|
+
extra varchar(255),
|
9
|
+
more_extra varchar(255),
|
10
|
+
geom point not null
|
11
|
+
) ENGINE=MyISAM"
|
12
|
+
execute "create spatial index index_point_models_on_geom on point_models (geom)"
|
13
|
+
execute "create index index_point_models_on_extra on point_models (extra, more_extra)"
|
14
|
+
|
15
|
+
execute "drop table if exists line_string_models"
|
16
|
+
execute "create table line_string_models
|
17
|
+
(
|
18
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
19
|
+
extra varchar(255),
|
20
|
+
geom linestring
|
21
|
+
) ENGINE=MyISAM"
|
22
|
+
|
23
|
+
execute "drop table if exists polygon_models"
|
24
|
+
execute "create table polygon_models
|
25
|
+
(
|
26
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
27
|
+
extra varchar(255),
|
28
|
+
geom polygon
|
29
|
+
) ENGINE=MyISAM"
|
30
|
+
|
31
|
+
execute "drop table if exists multi_point_models"
|
32
|
+
execute "create table multi_point_models
|
33
|
+
(
|
34
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
35
|
+
extra varchar(255),
|
36
|
+
geom multipoint
|
37
|
+
) ENGINE=MyISAM"
|
38
|
+
|
39
|
+
execute "drop table if exists multi_line_string_models"
|
40
|
+
execute "create table multi_line_string_models
|
41
|
+
(
|
42
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
43
|
+
extra varchar(255),
|
44
|
+
geom multilinestring
|
45
|
+
) ENGINE=MyISAM"
|
46
|
+
|
47
|
+
execute "drop table if exists multi_polygon_models"
|
48
|
+
execute "create table multi_polygon_models
|
49
|
+
(
|
50
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
51
|
+
extra varchar(255),
|
52
|
+
geom multipolygon
|
53
|
+
) ENGINE=MyISAM"
|
54
|
+
|
55
|
+
execute "drop table if exists geometry_collection_models"
|
56
|
+
execute "create table geometry_collection_models
|
57
|
+
(
|
58
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
59
|
+
extra varchar(255),
|
60
|
+
geom geometrycollection
|
61
|
+
) ENGINE=MyISAM"
|
62
|
+
|
63
|
+
execute "drop table if exists geometry_models"
|
64
|
+
execute "create table geometry_models
|
65
|
+
(
|
66
|
+
id int(11) DEFAULT NULL auto_increment PRIMARY KEY,
|
67
|
+
extra varchar(255),
|
68
|
+
geom geometry
|
69
|
+
) ENGINE=MyISAM"
|
70
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
postgis_connection
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define() do
|
4
|
+
execute <<-SQL
|
5
|
+
drop table if exists point_models;
|
6
|
+
create table point_models
|
7
|
+
(
|
8
|
+
id serial primary key,
|
9
|
+
extra varchar(255),
|
10
|
+
more_extra varchar(255)
|
11
|
+
);
|
12
|
+
select AddGeometryColumn('point_models', 'geom', 4326, 'POINT', 2);
|
13
|
+
create index index_point_models_on_geom on point_models using gist (geom);
|
14
|
+
create index index_point_models_on_extra on point_models (extra, more_extra);
|
15
|
+
|
16
|
+
drop table if exists line_string_models;
|
17
|
+
create table line_string_models
|
18
|
+
(
|
19
|
+
id serial primary key,
|
20
|
+
extra varchar(255)
|
21
|
+
);
|
22
|
+
select AddGeometryColumn('line_string_models', 'geom', 4326, 'LINESTRING', 2);
|
23
|
+
|
24
|
+
drop table if exists polygon_models;
|
25
|
+
create table polygon_models
|
26
|
+
(
|
27
|
+
id serial primary key,
|
28
|
+
extra varchar(255)
|
29
|
+
);
|
30
|
+
select AddGeometryColumn('polygon_models', 'geom', 4326, 'POLYGON', 2);
|
31
|
+
|
32
|
+
drop table if exists multi_point_models;
|
33
|
+
create table multi_point_models
|
34
|
+
(
|
35
|
+
id serial primary key,
|
36
|
+
extra varchar(255)
|
37
|
+
);
|
38
|
+
select AddGeometryColumn('multi_point_models', 'geom', 4326, 'MULTIPOINT', 2);
|
39
|
+
|
40
|
+
drop table if exists multi_line_string_models;
|
41
|
+
create table multi_line_string_models
|
42
|
+
(
|
43
|
+
id serial primary key,
|
44
|
+
extra varchar(255)
|
45
|
+
);
|
46
|
+
select AddGeometryColumn('multi_line_string_models', 'geom', 4326, 'MULTILINESTRING', 2);
|
47
|
+
|
48
|
+
drop table if exists multi_polygon_models;
|
49
|
+
create table multi_polygon_models
|
50
|
+
(
|
51
|
+
id serial primary key,
|
52
|
+
extra varchar(255)
|
53
|
+
);
|
54
|
+
select AddGeometryColumn('multi_polygon_models', 'geom', 4326, 'MULTIPOLYGON', 2);
|
55
|
+
|
56
|
+
drop table if exists geometry_collection_models;
|
57
|
+
create table geometry_collection_models
|
58
|
+
(
|
59
|
+
id serial primary key,
|
60
|
+
extra varchar(255)
|
61
|
+
);
|
62
|
+
select AddGeometryColumn('geometry_collection_models', 'geom', 4326, 'GEOMETRYCOLLECTION', 2);
|
63
|
+
|
64
|
+
drop table if exists geometry_models;
|
65
|
+
create table geometry_models
|
66
|
+
(
|
67
|
+
id serial primary key,
|
68
|
+
extra varchar(255)
|
69
|
+
);
|
70
|
+
select AddGeometryColumn('geometry_models', 'geom', 4326, 'GEOMETRY', 2);
|
71
|
+
|
72
|
+
drop table if exists pointz_models;
|
73
|
+
create table pointz_models
|
74
|
+
(
|
75
|
+
id serial primary key,
|
76
|
+
extra varchar(255)
|
77
|
+
);
|
78
|
+
select AddGeometryColumn('pointz_models', 'geom', 4326, 'POINT', 3);
|
79
|
+
|
80
|
+
drop table if exists pointm_models;
|
81
|
+
create table pointm_models
|
82
|
+
(
|
83
|
+
id serial primary key,
|
84
|
+
extra varchar(255)
|
85
|
+
);
|
86
|
+
select AddGeometryColumn('pointm_models', 'geom', 4326, 'POINTM', 3);
|
87
|
+
|
88
|
+
drop table if exists point4_models;
|
89
|
+
create table point4_models
|
90
|
+
(
|
91
|
+
id serial primary key,
|
92
|
+
extra varchar(255)
|
93
|
+
);
|
94
|
+
select AddGeometryColumn('point4_models', 'geom', 4326, 'POINT', 4);
|
95
|
+
SQL
|
96
|
+
|
97
|
+
if ActiveRecord::Base.connection.supports_geographic?
|
98
|
+
execute <<-SQL
|
99
|
+
drop table if exists geography_point_models;
|
100
|
+
create table geography_point_models
|
101
|
+
(
|
102
|
+
id serial primary key,
|
103
|
+
extra varchar(255),
|
104
|
+
geom geography(POINT)
|
105
|
+
);
|
106
|
+
create index index_geography_point_models_on_geom on geography_point_models using gist (geom);
|
107
|
+
create index index_geography_point_models_on_extra on geography_point_models (extra);
|
108
|
+
|
109
|
+
drop table if exists geography_line_string_models;
|
110
|
+
create table geography_line_string_models
|
111
|
+
(
|
112
|
+
id serial primary key,
|
113
|
+
extra varchar(255),
|
114
|
+
geom geography(LINESTRING)
|
115
|
+
);
|
116
|
+
|
117
|
+
drop table if exists geography_polygon_models;
|
118
|
+
create table geography_polygon_models
|
119
|
+
(
|
120
|
+
id serial primary key,
|
121
|
+
extra varchar(255),
|
122
|
+
geom geography(POLYGON)
|
123
|
+
);
|
124
|
+
|
125
|
+
drop table if exists geography_multi_point_models;
|
126
|
+
create table geography_multi_point_models
|
127
|
+
(
|
128
|
+
id serial primary key,
|
129
|
+
extra varchar(255),
|
130
|
+
geom geography(MULTIPOINT)
|
131
|
+
);
|
132
|
+
|
133
|
+
drop table if exists geography_multi_line_string_models;
|
134
|
+
create table geography_multi_line_string_models
|
135
|
+
(
|
136
|
+
id serial primary key,
|
137
|
+
extra varchar(255),
|
138
|
+
geom geography(MULTILINESTRING)
|
139
|
+
);
|
140
|
+
|
141
|
+
drop table if exists geography_multi_polygon_models;
|
142
|
+
create table geography_multi_polygon_models
|
143
|
+
(
|
144
|
+
id serial primary key,
|
145
|
+
extra varchar(255),
|
146
|
+
geom geography(MULTIPOLYGON)
|
147
|
+
);
|
148
|
+
|
149
|
+
drop table if exists geography_geometry_collection_models;
|
150
|
+
create table geography_geometry_collection_models
|
151
|
+
(
|
152
|
+
id serial primary key,
|
153
|
+
extra varchar(255),
|
154
|
+
geom geography(GEOMETRYCOLLECTION)
|
155
|
+
);
|
156
|
+
|
157
|
+
drop table if exists geography_models;
|
158
|
+
create table geography_models
|
159
|
+
(
|
160
|
+
id serial primary key,
|
161
|
+
extra varchar(255),
|
162
|
+
geom geography
|
163
|
+
);
|
164
|
+
|
165
|
+
drop table if exists geography_pointz_models;
|
166
|
+
create table geography_pointz_models
|
167
|
+
(
|
168
|
+
id serial primary key,
|
169
|
+
extra varchar(255),
|
170
|
+
geom geography(POINTZ)
|
171
|
+
);
|
172
|
+
|
173
|
+
drop table if exists geography_pointm_models;
|
174
|
+
create table geography_pointm_models
|
175
|
+
(
|
176
|
+
id serial primary key,
|
177
|
+
extra varchar(255),
|
178
|
+
geom geography(POINTM)
|
179
|
+
);
|
180
|
+
|
181
|
+
drop table if exists geography_point4_models;
|
182
|
+
create table geography_point4_models
|
183
|
+
(
|
184
|
+
id serial primary key,
|
185
|
+
extra varchar(255),
|
186
|
+
geom geography(POINTZM)
|
187
|
+
);
|
188
|
+
SQL
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class PointModel < ActiveRecord::Base
|
2
|
+
end
|
3
|
+
|
4
|
+
class LineStringModel < ActiveRecord::Base
|
5
|
+
end
|
6
|
+
|
7
|
+
class PolygonModel < ActiveRecord::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
class MultiPointModel < ActiveRecord::Base
|
11
|
+
end
|
12
|
+
|
13
|
+
class MultiLineStringModel < ActiveRecord::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
class MultiPolygonModel < ActiveRecord::Base
|
17
|
+
end
|
18
|
+
|
19
|
+
class GeometryCollectionModel < ActiveRecord::Base
|
20
|
+
end
|
21
|
+
|
22
|
+
class GeometryModel < ActiveRecord::Base
|
23
|
+
end
|
24
|
+
|
25
|
+
class PointzModel < ActiveRecord::Base
|
26
|
+
end
|
27
|
+
|
28
|
+
class PointmModel < ActiveRecord::Base
|
29
|
+
end
|
30
|
+
|
31
|
+
class Point4Model < ActiveRecord::Base
|
32
|
+
end
|
33
|
+
|
34
|
+
class GeographyPointModel < ActiveRecord::Base
|
35
|
+
end
|
36
|
+
|
37
|
+
class GeographyLineStringModel < ActiveRecord::Base
|
38
|
+
end
|
39
|
+
|
40
|
+
class GeographyPolygonModel < ActiveRecord::Base
|
41
|
+
end
|
42
|
+
|
43
|
+
class GeographyMultiPointModel < ActiveRecord::Base
|
44
|
+
end
|
45
|
+
|
46
|
+
class GeographyMultiLineStringModel < ActiveRecord::Base
|
47
|
+
end
|
48
|
+
|
49
|
+
class GeographyMultiPolygonModel < ActiveRecord::Base
|
50
|
+
end
|
51
|
+
|
52
|
+
class GeographyGeometryCollectionModel < ActiveRecord::Base
|
53
|
+
end
|
54
|
+
|
55
|
+
class GeographyModel < ActiveRecord::Base
|
56
|
+
end
|
57
|
+
|
58
|
+
class GeographyPointzModel < ActiveRecord::Base
|
59
|
+
end
|
60
|
+
|
61
|
+
class GeographyPointmModel < ActiveRecord::Base
|
62
|
+
end
|
63
|
+
|
64
|
+
class GeographyPoint4Model < ActiveRecord::Base
|
65
|
+
end
|