activerecord-mysql2spatial-adapter 0.2.0 → 0.2.1

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 CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.2.1 / 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
+
1
7
  === 0.2.0 / 2010-12-07
2
8
 
3
9
  * Initial public alpha release. Spun activerecord-mysql2spatial-adapter off from the core rgeo gem.
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
  * MySQL server 5.0 or later required for spatial extensions.
83
96
  * \ActiveRecord 3.0.3 or later. Earlier versions will not work.
84
- * rgeo gem 0.2.0 or later.
85
- * rgeo-activerecord gem 0.2.0 or later.
97
+ * rgeo gem 0.2.3 or later.
98
+ * rgeo-activerecord gem 0.2.1 or later.
86
99
  * mysql2 gem 0.2.6 or later.
87
100
 
88
101
  Install this adapter as a gem:
data/Version CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -42,7 +42,24 @@ require 'active_record/connection_adapters/mysql2_adapter'
42
42
 
43
43
  module Arel
44
44
  module Visitors
45
- VISITORS['mysql2spatial'] = ::Arel::Visitors::MySQL
45
+
46
+ class MySQL2Spatial < MySQL
47
+
48
+ FUNC_MAP = {
49
+ 'ST_WKTToSQL' => 'GeomFromText',
50
+ 'ST_Equals' => 'Equals',
51
+ }
52
+
53
+ include ::RGeo::ActiveRecord::SpatialToSql
54
+
55
+ def st_func(standard_name_)
56
+ FUNC_MAP[standard_name_] || standard_name_
57
+ end
58
+
59
+ end
60
+
61
+ VISITORS['mysql2spatial'] = ::Arel::Visitors::MySQL2Spatial
62
+
46
63
  end
47
64
  end
48
65
 
data/test/tc_basic.rb CHANGED
@@ -161,6 +161,32 @@ module RGeo
161
161
  end
162
162
 
163
163
 
164
+ def test_query_point
165
+ klass_ = populate_ar_class(:latlon_point)
166
+ obj_ = klass_.new
167
+ obj_.latlon = @factory.point(1, 2)
168
+ obj_.save!
169
+ id_ = obj_.id
170
+ obj2_ = klass_.where(:latlon => @factory.multi_point([@factory.point(1, 2)])).first
171
+ assert_equal(id_, obj2_.id)
172
+ obj3_ = klass_.where(:latlon => @factory.point(2, 2)).first
173
+ assert_nil(obj3_)
174
+ end
175
+
176
+
177
+ def test_query_point_wkt
178
+ klass_ = populate_ar_class(:latlon_point)
179
+ obj_ = klass_.new
180
+ obj_.latlon = @factory.point(1, 2)
181
+ obj_.save!
182
+ id_ = obj_.id
183
+ obj2_ = klass_.where(:latlon => 'POINT(1 2)').first
184
+ assert_equal(id_, obj2_.id)
185
+ obj3_ = klass_.where(:latlon => 'POINT(2 2)').first
186
+ assert_nil(obj3_)
187
+ end
188
+
189
+
164
190
  end
165
191
 
166
192
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
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-07 00:00:00 -08:00
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
- - 0
32
- version: 0.2.0
31
+ - 1
32
+ version: 0.2.1
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -95,6 +95,6 @@ rubyforge_project: virtuoso
95
95
  rubygems_version: 1.3.7
96
96
  signing_key:
97
97
  specification_version: 3
98
- summary: An ActiveRecord adapter for MySQL Spatial Extensions, based on the mysql2 and rgeo gems.
98
+ summary: An ActiveRecord adapter for MySQL Spatial Extensions, based on RGeo and the mysql2 gem.
99
99
  test_files:
100
100
  - test/tc_basic.rb