rgeo-activerecord 0.4.1 → 0.4.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 +5 -0
- data/README.rdoc +4 -4
- data/Version +1 -1
- data/lib/rgeo-activerecord.rb +36 -0
- data/lib/rgeo/active_record.rb +13 -13
- data/lib/rgeo/active_record/adapter_test_helper.rb +33 -33
- data/lib/rgeo/active_record/ar_factory_settings.rb +75 -71
- data/lib/rgeo/active_record/arel_spatial_queries.rb +63 -63
- data/lib/rgeo/active_record/common_adapter_elements.rb +36 -36
- data/lib/rgeo/active_record/geometry_mixin.rb +30 -30
- data/lib/rgeo/active_record/spatial_expressions.rb +86 -86
- data/lib/rgeo/active_record/task_hacker.rb +30 -30
- data/lib/rgeo/active_record/version.rb +12 -12
- data/test/tc_basic.rb +34 -30
- metadata +11 -10
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
2
|
+
#
|
3
|
+
# Spatial expressions for Arel
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,280 +35,280 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module ActiveRecord
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# Returns true if spatial expressions (i.e. the methods in the
|
43
43
|
# SpatialExpressions module) are supported. Generally, this is true
|
44
44
|
# if Arel is at version 2.1 or later.
|
45
|
-
|
45
|
+
|
46
46
|
def self.spatial_expressions_supported?
|
47
47
|
defined?(::Arel::Nodes::NamedFunction)
|
48
48
|
end
|
49
|
-
|
50
|
-
|
49
|
+
|
50
|
+
|
51
51
|
# A set of spatial expression builders.
|
52
52
|
# These methods can be chained off other spatial expressions to form
|
53
53
|
# complex expressions.
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# These functions require Arel 2.1 or later.
|
56
|
-
|
56
|
+
|
57
57
|
module SpatialExpressions
|
58
|
-
|
59
|
-
|
58
|
+
|
59
|
+
|
60
60
|
#--
|
61
61
|
# Generic functions
|
62
62
|
#++
|
63
|
-
|
63
|
+
|
64
64
|
def st_function(function_, *args_)
|
65
65
|
spatial_info_ = args_.last.is_a?(::Array) ? args_.pop : []
|
66
66
|
::RGeo::ActiveRecord::SpatialNamedFunction.new(function_, [self] + args_, spatial_info_)
|
67
67
|
end
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
#--
|
71
71
|
# Geometry functions
|
72
72
|
#++
|
73
|
-
|
73
|
+
|
74
74
|
def st_dimension
|
75
75
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Dimension', [self], [false, true])
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def st_geometrytype
|
79
79
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_GeometryType', [self], [false, true])
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def st_astext
|
83
83
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_AsText', [self], [false, true])
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def st_asbinary
|
87
87
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_AsBinary', [self], [false, true])
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def st_srid
|
91
91
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_SRID', [self], [false, true])
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def st_isempty
|
95
95
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_IsEmpty', [self], [false, true])
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def st_issimple
|
99
99
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_IsSimple', [self], [false, true])
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def st_boundary
|
103
103
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Boundary', [self], [true, true])
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
def st_envelope
|
107
107
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Envelope', [self], [true, true])
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
def st_equals(rhs_)
|
111
111
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Equals', [self, rhs_], [false, true, true])
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
def st_disjoint(rhs_)
|
115
115
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Disjoint', [self, rhs_], [false, true, true])
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
def st_intersects(rhs_)
|
119
119
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Intersects', [self, rhs_], [false, true, true])
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def st_touches(rhs_)
|
123
123
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Touches', [self, rhs_], [false, true, true])
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
def st_crosses(rhs_)
|
127
127
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Crosses', [self, rhs_], [false, true, true])
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def st_within(rhs_)
|
131
131
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Within', [self, rhs_], [false, true, true])
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
def st_contains(rhs_)
|
135
135
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Contains', [self, rhs_], [false, true, true])
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
def st_overlaps(rhs_)
|
139
139
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Overlaps', [self, rhs_], [false, true, true])
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
def st_relate(rhs_, matrix_=nil)
|
143
143
|
args_ = [self, rhs_]
|
144
144
|
args_ << matrix.to_s if matrix_
|
145
145
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Relate', args_, [false, true, true, false])
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
def st_distance(rhs_, units_=nil)
|
149
149
|
args_ = [self, rhs_]
|
150
150
|
args_ << units.to_s if units_
|
151
151
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Distance', args_, [false, true, true, false])
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
def st_intersection(rhs_)
|
155
155
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Intersection', [self, rhs_], [true, true, true])
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
def st_difference(rhs_)
|
159
159
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Difference', [self, rhs_], [true, true, true])
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
def st_union(rhs_)
|
163
163
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Union', [self, rhs_], [true, true, true])
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
def st_symdifference(rhs_)
|
167
167
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_SymDifference', [self, rhs_], [true, true, true])
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
def st_buffer(distance_, units_=nil)
|
171
171
|
args_ = [self, distance_.to_f]
|
172
172
|
args_ << units.to_s if units_
|
173
173
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Buffer', args_, [true, true, false])
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
def st_convexhull
|
177
177
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_ConvexHull', [self], [true, true])
|
178
178
|
end
|
179
|
-
|
180
|
-
|
179
|
+
|
180
|
+
|
181
181
|
#--
|
182
182
|
# Point functions
|
183
183
|
#++
|
184
|
-
|
184
|
+
|
185
185
|
def st_x
|
186
186
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_X', [self], [false, true])
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
def st_y
|
190
190
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Y', [self], [false, true])
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
def st_z
|
194
194
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Z', [self], [false, true])
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
def st_m
|
198
198
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_M', [self], [false, true])
|
199
199
|
end
|
200
|
-
|
201
|
-
|
200
|
+
|
201
|
+
|
202
202
|
#--
|
203
203
|
# Curve functions
|
204
204
|
#++
|
205
|
-
|
205
|
+
|
206
206
|
def st_startpoint
|
207
207
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_StartPoint', [self], [true, true])
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
def st_endpoint
|
211
211
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_EndPoint', [self], [true, true])
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
def st_isclosed
|
215
215
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_IsClosed', [self], [false, true])
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
def st_isring
|
219
219
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_IsRing', [self], [false, true])
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
def st_length(units_=nil)
|
223
223
|
args_ = [self]
|
224
224
|
args_ << units.to_s if units_
|
225
225
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Length', args_, [false, true, false])
|
226
226
|
end
|
227
|
-
|
228
|
-
|
227
|
+
|
228
|
+
|
229
229
|
#--
|
230
230
|
# LineString functions
|
231
231
|
#++
|
232
|
-
|
232
|
+
|
233
233
|
def st_numpoints
|
234
234
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_NumPoints', [self], [false, true])
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
def st_pointn(n_)
|
238
238
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_PointN', [self, n_.to_i], [true, true, false])
|
239
239
|
end
|
240
|
-
|
241
|
-
|
240
|
+
|
241
|
+
|
242
242
|
#--
|
243
243
|
# Surface functions
|
244
244
|
#++
|
245
|
-
|
245
|
+
|
246
246
|
def st_area(units_=nil)
|
247
247
|
args_ = [self]
|
248
248
|
args_ << units.to_s if units_
|
249
249
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_StartPoint', args_, [false, true, false])
|
250
250
|
end
|
251
|
-
|
251
|
+
|
252
252
|
def st_centroid
|
253
253
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_Centroid', [self], [true, true])
|
254
254
|
end
|
255
|
-
|
255
|
+
|
256
256
|
def st_pointonsurface
|
257
257
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_PointOnSurface', [self], [true, true])
|
258
258
|
end
|
259
|
-
|
260
|
-
|
259
|
+
|
260
|
+
|
261
261
|
#--
|
262
262
|
# Polygon functions
|
263
263
|
#++
|
264
|
-
|
264
|
+
|
265
265
|
def st_exteriorring
|
266
266
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_ExteriorRing', [self], [true, true])
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
def st_numinteriorrings
|
270
270
|
# Note: the name difference is intentional. The standard
|
271
271
|
# names this function incorrectly.
|
272
272
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_NumInteriorRing', [self], [false, true])
|
273
273
|
end
|
274
|
-
|
274
|
+
|
275
275
|
def st_interiorringn(n_)
|
276
276
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_InteriorRingN', [self, n_.to_i], [true, true, false])
|
277
277
|
end
|
278
|
-
|
279
|
-
|
278
|
+
|
279
|
+
|
280
280
|
#--
|
281
281
|
# GeometryCollection functions
|
282
282
|
#++
|
283
|
-
|
283
|
+
|
284
284
|
def st_numgeometries
|
285
285
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_NumGeometries', [self], [false, true])
|
286
286
|
end
|
287
|
-
|
287
|
+
|
288
288
|
def st_geometryn(n_)
|
289
289
|
::RGeo::ActiveRecord::SpatialNamedFunction.new('ST_GeometryN', [self, n_.to_i], [true, true, false])
|
290
290
|
end
|
291
|
-
|
292
|
-
|
291
|
+
|
292
|
+
|
293
293
|
end
|
294
|
-
|
295
|
-
|
294
|
+
|
295
|
+
|
296
296
|
end
|
297
|
-
|
297
|
+
|
298
298
|
end
|
299
299
|
|
300
300
|
|
301
301
|
module Arel
|
302
|
-
|
302
|
+
|
303
303
|
# Create a spatial constant node.
|
304
304
|
# This node wraps a spatial value (such as an RGeo feature or a text
|
305
305
|
# string in WKT format). It supports chaining with the functions
|
306
306
|
# defined by RGeo::ActiveRecord::SpatialExpressions.
|
307
|
-
#
|
307
|
+
#
|
308
308
|
# Requires Arel 2.1 or later.
|
309
|
-
|
309
|
+
|
310
310
|
def self.spatial(arg_)
|
311
311
|
::RGeo::ActiveRecord::SpatialConstantNode.new(arg_)
|
312
312
|
end
|
313
|
-
|
313
|
+
|
314
314
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
2
|
+
#
|
3
|
+
# A tool for hacking ActiveRecord's rake tasks
|
4
|
+
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010 Daniel Azuma
|
7
|
-
#
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
8
|
# All rights reserved.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# Redistribution and use in source and binary forms, with or without
|
11
11
|
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# * Redistributions of source code must retain the above copyright notice,
|
14
14
|
# this list of conditions and the following disclaimer.
|
15
15
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# * Neither the name of the copyright holder, nor the names of any other
|
19
19
|
# contributors to this software, may be used to endorse or promote products
|
20
20
|
# derived from this software without specific prior written permission.
|
21
|
-
#
|
21
|
+
#
|
22
22
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
23
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
24
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
@@ -35,23 +35,23 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module RGeo
|
38
|
-
|
38
|
+
|
39
39
|
module ActiveRecord
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# A set of tools for hacking ActiveRecord's Rake tasks.
|
43
|
-
|
43
|
+
|
44
44
|
module TaskHacker
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
|
47
47
|
class Action # :nodoc:
|
48
|
-
|
48
|
+
|
49
49
|
def initialize(env_, pattern_, proc_)
|
50
50
|
@env = env_
|
51
51
|
@pattern = pattern_
|
52
52
|
@proc = proc_
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def call(task_)
|
56
56
|
env_ = @env || ::Rails.env || 'development'
|
57
57
|
config_ = ::ActiveRecord::Base.configurations[env_]
|
@@ -64,17 +64,17 @@ module RGeo
|
|
64
64
|
puts "WARNING: Could not find environment #{env_.inspect} in your database.yml"
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def arity
|
69
69
|
1
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
end
|
73
|
-
|
74
|
-
|
73
|
+
|
74
|
+
|
75
75
|
class << self
|
76
|
-
|
77
|
-
|
76
|
+
|
77
|
+
|
78
78
|
# Modify a named ActiveRecord rake task.
|
79
79
|
# The task must be of the form that hinges on the database adapter
|
80
80
|
# name. You must provide the fully-qualified name of the rake task
|
@@ -86,18 +86,18 @@ module RGeo
|
|
86
86
|
# then the rake task's action(s) will be replaced by the given
|
87
87
|
# block. The block will be passed the environment's database
|
88
88
|
# configuration hash.
|
89
|
-
|
89
|
+
|
90
90
|
def modify(name_, env_, pattern_, &block_)
|
91
91
|
::Rake::Task[name_].actions.unshift(Action.new(env_, pattern_, block_))
|
92
92
|
end
|
93
|
-
|
94
|
-
|
93
|
+
|
94
|
+
|
95
95
|
end
|
96
|
-
|
97
|
-
|
96
|
+
|
97
|
+
|
98
98
|
end
|
99
|
-
|
100
|
-
|
99
|
+
|
100
|
+
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
end
|