spatial_adapter 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/spatial_adapter/common/spatial_column.rb +12 -14
- data/lib/spatial_adapter/postgresql.rb +1 -1
- data/spec/mysql/migration_spec.rb +2 -2
- data/spec/mysql/schema_dumper_spec.rb +1 -1
- data/spec/postgresql/connection_adapter_spec.rb +0 -2
- data/spec/postgresql/migration_spec.rb +15 -15
- data/spec/postgresql/schema_dumper_spec.rb +2 -2
- data/spec/spec_helper.rb +7 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
@@ -10,6 +10,10 @@ module SpatialAdapter
|
|
10
10
|
@with_m = with_m
|
11
11
|
end
|
12
12
|
|
13
|
+
def spatial?
|
14
|
+
!@geometry_type.nil?
|
15
|
+
end
|
16
|
+
|
13
17
|
def geographic?
|
14
18
|
false
|
15
19
|
end
|
@@ -18,10 +22,7 @@ module SpatialAdapter
|
|
18
22
|
# alias_method :type_cast_without_spatial, :type_cast
|
19
23
|
def type_cast(value)
|
20
24
|
return nil if value.nil?
|
21
|
-
|
22
|
-
when :geometry then self.class.string_to_geometry(value)
|
23
|
-
else super
|
24
|
-
end
|
25
|
+
spatial? ? self.class.string_to_geometry(value) : super
|
25
26
|
end
|
26
27
|
|
27
28
|
#Redefines type_cast_code to add support for geometries.
|
@@ -29,28 +30,25 @@ module SpatialAdapter
|
|
29
30
|
#WARNING : Since ActiveRecord keeps only the string values directly returned from the database, it translates from these to the correct types everytime an attribute is read (using the code returned by this method), which is probably ok for simple types, but might be less than efficient for geometries. Also you cannot modify the geometry object returned directly or your change will not be saved.
|
30
31
|
# alias_method :type_cast_code_without_spatial, :type_cast_code
|
31
32
|
def type_cast_code(var_name)
|
32
|
-
|
33
|
-
when :geometry then "#{self.class.name}.string_to_geometry(#{var_name})"
|
34
|
-
else super
|
35
|
-
end
|
33
|
+
spatial? ? "#{self.class.name}.string_to_geometry(#{var_name})" : super
|
36
34
|
end
|
37
35
|
|
38
36
|
|
39
37
|
#Redefines klass to add support for geometries
|
40
38
|
# alias_method :klass_without_spatial, :klass
|
41
39
|
def klass
|
42
|
-
|
43
|
-
when :geometry then GeoRuby::SimpleFeatures::Geometry
|
44
|
-
else super
|
45
|
-
end
|
40
|
+
spatial? ? GeoRuby::SimpleFeatures::Geometry : super
|
46
41
|
end
|
47
42
|
|
48
43
|
private
|
49
44
|
|
50
|
-
#
|
45
|
+
# Maps additional data types to base Rails/Arel types
|
46
|
+
#
|
47
|
+
# For Rails 3, only the types defined by Arel can be used. We'll
|
48
|
+
# use :string since the database returns the columns as hex strings.
|
51
49
|
def simplified_type(field_type)
|
52
50
|
case field_type
|
53
|
-
when /geography|geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i then :
|
51
|
+
when /geography|geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geometrycollection/i then :string
|
54
52
|
else super
|
55
53
|
end
|
56
54
|
end
|
@@ -99,7 +99,7 @@ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
|
|
99
99
|
columns(table_name).each do |col|
|
100
100
|
if column_names.include?(col.name.to_sym)
|
101
101
|
# Geometry columns have to be removed using DropGeometryColumn
|
102
|
-
if col.
|
102
|
+
if col.spatial? && !col.geographic?
|
103
103
|
execute "SELECT DropGeometryColumn('#{table_name}','#{col.name}')"
|
104
104
|
else
|
105
105
|
original_remove_column(table_name, col.name)
|
@@ -27,7 +27,7 @@ describe "Spatially-enabled Migrations" do
|
|
27
27
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
28
28
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
29
29
|
geom_column.geometry_type.should == type
|
30
|
-
geom_column.type.should == :
|
30
|
+
geom_column.type.should == :string
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -54,7 +54,7 @@ describe "Spatially-enabled Migrations" do
|
|
54
54
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
55
55
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
56
56
|
geom_column.geometry_type.should == type
|
57
|
-
geom_column.type.should == :
|
57
|
+
geom_column.type.should == :string
|
58
58
|
geom_column.with_z.should == false
|
59
59
|
geom_column.with_m.should == false
|
60
60
|
geom_column.srid.should == -1
|
@@ -41,7 +41,7 @@ describe "Spatially-enabled Schema Dumps" do
|
|
41
41
|
geom_column = columns.select{|c| c.name == 'geom'}.first
|
42
42
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
43
43
|
geom_column.geometry_type.should == :point
|
44
|
-
geom_column.type.should == :
|
44
|
+
geom_column.type.should == :string
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should preserve spatial indexes" do
|
@@ -80,7 +80,6 @@ describe "Modified PostgreSQLAdapter" do
|
|
80
80
|
it "should be a regular SpatialPostgreSQLColumn if column is a geometry data type" do
|
81
81
|
column = PointModel.columns.select{|c| c.name == 'geom'}.first
|
82
82
|
column.should be_a(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
|
83
|
-
column.type.should == :geometry
|
84
83
|
column.geometry_type.should == :point
|
85
84
|
column.should_not be_geographic
|
86
85
|
end
|
@@ -88,7 +87,6 @@ describe "Modified PostgreSQLAdapter" do
|
|
88
87
|
it "should be a geographic SpatialPostgreSQLColumn if column is a geography data type" do
|
89
88
|
column = GeographyPointModel.columns.select{|c| c.name == 'geom'}.first
|
90
89
|
column.should be_a(ActiveRecord::ConnectionAdapters::SpatialPostgreSQLColumn)
|
91
|
-
column.type.should == :geometry
|
92
90
|
column.geometry_type.should == :point
|
93
91
|
column.should be_geographic
|
94
92
|
end
|
@@ -26,7 +26,7 @@ describe "Spatially-enabled Migrations" do
|
|
26
26
|
|
27
27
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
28
28
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
29
|
-
geom_column.type.should == :
|
29
|
+
geom_column.type.should == :string
|
30
30
|
geom_column.geometry_type.should == type
|
31
31
|
geom_column.should_not be_geographic
|
32
32
|
geom_column.with_z.should == false
|
@@ -45,7 +45,7 @@ describe "Spatially-enabled Migrations" do
|
|
45
45
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
46
46
|
|
47
47
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
48
|
-
geom_column.type.should == :
|
48
|
+
geom_column.type.should == :string
|
49
49
|
geom_column.geometry_type.should == type
|
50
50
|
geom_column.should be_geographic
|
51
51
|
geom_column.with_z.should == false
|
@@ -82,7 +82,7 @@ describe "Spatially-enabled Migrations" do
|
|
82
82
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
83
83
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
84
84
|
geom_column.geometry_type.should == :point
|
85
|
-
geom_column.type.should == :
|
85
|
+
geom_column.type.should == :string
|
86
86
|
geom_column.with_z.should == false
|
87
87
|
geom_column.with_m.should == true
|
88
88
|
geom_column.srid.should == -1
|
@@ -100,7 +100,7 @@ describe "Spatially-enabled Migrations" do
|
|
100
100
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
101
101
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
102
102
|
geom_column.geometry_type.should == :point
|
103
|
-
geom_column.type.should == :
|
103
|
+
geom_column.type.should == :string
|
104
104
|
geom_column.with_z.should == true
|
105
105
|
geom_column.with_m.should == true
|
106
106
|
geom_column.srid.should == -1
|
@@ -133,7 +133,7 @@ describe "Spatially-enabled Migrations" do
|
|
133
133
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
134
134
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
135
135
|
geom_column.geometry_type.should == :point
|
136
|
-
geom_column.type.should == :
|
136
|
+
geom_column.type.should == :string
|
137
137
|
geom_column.should be_geographic
|
138
138
|
geom_column.with_z.should == false
|
139
139
|
geom_column.with_m.should == true
|
@@ -152,7 +152,7 @@ describe "Spatially-enabled Migrations" do
|
|
152
152
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
153
153
|
geom_column.geometry_type.should == :point
|
154
154
|
geom_column.should be_geographic
|
155
|
-
geom_column.type.should == :
|
155
|
+
geom_column.type.should == :string
|
156
156
|
geom_column.with_z.should == true
|
157
157
|
geom_column.with_m.should == true
|
158
158
|
end
|
@@ -168,7 +168,7 @@ describe "Spatially-enabled Migrations" do
|
|
168
168
|
|
169
169
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
170
170
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
171
|
-
geom_column.type.should == :
|
171
|
+
geom_column.type.should == :string
|
172
172
|
geom_column.geometry_type.should == :geometry
|
173
173
|
geom_column.with_z.should == false
|
174
174
|
geom_column.with_m.should == false
|
@@ -197,7 +197,7 @@ describe "Spatially-enabled Migrations" do
|
|
197
197
|
|
198
198
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
199
199
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
200
|
-
geom_column.type.should == :
|
200
|
+
geom_column.type.should == :string
|
201
201
|
geom_column.geometry_type.should == type
|
202
202
|
geom_column.with_z.should == false
|
203
203
|
geom_column.with_m.should == false
|
@@ -212,7 +212,7 @@ describe "Spatially-enabled Migrations" do
|
|
212
212
|
|
213
213
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
214
214
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
215
|
-
geom_column.type.should == :
|
215
|
+
geom_column.type.should == :string
|
216
216
|
geom_column.geometry_type.should == :point
|
217
217
|
geom_column.with_z.should == true
|
218
218
|
geom_column.with_m.should == false
|
@@ -227,7 +227,7 @@ describe "Spatially-enabled Migrations" do
|
|
227
227
|
|
228
228
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
229
229
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
230
|
-
geom_column.type.should == :
|
230
|
+
geom_column.type.should == :string
|
231
231
|
geom_column.geometry_type.should == :point
|
232
232
|
geom_column.with_z.should == false
|
233
233
|
geom_column.with_m.should == true
|
@@ -242,7 +242,7 @@ describe "Spatially-enabled Migrations" do
|
|
242
242
|
|
243
243
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
244
244
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
245
|
-
geom_column.type.should == :
|
245
|
+
geom_column.type.should == :string
|
246
246
|
geom_column.geometry_type.should == :point
|
247
247
|
geom_column.with_z.should == true
|
248
248
|
geom_column.with_m.should == true
|
@@ -256,7 +256,7 @@ describe "Spatially-enabled Migrations" do
|
|
256
256
|
|
257
257
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
258
258
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
259
|
-
geom_column.type.should == :
|
259
|
+
geom_column.type.should == :string
|
260
260
|
geom_column.should be_geographic
|
261
261
|
geom_column.geometry_type.should == :point
|
262
262
|
geom_column.with_z.should == true
|
@@ -271,7 +271,7 @@ describe "Spatially-enabled Migrations" do
|
|
271
271
|
|
272
272
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
273
273
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
274
|
-
geom_column.type.should == :
|
274
|
+
geom_column.type.should == :string
|
275
275
|
geom_column.should be_geographic
|
276
276
|
geom_column.geometry_type.should == :point
|
277
277
|
geom_column.with_z.should == false
|
@@ -286,7 +286,7 @@ describe "Spatially-enabled Migrations" do
|
|
286
286
|
|
287
287
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
288
288
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
289
|
-
geom_column.type.should == :
|
289
|
+
geom_column.type.should == :string
|
290
290
|
geom_column.should be_geographic
|
291
291
|
geom_column.geometry_type.should == :point
|
292
292
|
geom_column.with_z.should == true
|
@@ -301,7 +301,7 @@ describe "Spatially-enabled Migrations" do
|
|
301
301
|
geom_column = @connection.columns(:migrated_geometry_models).select{|c| c.name == 'geom'}.first
|
302
302
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
303
303
|
geom_column.geometry_type.should == :geometry
|
304
|
-
geom_column.type.should == :
|
304
|
+
geom_column.type.should == :string
|
305
305
|
geom_column.with_z.should == false
|
306
306
|
geom_column.with_m.should == false
|
307
307
|
geom_column.srid.should == 4326
|
@@ -48,7 +48,7 @@ describe "Spatially-enabled Schema Dumps" do
|
|
48
48
|
geom_column = columns.select{|c| c.name == 'geom'}.first
|
49
49
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
50
50
|
geom_column.geometry_type.should == :point
|
51
|
-
geom_column.type.should == :
|
51
|
+
geom_column.type.should == :string
|
52
52
|
geom_column.with_z.should == true
|
53
53
|
geom_column.with_m.should == true
|
54
54
|
geom_column.srid.should == 4326
|
@@ -61,7 +61,7 @@ describe "Spatially-enabled Schema Dumps" do
|
|
61
61
|
geom_column = columns.select{|c| c.name == 'geom'}.first
|
62
62
|
geom_column.should be_a(SpatialAdapter::SpatialColumn)
|
63
63
|
geom_column.geometry_type.should == :point
|
64
|
-
geom_column.type.should == :
|
64
|
+
geom_column.type.should == :string
|
65
65
|
geom_column.with_z.should == true
|
66
66
|
geom_column.with_m.should == true
|
67
67
|
geom_column.should be_geographic
|
data/spec/spec_helper.rb
CHANGED
@@ -2,14 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'spec'
|
3
3
|
require 'geo_ruby'
|
4
4
|
gem 'activerecord', '=2.3.5'
|
5
|
+
#gem 'activerecord', '=3.0.0.beta3'
|
5
6
|
require 'active_record'
|
6
7
|
|
7
8
|
$:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
|
8
9
|
|
9
10
|
include GeoRuby::SimpleFeatures
|
10
11
|
|
11
|
-
# Don't output migration logging
|
12
|
-
ActiveRecord::Migration.verbose = false
|
13
12
|
|
14
13
|
def postgis_connection
|
15
14
|
ActiveRecord::Base.establish_connection(
|
@@ -18,6 +17,9 @@ def postgis_connection
|
|
18
17
|
)
|
19
18
|
# Turn off those annoying NOTICE messages
|
20
19
|
ActiveRecord::Base.connection.execute 'set client_min_messages = warning'
|
20
|
+
|
21
|
+
# Don't output migration logging
|
22
|
+
ActiveRecord::Migration.verbose = false
|
21
23
|
end
|
22
24
|
|
23
25
|
def mysql_connection
|
@@ -27,6 +29,9 @@ def mysql_connection
|
|
27
29
|
:username => 'root',
|
28
30
|
:host => 'localhost'
|
29
31
|
)
|
32
|
+
|
33
|
+
# Don't output migration logging
|
34
|
+
ActiveRecord::Migration.verbose = false
|
30
35
|
end
|
31
36
|
|
32
37
|
class GeometryFactory
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pete Deffendol
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-20 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|