mongoid_geo 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +35 -27
- data/lib/mongoid/geo/geo_near.rb +1 -0
- data/lib/mongoid/geo/inflections.rb +5 -0
- metadata +11 -11
data/README.textile
CHANGED
@@ -5,10 +5,13 @@ A Geo extension for Mongoid.
|
|
5
5
|
"MongoDB Geospatial Indexing":http://www.mongodb.org/display/DOCS/Geospatial+Indexing
|
6
6
|
|
7
7
|
* Supports Mongo DB 1.7+ sphere distance calculations
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
|
8
|
+
* Extra geo calculation methods such as #near_sphere etc.
|
9
|
+
* Add concept of a special "geo" field (for setting the location point)
|
10
|
+
* Calculate locations near a given point and return as criteria, sorted by distance
|
11
|
+
|
12
|
+
h2. Status update (May 18, 2011)
|
13
|
+
|
14
|
+
Created alias methods such as _#near_sphere_ for _#nearSphere_ etc. to make the DSL much more 'rubyish'!
|
12
15
|
|
13
16
|
h2. Mongoid 2 geo features
|
14
17
|
|
@@ -134,6 +137,12 @@ Usage example:
|
|
134
137
|
address.location.should == [23.5, -47].reverse
|
135
138
|
</pre>
|
136
139
|
|
140
|
+
h3. Future ideas...
|
141
|
+
|
142
|
+
I have recently created a new geo *geo_calc* which includes the concept of a GeoPoint that is much more powerful than the current #to_point implementation in this gem.
|
143
|
+
I plan to substitute this functionality accordingly. Also I plan to include support for Geo vectors (see my *geo_vectors* gem) that I'm currently implementing.
|
144
|
+
Stay tuned!
|
145
|
+
|
137
146
|
h2. geoNear
|
138
147
|
|
139
148
|
<pre>
|
@@ -201,38 +210,37 @@ h2. Mongoid Geo extra inclusions
|
|
201
210
|
Find addresses near a point using spherical distance calculation
|
202
211
|
|
203
212
|
<pre>
|
204
|
-
Address.
|
213
|
+
Address.near_sphere(:location => [ 72, -44 ])
|
205
214
|
</pre>
|
206
215
|
|
207
|
-
|
208
216
|
h2. Mongoid Geo extra inflections
|
209
217
|
|
210
|
-
h3.
|
218
|
+
h3. near_sphere
|
211
219
|
|
212
220
|
<pre>
|
213
|
-
base.where(:location.
|
221
|
+
base.where(:location.near_sphere => [ 72, -44 ])
|
214
222
|
# => :location => { "$nearSphere" : [ 72, -44 ] }
|
215
223
|
</pre>
|
216
224
|
|
217
|
-
h3.
|
225
|
+
h3. near_max
|
218
226
|
|
219
227
|
Find points near a given point within a maximum distance
|
220
228
|
|
221
229
|
<pre>
|
222
|
-
base.where(:location.
|
230
|
+
base.where(:location.near_max => [[ 72, -44 ], 5])
|
223
231
|
# => { $near: [50, 40] , $maxDistance: 3 }
|
224
232
|
|
225
|
-
base.where(:location.
|
233
|
+
base.where(:location.near_max(:sphere) => [[ 72, -44 ], 5])
|
226
234
|
# => { $nearSphere: [50, 40] , $maxDistanceSphere: 3 }
|
227
235
|
|
228
|
-
base.where(:location.
|
236
|
+
base.where(:location.near_max(:sphere, :flat) => [[ 72, -44 ], 5])
|
229
237
|
# => { $nearSphere: [50, 40] , $maxDistance: 3 }
|
230
238
|
</pre>
|
231
239
|
|
232
240
|
You can also use a Hash to define the nearMax
|
233
241
|
|
234
242
|
<pre>
|
235
|
-
places.where(:location.
|
243
|
+
places.where(:location.near_max => {:point => [ 72, -44 ], :distance => 5})
|
236
244
|
</pre>
|
237
245
|
|
238
246
|
Or use an Object (which must have the methods @#point@ and @#distance@ that return the point and max distance from that point)
|
@@ -242,7 +250,7 @@ Or use an Object (which must have the methods @#point@ and @#distance@ that retu
|
|
242
250
|
near_max.point = [50, 40]
|
243
251
|
near_max.distance = [30,55]
|
244
252
|
|
245
|
-
places.where(:location.
|
253
|
+
places.where(:location.near_max => near_max)
|
246
254
|
</pre>
|
247
255
|
|
248
256
|
Note: For the points, you can also use a hash or an object with the methods/keys, either @:lat, :lng@ or @:latitude, :longitude@
|
@@ -253,32 +261,32 @@ Example:
|
|
253
261
|
center = (Struct.new :lat, :lng).new
|
254
262
|
center.lat = 72
|
255
263
|
center.lng = -44
|
256
|
-
places.where(:location.
|
264
|
+
places.where(:location.within_center => [center, radius])
|
257
265
|
|
258
266
|
# OR
|
259
267
|
|
260
|
-
places.where(:location.
|
268
|
+
places.where(:location.within_center => [{:lat => 72, :lng => -44}, radius])
|
261
269
|
</pre>
|
262
270
|
|
263
|
-
h3.
|
271
|
+
h3. within_box
|
264
272
|
|
265
273
|
<pre>
|
266
274
|
box = [[50, 40], [30,55]]
|
267
|
-
base.where(:location.
|
275
|
+
base.where(:location.within_box => box)
|
268
276
|
# => locations: {"$within" : {"$box" : [[50, 40], [30,55]]}
|
269
277
|
|
270
|
-
base.where(:location.
|
278
|
+
base.where(:location.within_box(:sphere) => box)
|
271
279
|
# => locations: {"$within" : {"$boxSphere" : [[50, 40], [30,55]]}
|
272
280
|
</pre>
|
273
281
|
|
274
282
|
You can also use a Hash to define the box
|
275
283
|
|
276
284
|
<pre>
|
277
|
-
places.where(:location.
|
285
|
+
places.where(:location.within_box => {:lower_left => [50, 40], :upper_right => [30,55]})
|
278
286
|
|
279
287
|
# or mix and match
|
280
288
|
|
281
|
-
places.where(:location.
|
289
|
+
places.where(:location.within_box => {:lower_left => {:lat => 50, :lng => 40}, :upper_right => [30,55] } )
|
282
290
|
</pre>
|
283
291
|
|
284
292
|
Or use an object (which must have the methods @#lower_left@ and @#upper_right@ that return the points of the bounding box)
|
@@ -288,26 +296,26 @@ Or use an object (which must have the methods @#lower_left@ and @#upper_right@ t
|
|
288
296
|
box.lower_left = [50, 40]
|
289
297
|
box.upper_right = [30, 55]
|
290
298
|
|
291
|
-
places.where(:location.
|
299
|
+
places.where(:location.within_box => box)
|
292
300
|
</pre>
|
293
301
|
|
294
|
-
h3.
|
302
|
+
h3. within_center
|
295
303
|
|
296
304
|
<pre>
|
297
305
|
center = [50, 40]
|
298
306
|
radius = 4
|
299
307
|
|
300
|
-
places.where(:location.
|
308
|
+
places.where(:location.within_center => [center, radius])
|
301
309
|
# => places: {"$within" : {"$center" : [[50, 40], 4]}
|
302
310
|
|
303
|
-
places.where(:location.
|
311
|
+
places.where(:location.within_center(:sphere) => [center, radius])
|
304
312
|
# => places: {"$within" : {"$centerSphere" : [[50, 40], 4]}
|
305
313
|
</pre>
|
306
314
|
|
307
315
|
You can also use a hash to define the circle, with @:center@ and @:radius@ keys
|
308
316
|
|
309
317
|
<pre>
|
310
|
-
places.where(:location.
|
318
|
+
places.where(:location.within_center => {:center => [50, 40], :radius => 4})
|
311
319
|
</pre>
|
312
320
|
|
313
321
|
Or use an object (which must have the methods #lower_left and #upper_right that return the points of the bounding box)
|
@@ -317,5 +325,5 @@ Or use an object (which must have the methods #lower_left and #upper_right that
|
|
317
325
|
circle.center = [50, 40]
|
318
326
|
circle.radius = 4
|
319
327
|
|
320
|
-
places.where(:location.
|
328
|
+
places.where(:location.within_center => circle)
|
321
329
|
</pre>
|
data/lib/mongoid/geo/geo_near.rb
CHANGED
@@ -68,6 +68,7 @@ module Mongoid
|
|
68
68
|
query = create_query(self, center, options)
|
69
69
|
create_result(query_result(self, query, center, location_attribute, options)).extend(Mongoid::Geo::Models).as_criteria(options[:dist_order])
|
70
70
|
end
|
71
|
+
alias_method :geo_near, :geoNear
|
71
72
|
|
72
73
|
protected
|
73
74
|
|
@@ -15,12 +15,14 @@ module Mongoid #:nodoc:
|
|
15
15
|
def geoNear
|
16
16
|
Criterion::Complex.new(:operator => 'geoNearSphere', :key => self)
|
17
17
|
end
|
18
|
+
alias_method :geo_near, :geoNear
|
18
19
|
|
19
20
|
def nearSphere
|
20
21
|
Mongoid::Geo.spherical_mode do
|
21
22
|
Criterion::Complex.new(:operator => 'nearSphere', :key => self)
|
22
23
|
end
|
23
24
|
end
|
25
|
+
alias_method :near_sphere, :nearSphere
|
24
26
|
|
25
27
|
def nearMax *calcs
|
26
28
|
calcs = (!calcs || calcs.empty?) ? [:flat] : calcs
|
@@ -33,14 +35,17 @@ module Mongoid #:nodoc:
|
|
33
35
|
raise "method nearMax takes one or two symbols as arguments, each symbol must be either :flat or :sphere"
|
34
36
|
end
|
35
37
|
end
|
38
|
+
alias_method :near_max, :nearMax
|
36
39
|
|
37
40
|
def withinBox calc = :flat
|
38
41
|
Criterion::OuterOperator.new(:outer_op => 'within', :operator => get_op(calc, 'box'), :key => self)
|
39
42
|
end
|
43
|
+
alias_method :within_box, :withinBox
|
40
44
|
|
41
45
|
def withinCenter calc = :flat
|
42
46
|
Criterion::OuterOperator.new(:outer_op => 'within', :operator => get_op(calc, 'center'), :key => self)
|
43
47
|
end
|
48
|
+
alias_method :within_center, :withinCenter
|
44
49
|
|
45
50
|
private
|
46
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_geo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-05-09 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2157121480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.4'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2157121480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mongoid
|
27
|
-
requirement: &
|
27
|
+
requirement: &2157121020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.0.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2157121020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bson
|
38
|
-
requirement: &
|
38
|
+
requirement: &2157120560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.3'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2157120560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &2157120100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 3.0.4
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2157120100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: hashie
|
60
|
-
requirement: &
|
60
|
+
requirement: &2157119640 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.4.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2157119640
|
69
69
|
description: Geo spatial extension on Mongoid 2, to add more geo-spatial capabilities
|
70
70
|
email:
|
71
71
|
- kmandrup@gmail.com
|