activerecord-postgis-adapter 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +7 -0
- data/README.rdoc +15 -2
- data/Version +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +18 -2
- data/test/tc_basic.rb +49 -0
- metadata +5 -5
data/History.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 0.2.2 / 2010-12-27
|
2
|
+
|
3
|
+
* Support for basic spatial equality queries. e.g. constructs such as:
|
4
|
+
MyClass.where(:geom_column => factory.point(1, 2))
|
5
|
+
MyClass.where(:geom_column => 'POINT(1 2)')
|
6
|
+
* Fixed an exception when adding spatial columns where the column name is specified as a symbol.
|
7
|
+
|
1
8
|
=== 0.2.1 / 2010-12-15
|
2
9
|
|
3
10
|
* Provides meta-information to RGeo 0.2.2 or later to support access to PostGIS's spatial reference system table.
|
data/README.rdoc
CHANGED
@@ -74,6 +74,19 @@ Now you can interact with the data using the RGeo types:
|
|
74
74
|
# value will be cast from geographic to GEOS.
|
75
75
|
RGeo::Geos.is_geos?(rec.shape) # => true
|
76
76
|
|
77
|
+
You can create simple queries based on spatial equality in the same way
|
78
|
+
you would on a scalar column:
|
79
|
+
|
80
|
+
rec = SpatialTable.where(:latlon => RGeo::Geos.factory.point(-122, 47)).first
|
81
|
+
|
82
|
+
You can also use WKT:
|
83
|
+
|
84
|
+
rec = SpatialTable.where(:latlon => 'POINT(-122 47)').first
|
85
|
+
|
86
|
+
Other types of queries currently must be written in SQL. However, we are
|
87
|
+
investigating writing a set of Arel extensions for constructing arbitrary
|
88
|
+
spatial queries.
|
89
|
+
|
77
90
|
=== Installation
|
78
91
|
|
79
92
|
This adapter has the following requirements:
|
@@ -81,8 +94,8 @@ This adapter has the following requirements:
|
|
81
94
|
* Ruby 1.8.7 or later. Ruby 1.9.2 or later preferred.
|
82
95
|
* PostGIS 1.5 or later.
|
83
96
|
* \ActiveRecord 3.0.3 or later. Earlier versions will not work.
|
84
|
-
* rgeo gem 0.2.
|
85
|
-
* rgeo-activerecord gem 0.2.
|
97
|
+
* rgeo gem 0.2.3 or later.
|
98
|
+
* rgeo-activerecord gem 0.2.1 or later.
|
86
99
|
* pg gem 0.10 or later.
|
87
100
|
|
88
101
|
Install this adapter as a gem:
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -42,7 +42,23 @@ require 'active_record/connection_adapters/postgresql_adapter'
|
|
42
42
|
|
43
43
|
module Arel
|
44
44
|
module Visitors
|
45
|
-
|
45
|
+
|
46
|
+
class PostGIS < PostgreSQL
|
47
|
+
|
48
|
+
FUNC_MAP = {
|
49
|
+
'ST_WKTToSQL' => 'GeomFromEWKT',
|
50
|
+
}
|
51
|
+
|
52
|
+
include ::RGeo::ActiveRecord::SpatialToSql
|
53
|
+
|
54
|
+
def st_func(standard_name_)
|
55
|
+
FUNC_MAP[standard_name_] || standard_name_
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
VISITORS['postgis'] = ::Arel::Visitors::PostGIS
|
61
|
+
|
46
62
|
end
|
47
63
|
end
|
48
64
|
|
@@ -161,7 +177,7 @@ module ActiveRecord
|
|
161
177
|
dimensions_ = 2
|
162
178
|
dimensions_ += 1 if has_z_
|
163
179
|
dimensions_ += 1 if has_m_
|
164
|
-
execute("SELECT AddGeometryColumn('#{quote_string(table_name_)}', '#{quote_string(col_.name)}', #{col_.srid}, '#{quote_string(type_)}', #{dimensions_})")
|
180
|
+
execute("SELECT AddGeometryColumn('#{quote_string(table_name_)}', '#{quote_string(col_.name.to_s)}', #{col_.srid}, '#{quote_string(type_)}', #{dimensions_})")
|
165
181
|
end
|
166
182
|
end
|
167
183
|
|
data/test/tc_basic.rb
CHANGED
@@ -261,6 +261,55 @@ module RGeo
|
|
261
261
|
end
|
262
262
|
|
263
263
|
|
264
|
+
def test_readme_example
|
265
|
+
klass_ = create_ar_class
|
266
|
+
klass_.connection.create_table(:spatial_test) do |t_|
|
267
|
+
t_.column(:latlon, :point)
|
268
|
+
t_.line_string(:path)
|
269
|
+
t_.geometry(:shape)
|
270
|
+
end
|
271
|
+
klass_.connection.change_table(:spatial_test) do |t_|
|
272
|
+
t_.index(:latlon, :spatial => true)
|
273
|
+
end
|
274
|
+
klass_.class_eval do
|
275
|
+
self.rgeo_factory_generator = ::RGeo::Geos.method(:factory)
|
276
|
+
set_rgeo_factory_for_column(:latlon, ::RGeo::Geographic.spherical_factory)
|
277
|
+
end
|
278
|
+
rec_ = klass_.new
|
279
|
+
rec_.latlon = 'POINT(-122 47)'
|
280
|
+
loc_ = rec_.latlon
|
281
|
+
assert_equal(47, loc_.latitude)
|
282
|
+
rec_.shape = loc_
|
283
|
+
assert_equal(true, ::RGeo::Geos.is_geos?(rec_.shape))
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
def test_query_point
|
288
|
+
klass_ = populate_ar_class(:latlon_point)
|
289
|
+
obj_ = klass_.new
|
290
|
+
obj_.latlon = @factory.point(1, 2)
|
291
|
+
obj_.save!
|
292
|
+
id_ = obj_.id
|
293
|
+
obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1, 2)])).first
|
294
|
+
assert_equal(id_, obj2_.id)
|
295
|
+
obj3_ = klass_.where(:latlon => @factory.point(2, 2)).first
|
296
|
+
assert_nil(obj3_)
|
297
|
+
end
|
298
|
+
|
299
|
+
|
300
|
+
def test_query_point_wkt
|
301
|
+
klass_ = populate_ar_class(:latlon_point)
|
302
|
+
obj_ = klass_.new
|
303
|
+
obj_.latlon = @factory.point(1, 2)
|
304
|
+
obj_.save!
|
305
|
+
id_ = obj_.id
|
306
|
+
obj2_ = klass_.where(:latlon => 'SRID=4326;POINT(1 2)').first
|
307
|
+
assert_equal(id_, obj2_.id)
|
308
|
+
obj3_ = klass_.where(:latlon => 'SRID=4326;POINT(2 2)').first
|
309
|
+
assert_nil(obj3_)
|
310
|
+
end
|
311
|
+
|
312
|
+
|
264
313
|
end
|
265
314
|
|
266
315
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Azuma
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-27 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -28,8 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
- 2
|
31
|
-
-
|
32
|
-
version: 0.2.
|
31
|
+
- 1
|
32
|
+
version: 0.2.1
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|