mongoid-geospatial 7.4.2 → 7.5.0
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.
- checksums.yaml +4 -4
- data/README.md +63 -84
- data/lib/mongoid/geospatial/fields/point.rb +4 -1
- data/lib/mongoid/geospatial/version.rb +1 -1
- data/lib/mongoid/geospatial/wrappers/rgeo.rb +7 -5
- data/lib/mongoid/geospatial.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f8f3869bc29a615f09d50477558b26adb0adfd9d2bba8989f3501d164a4aa2cb
|
|
4
|
+
data.tar.gz: 46d419c3a7747f9fb499f551ba09b38fcb9bad78170a9b455434f453a76d3c2b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b61abde5ab7e9a4ad7539fd706c0e3748788d1a8c0f3f65aa99c2a08e09c383cdb299498972020530b1d5e8668eb08f29bbfbe7b3f7fc6433029807f5dfaad2
|
|
7
|
+
data.tar.gz: 6993c1dc4a2444ac96fd91c5bd2cb12252415d11e66c5f1405348e4535d76b57ddb0f6e04523a4189f7f089a495129785b7eb30aa293f375c7cf0b5ea6f8cea6
|
data/README.md
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A Mongoid Extension that simplifies the use of MongoDB spatial features.
|
|
4
4
|
|
|
5
|
-
[](
|
|
6
|
-
[](https://github.com/mongoid/mongoid-geospatial/actions/workflows/test.yml?query=branch%3Amaster)
|
|
7
|
-
[](https://coveralls.io/github/mongoid/mongoid-geospatial?branch=master)
|
|
5
|
+
[](https://badge.fury.io/rb/mongoid-geospatial) [](https://github.com/mongoid/mongoid-geospatial/actions/workflows/test.yml?query=branch%3Amaster) [](https://coveralls.io/github/mongoid/mongoid-geospatial?branch=master)
|
|
8
6
|
|
|
9
7
|
The Ruby 4.0 CI job measures all library files with SimpleCov and submits `coverage/.resultset.json` through the official Coveralls action using GitHub's automatic token. Other matrix jobs do not upload duplicate reports. Run `COVERAGE=true bundle install` and `COVERAGE=true bundle exec rake spec` to measure coverage locally. An accepted upstream default-branch build is required for the badge; this workflow alone does not activate the external service.
|
|
10
8
|
|
|
@@ -36,32 +34,33 @@ class Place
|
|
|
36
34
|
|
|
37
35
|
# To query on your points, don't forget to index:
|
|
38
36
|
# You may use a method:
|
|
39
|
-
sphere_index :location
|
|
37
|
+
sphere_index :location # 2dsphere
|
|
40
38
|
# or
|
|
41
39
|
spatial_index :location # 2d
|
|
42
40
|
|
|
43
41
|
# Or use a helper directly on the `field`:
|
|
44
|
-
field :location, type: Point, spatial: true
|
|
42
|
+
field :location, type: Point, spatial: true # 2d
|
|
45
43
|
# or
|
|
46
|
-
field :location, type: Point, sphere: true
|
|
44
|
+
field :location, type: Point, sphere: true # 2dsphere
|
|
47
45
|
end
|
|
48
46
|
```
|
|
49
47
|
|
|
50
48
|
A pin named `geom` on a 2dsphere index is one include:
|
|
51
49
|
|
|
52
50
|
```ruby
|
|
53
|
-
include Mongoid::Geospatial::Geom
|
|
51
|
+
include Mongoid::Geospatial::Geom # field :geom, type: Point, sphere: true
|
|
52
|
+
|
|
54
53
|
# or a named one:
|
|
55
54
|
geom :pick_up
|
|
56
55
|
```
|
|
57
56
|
|
|
58
57
|
Generate indexes on MongoDB via rake:
|
|
59
58
|
|
|
60
|
-
```
|
|
59
|
+
```sh
|
|
61
60
|
rake db:mongoid:create_indexes
|
|
62
61
|
```
|
|
63
62
|
|
|
64
|
-
Or
|
|
63
|
+
Or programmatically:
|
|
65
64
|
|
|
66
65
|
```ruby
|
|
67
66
|
Place.create_indexes
|
|
@@ -69,38 +68,37 @@ Place.create_indexes
|
|
|
69
68
|
|
|
70
69
|
## Points
|
|
71
70
|
|
|
72
|
-
This gem defines a specific `Point` class under the Mongoid::Geospatial namespace. Make sure to use `type: ::Mongoid::Geospatial::Point` to avoid name errors or collisions with other `Point` classes you might already have defined `NameError`
|
|
71
|
+
This gem defines a specific `Point` class under the Mongoid::Geospatial namespace. Make sure to use `type: ::Mongoid::Geospatial::Point` to avoid name errors or collisions with other `Point` classes you might already have defined `NameError` exceptions.
|
|
73
72
|
|
|
74
73
|
Currently, MongoDB supports query operations on 2D points only, so that's what this lib does. All geometries apart from points are just arrays in the database. Here's is how you can input a point as:
|
|
75
74
|
|
|
76
75
|
- longitude latitude array in that order - [long,lat] ([x, y])
|
|
77
76
|
- an unordered hash with latitude key(:lat, :latitude) and a longitude key(:lon, :long, :lng, :longitude)
|
|
78
|
-
- an ordered hash with longitude as the first item and latitude as the second item; this hash does not
|
|
79
|
-
- anything with
|
|
77
|
+
- an ordered hash with longitude as the first item and latitude as the second item; this hash does not need to include the latitude and longitude keys
|
|
78
|
+
- anything with a method #to_xy or #to_lng_lat that converts itself to [long, lat] array
|
|
80
79
|
|
|
81
80
|
_Note: the convention of having longitude as the first coordinate may vary for other libraries. For instance, Google Maps often refer to "LatLng". Make sure you keep those differences in mind. See below for how to configure this library for LatLng._
|
|
82
81
|
|
|
83
82
|
We store data in the DB as a [x, y] array then reformat when it is returned to you
|
|
84
83
|
|
|
84
|
+
An empty array already stored in a Point field is read as `nil`, matching assignment of an empty array. Reading it does not rewrite the database; you can replace it with valid coordinates or explicitly set the field to `nil` and save.
|
|
85
|
+
|
|
85
86
|
```ruby
|
|
86
|
-
cafe = Place.create(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
# or
|
|
90
|
-
location: {latitude: 40.703056, longitude: -74.026667}
|
|
91
|
-
#...
|
|
87
|
+
cafe = Place.create(name: 'Café Rider', location: { lat: 44.106667, lng: -73.935833 })
|
|
88
|
+
# or
|
|
89
|
+
cafe = Place.create(name: 'Café Rider', location: { latitude: 40.703056, longitude: -74.026667 })
|
|
92
90
|
```
|
|
93
91
|
|
|
94
92
|
Now to access this spatial information we can do this
|
|
95
93
|
|
|
96
94
|
```ruby
|
|
97
|
-
cafe.location
|
|
95
|
+
cafe.location # => [-74.026667, 40.703056]
|
|
98
96
|
```
|
|
99
97
|
|
|
100
98
|
If you need a hash
|
|
101
99
|
|
|
102
100
|
```ruby
|
|
103
|
-
cafe.location.to_hsh
|
|
101
|
+
cafe.location.to_hsh # => { x: -74.026667, y: 40.703056 }
|
|
104
102
|
```
|
|
105
103
|
|
|
106
104
|
Commonly used
|
|
@@ -120,11 +118,11 @@ cafe.location.to_geo # => GeoRuby::Point
|
|
|
120
118
|
cafe.location.to_rgeo # => RGeo::Point
|
|
121
119
|
```
|
|
122
120
|
|
|
121
|
+
Point fields also accept GeoJSON hashes such as `{ type: 'Point', coordinates: [lng, lat] }` (with symbol or string keys). Assignment retains the existing coordinate-array storage format; Point fields can also read GeoJSON Point documents already stored in MongoDB. Both representations work with a `2dsphere` index: `sphere: true` selects the index, not a different storage format.
|
|
122
|
+
|
|
123
123
|
Conventions:
|
|
124
124
|
|
|
125
|
-
This lib uses #x and #y everywhere.
|
|
126
|
-
It's shorter than lat or lng or another variation that also confuses.
|
|
127
|
-
A point is a 2D mathematical notation, longitude/latitude is when you use that notation to map an sphere. In other words: all longitudes are 'xs' where not all 'xs' are longitudes.
|
|
125
|
+
This lib uses #x and #y everywhere. It's shorter than lat or lng or another variation that also confuses. A point is a 2D mathematical notation, longitude/latitude is when you use that notation to map an sphere. In other words: all longitudes are 'xs' where not all 'xs' are longitudes.
|
|
128
126
|
|
|
129
127
|
Distance is `Point#distance` (haversine, km). Projections and heavier geometry still go to RGeo or GeoRuby. Some built in helpers for mongoid queries:
|
|
130
128
|
|
|
@@ -160,11 +158,11 @@ class CrazyGeom
|
|
|
160
158
|
field :route, type: Line
|
|
161
159
|
field :area, type: Polygon
|
|
162
160
|
|
|
163
|
-
field :square,
|
|
164
|
-
field :around,
|
|
161
|
+
field :square, type: Box
|
|
162
|
+
field :around, type: Circle
|
|
165
163
|
|
|
166
164
|
# default mongodb options
|
|
167
|
-
spatial_index :location, {bit: 24, min: -180, max: 180}
|
|
165
|
+
spatial_index :location, { bit: 24, min: -180, max: 180 }
|
|
168
166
|
|
|
169
167
|
# query by location
|
|
170
168
|
spatial_scope :location
|
|
@@ -173,31 +171,29 @@ end
|
|
|
173
171
|
|
|
174
172
|
## Helpers
|
|
175
173
|
|
|
176
|
-
You can use `spatial: true` to add a '2d' index automatically,
|
|
177
|
-
No need for `spatial_index :location`:
|
|
174
|
+
You can use `spatial: true` to add a '2d' index automatically, No need for `spatial_index :location`:
|
|
178
175
|
|
|
179
176
|
```ruby
|
|
180
|
-
field :location,
|
|
177
|
+
field :location, type: Point, spatial: true
|
|
181
178
|
```
|
|
182
179
|
|
|
183
180
|
And you can use `sphere: true` to add a '2dsphere' index automatically, no need for `spatial_sphere :location`:
|
|
184
181
|
|
|
185
182
|
```ruby
|
|
186
|
-
field :location,
|
|
183
|
+
field :location, type: Point, sphere: true
|
|
187
184
|
```
|
|
188
185
|
|
|
189
186
|
You can delegate some point methods to the instance itself:
|
|
190
187
|
|
|
191
188
|
```ruby
|
|
192
|
-
field :location,
|
|
189
|
+
field :location, type: Point, delegate: true
|
|
193
190
|
```
|
|
194
191
|
|
|
195
192
|
Now instead of `instance.location.x` you may call `instance.x`.
|
|
196
193
|
|
|
197
194
|
## Geometry
|
|
198
195
|
|
|
199
|
-
You can also store Circle, Box, Line (LineString) and Polygons.
|
|
200
|
-
Some helper methods are available to them:
|
|
196
|
+
You can also store Circle, Box, Line (LineString) and Polygons. Some helper methods are available to them:
|
|
201
197
|
|
|
202
198
|
```ruby
|
|
203
199
|
# Returns a geometry bounding box
|
|
@@ -219,21 +215,21 @@ polygon.radius_sphere(5) # [[1.0, 1.0], 0.00048..]
|
|
|
219
215
|
|
|
220
216
|
You can use Geometry instance directly on any query:
|
|
221
217
|
|
|
222
|
-
###
|
|
218
|
+
### Near
|
|
223
219
|
|
|
224
220
|
```ruby
|
|
225
221
|
Bar.near(location: person.house)
|
|
226
222
|
Bar.where(:location.near => person.house)
|
|
227
223
|
```
|
|
228
224
|
|
|
229
|
-
###
|
|
225
|
+
### Near Sphere
|
|
230
226
|
|
|
231
227
|
```ruby
|
|
232
228
|
Bar.near_sphere(location: person.house)
|
|
233
229
|
Bar.where(:location.near_sphere => person.house)
|
|
234
230
|
```
|
|
235
231
|
|
|
236
|
-
###
|
|
232
|
+
### Nearby / Within
|
|
237
233
|
|
|
238
234
|
```ruby
|
|
239
235
|
Bar.nearby(person.house)
|
|
@@ -244,30 +240,20 @@ Ride.within(here, 5, field: :drop_up) # two pins? name the one you mean
|
|
|
244
240
|
City.where(:geom.near_sphere => Mongoid::Geospatial.near_query(geom, 50))
|
|
245
241
|
```
|
|
246
242
|
|
|
247
|
-
`within` caps by km, nearest first, chainable — on either index. `$nearSphere`
|
|
248
|
-
speaks two dialects and **the field's index picks which**, so the km never moves:
|
|
243
|
+
`within` caps by km, nearest first, chainable — on either index. `$nearSphere` speaks two dialects and **the field's index picks which**, so the km never moves:
|
|
249
244
|
|
|
250
|
-
```
|
|
245
|
+
```text
|
|
251
246
|
sphere: true { loc: { $nearSphere: { $geometry: {..}, $maxDistance: <metres> } } }
|
|
252
247
|
spatial: true { loc: { $nearSphere: [x, y], $maxDistance: <radians> } }
|
|
253
248
|
km / 6371
|
|
254
249
|
```
|
|
255
250
|
|
|
256
|
-
Hand the server the wrong one and it answers `NoQueryExecutionPlans` — not a
|
|
257
|
-
wrong count, a raise.
|
|
251
|
+
Hand the server the wrong one and it answers `NoQueryExecutionPlans` — not a wrong count, a raise.
|
|
258
252
|
|
|
259
|
-
**`within(..).first` is not the nearest one.** Mongoid's `#first` and `#last`
|
|
260
|
-
|
|
261
|
-
sort replaces the distance order `$near` put there. It reads as working every
|
|
262
|
-
time the closest document happens to be the oldest. Walk the criteria
|
|
263
|
-
(`.to_a.first`) or ask `nearest`. `Mongoid::Geospatial.near_selector(field, point, km,
|
|
264
|
-
sphere: <bool>)` is the one place both shapes are built; `near_query` is the
|
|
265
|
-
2dsphere half of it, for a query you write by hand.
|
|
253
|
+
**`within(..).first` is not the nearest one.** Mongoid's `#first` and `#last` sort by `_id` whenever the criteria carries no sort of its own, and that `_id` sort replaces the distance order `$near` put there. It reads as working every time the closest document happens to be the oldest. Walk the criteria (`.to_a.first`) or ask `nearest`. `Mongoid::Geospatial.near_selector(field, point, km,
|
|
254
|
+
sphere: <bool>)` is the one place both shapes are built; `near_query` is the 2dsphere half of it, for a query you write by hand.
|
|
266
255
|
|
|
267
|
-
**Don't call `#first` or `#last` on a `$near` criteria.** Mongoid sorts by
|
|
268
|
-
`_id` when a criteria carries no sort of its own, and that replaces the
|
|
269
|
-
distance order Mongo put there. Walk the criteria instead — `.to_a.first` —
|
|
270
|
-
or use `geo_near`, which returns the distance as a field you can sort on.
|
|
256
|
+
**Don't call `#first` or `#last` on a `$near` criteria.** Mongoid sorts by `_id` when a criteria carries no sort of its own, and that replaces the distance order Mongo put there. Walk the criteria instead — `.to_a.first` — or use `geo_near`, which returns the distance as a field you can sort on.
|
|
271
257
|
|
|
272
258
|
You can add a `spatial_scope` on your models. So you can query:
|
|
273
259
|
|
|
@@ -281,17 +267,15 @@ instead of
|
|
|
281
267
|
Bar.near(location: my.location)
|
|
282
268
|
```
|
|
283
269
|
|
|
284
|
-
|
|
270
|
+
Add it to your model:
|
|
285
271
|
|
|
286
272
|
```ruby
|
|
287
|
-
spatial_scope
|
|
273
|
+
spatial_scope :location
|
|
288
274
|
```
|
|
289
275
|
|
|
290
|
-
###
|
|
276
|
+
### Geo Near
|
|
291
277
|
|
|
292
|
-
The `geo_near` class method provides a more powerful way to query for documents based on proximity,
|
|
293
|
-
using MongoDB's `$geoNear` aggregation pipeline stage. This method allows for more complex
|
|
294
|
-
options and returns the distance to each matched document.
|
|
278
|
+
The `geo_near` class method provides a more powerful way to query for documents based on proximity, using MongoDB's `$geoNear` aggregation pipeline stage. This method allows for more complex options and returns the distance to each matched document.
|
|
295
279
|
|
|
296
280
|
```ruby
|
|
297
281
|
# Find places near [10, 20], using spherical calculations, up to 5km away,
|
|
@@ -330,25 +314,25 @@ The `geo_near` method returns an array of instantiated Mongoid documents, with t
|
|
|
330
314
|
|
|
331
315
|
- within_polygon
|
|
332
316
|
|
|
317
|
+
Use Mongoid's symbol operator inside `where`, not `Bar.within_polygon`. Polygon coordinates are an array of rings; close each ring by repeating its first point at the end.
|
|
318
|
+
|
|
333
319
|
```ruby
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
320
|
+
ring = [[0, 0], [2, 0], [2, 2], [0, 2], [0, 0]]
|
|
321
|
+
Bar.where(:location.within_polygon => [ring])
|
|
322
|
+
# or with a bounding box (two opposite corners, not a polygon ring)
|
|
323
|
+
Bar.where(:location.within_box => street.bbox)
|
|
337
324
|
```
|
|
338
325
|
|
|
339
326
|
- within_circle / within_spherical_circle
|
|
340
327
|
|
|
341
|
-
Mongoid
|
|
342
|
-
registers the two circle shapes, which is what `radius` and `radius_sphere`
|
|
343
|
-
have been building arguments for all along.
|
|
328
|
+
Mongoid provides the `within_polygon` and `within_box` symbol operators; this gem registers the two circle operators for use with `radius` and `radius_sphere`.
|
|
344
329
|
|
|
345
330
|
```ruby
|
|
346
331
|
Bar.where(:location.within_spherical_circle => cafe.location.radius_sphere(5, :km))
|
|
347
|
-
Bar.where(:location.within_circle => cafe.location.radius(0.05))
|
|
332
|
+
Bar.where(:location.within_circle => cafe.location.radius(0.05)) # degrees, flat
|
|
348
333
|
```
|
|
349
334
|
|
|
350
|
-
`$centerSphere` reads radians (`radius_sphere` hands it those); `$center`
|
|
351
|
-
reads the coordinate system's own units — degrees on a legacy pair.
|
|
335
|
+
`$centerSphere` reads radians (`radius_sphere` hands it those); `$center` reads the coordinate system's own units — degrees on a legacy pair.
|
|
352
336
|
|
|
353
337
|
- intersects_line
|
|
354
338
|
- intersects_point
|
|
@@ -356,26 +340,19 @@ reads the coordinate system's own units — degrees on a legacy pair.
|
|
|
356
340
|
|
|
357
341
|
## External Libraries
|
|
358
342
|
|
|
359
|
-
We currently support GeoRuby and RGeo.
|
|
360
|
-
If you require one of those, a #to_geo and #to_rgeo, respectivelly,
|
|
361
|
-
method(s) will be available to all spatial fields, returning the
|
|
362
|
-
external library corresponding object.
|
|
343
|
+
We currently support GeoRuby and RGeo. If you require one of those, a #to_geo and #to_rgeo, respectively, method(s) will be available to all spatial fields, returning the external library corresponding object.
|
|
363
344
|
|
|
364
345
|
### Use RGeo?
|
|
365
346
|
|
|
366
347
|
<https://github.com/dazuma/rgeo>
|
|
367
348
|
|
|
368
|
-
RGeo is a Ruby wrapper for Proj/GEOS.
|
|
369
|
-
It's perfect when you need to work with complex calculations and projections.
|
|
370
|
-
It'll require more stuff installed to compile/work.
|
|
349
|
+
RGeo is a Ruby wrapper for Proj/GEOS. It's perfect when you need to work with complex calculations and projections. It'll require more stuff installed to compile/work.
|
|
371
350
|
|
|
372
351
|
### Use GeoRuby?
|
|
373
352
|
|
|
374
353
|
<https://github.com/nofxx/georuby>
|
|
375
354
|
|
|
376
|
-
GeoRuby is a pure Ruby Geometry Library.
|
|
377
|
-
It's perfect if you want simple calculations and/or keep your stack in pure ruby.
|
|
378
|
-
Albeit not full featured in maths it has a handful of methods and good import/export helpers.
|
|
355
|
+
GeoRuby is a pure Ruby Geometry Library. It's perfect if you want simple calculations and/or keep your stack in pure ruby. Albeit not full featured in maths it has a handful of methods and good import/export helpers.
|
|
379
356
|
|
|
380
357
|
### Example
|
|
381
358
|
|
|
@@ -410,6 +387,8 @@ Mongoid::Geospatial.with_rgeo!
|
|
|
410
387
|
# Mongoid::Geospatial.factory = RGeo::Geographic.spherical_factory
|
|
411
388
|
```
|
|
412
389
|
|
|
390
|
+
The default is RGeo's spherical factory. Set `Mongoid::Geospatial.factory` before or after loading the wrapper to use a different factory, for example `RGeo::Cartesian.simple_factory` for planar coordinates. Points, line strings, polygon rings, and polygons all use the configured factory. Distances and other operations follow that factory's coordinate system and units; this does not change MongoDB storage or indexes.
|
|
391
|
+
|
|
413
392
|
With GeoRuby
|
|
414
393
|
|
|
415
394
|
```ruby
|
|
@@ -429,8 +408,7 @@ You will need to manually migrate any existing `Point` data if you change config
|
|
|
429
408
|
|
|
430
409
|
## This Fork
|
|
431
410
|
|
|
432
|
-
This fork is not backwards compatible with 'mongoid_spacial'.
|
|
433
|
-
This fork delegates calculations to external libs.
|
|
411
|
+
This fork is not backwards compatible with 'mongoid_spacial'. This fork delegates calculations to external libs.
|
|
434
412
|
|
|
435
413
|
Change in your models:
|
|
436
414
|
|
|
@@ -442,18 +420,19 @@ to
|
|
|
442
420
|
|
|
443
421
|
```ruby
|
|
444
422
|
include Mongoid::Geospatial
|
|
423
|
+
|
|
445
424
|
```
|
|
446
425
|
|
|
447
426
|
And for the fields:
|
|
448
427
|
|
|
449
428
|
```ruby
|
|
450
|
-
field :source,
|
|
429
|
+
field :source, type: Array, spacial: true
|
|
451
430
|
```
|
|
452
431
|
|
|
453
432
|
to
|
|
454
433
|
|
|
455
434
|
```ruby
|
|
456
|
-
field :source,
|
|
435
|
+
field :source, type: Point, spatial: true # or sphere: true
|
|
457
436
|
```
|
|
458
437
|
|
|
459
438
|
Beware the 't' and 'c' issue. It's spaTial.
|
|
@@ -464,19 +443,19 @@ Beware the 't' and 'c' issue. It's spaTial.
|
|
|
464
443
|
|
|
465
444
|
Indexes need to be created. Execute command:
|
|
466
445
|
|
|
467
|
-
```
|
|
446
|
+
```sh
|
|
468
447
|
rake db:mongoid:create_indexes
|
|
469
448
|
```
|
|
470
449
|
|
|
471
450
|
Programatically
|
|
472
451
|
|
|
473
|
-
```
|
|
452
|
+
```ruby
|
|
474
453
|
Model.create_indexes
|
|
475
454
|
```
|
|
476
455
|
|
|
477
456
|
## Contributing
|
|
478
457
|
|
|
479
|
-
See [CONTRIBUTING](CONTRIBUTING.md).
|
|
458
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), [CHANGELOG.md](CHANGELOG.md), and [RELEASING.md](RELEASING.md).
|
|
480
459
|
|
|
481
460
|
## License
|
|
482
461
|
|
|
@@ -168,7 +168,10 @@ module Mongoid
|
|
|
168
168
|
# Database -> Object
|
|
169
169
|
# Get it back
|
|
170
170
|
def demongoize(obj)
|
|
171
|
-
obj
|
|
171
|
+
coordinates = obj.is_a?(Hash) ? obj['coordinates'] || obj[:coordinates] : obj
|
|
172
|
+
return nil if coordinates == []
|
|
173
|
+
|
|
174
|
+
obj && new(*coordinates)
|
|
172
175
|
end
|
|
173
176
|
|
|
174
177
|
#
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require 'rgeo'
|
|
4
4
|
require 'mongoid/geospatial/ext/rgeo_spherical_point_impl'
|
|
5
5
|
|
|
6
|
+
Mongoid::Geospatial.factory ||= RGeo::Geographic.spherical_factory
|
|
7
|
+
|
|
6
8
|
module Mongoid
|
|
7
9
|
#
|
|
8
10
|
# Wrappers for RGeo
|
|
@@ -16,7 +18,7 @@ module Mongoid
|
|
|
16
18
|
#
|
|
17
19
|
# @return (RGeo::SphericalFactory::Point)
|
|
18
20
|
def to_rgeo
|
|
19
|
-
|
|
21
|
+
Mongoid::Geospatial.factory.point x, y
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
#
|
|
@@ -32,7 +34,7 @@ module Mongoid
|
|
|
32
34
|
GeometryField.class_eval do
|
|
33
35
|
def points
|
|
34
36
|
map do |pair|
|
|
35
|
-
|
|
37
|
+
Mongoid::Geospatial.factory.point(*pair)
|
|
36
38
|
end
|
|
37
39
|
end
|
|
38
40
|
end
|
|
@@ -40,15 +42,15 @@ module Mongoid
|
|
|
40
42
|
# Wrapper to Rgeo's LineString
|
|
41
43
|
LineString.class_eval do
|
|
42
44
|
def to_rgeo
|
|
43
|
-
|
|
45
|
+
Mongoid::Geospatial.factory.line_string(points)
|
|
44
46
|
end
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
# Wrapper to Rgeo's Polygon
|
|
48
50
|
Polygon.class_eval do
|
|
49
51
|
def to_rgeo
|
|
50
|
-
ring =
|
|
51
|
-
|
|
52
|
+
ring = Mongoid::Geospatial.factory.linear_ring(points)
|
|
53
|
+
Mongoid::Geospatial.factory.polygon(ring)
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
end
|
data/lib/mongoid/geospatial.rb
CHANGED
|
@@ -390,7 +390,7 @@ module Mongoid
|
|
|
390
390
|
mongoized_coords = { 'type' => 'Point', 'coordinates' => mongoized_coords }
|
|
391
391
|
end
|
|
392
392
|
|
|
393
|
-
# Core $geoNear parameters derived from method arguments, these are not
|
|
393
|
+
# Core $geoNear parameters derived from method arguments, these are not overridable by user_options.
|
|
394
394
|
geo_near_core_params = {
|
|
395
395
|
key: field_name.to_s,
|
|
396
396
|
near: mongoized_coords
|
metadata
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid-geospatial
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.
|
|
4
|
+
version: 7.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Ong
|
|
8
8
|
- Marcos Piccinini
|
|
9
|
+
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: mongoid
|
|
@@ -57,6 +58,7 @@ licenses:
|
|
|
57
58
|
- MIT
|
|
58
59
|
metadata:
|
|
59
60
|
rubygems_mfa_required: 'true'
|
|
61
|
+
post_install_message:
|
|
60
62
|
rdoc_options: []
|
|
61
63
|
require_paths:
|
|
62
64
|
- lib
|
|
@@ -71,7 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
71
73
|
- !ruby/object:Gem::Version
|
|
72
74
|
version: '0'
|
|
73
75
|
requirements: []
|
|
74
|
-
rubygems_version:
|
|
76
|
+
rubygems_version: 3.5.22
|
|
77
|
+
signing_key:
|
|
75
78
|
specification_version: 4
|
|
76
79
|
summary: Mongoid Extension that simplifies MongoDB Geospatial Operations.
|
|
77
80
|
test_files: []
|