mongoid-geospatial 7.4.1 → 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 -86
- 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 +3 -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
|
|
|
@@ -12,8 +10,6 @@ The Ruby 4.0 CI job measures all library files with SimpleCov and submits `cover
|
|
|
12
10
|
|
|
13
11
|
This gem focuses on (making helpers for) MongoDB's spatial features using Mongoid.
|
|
14
12
|
|
|
15
|
-
CI tests representative compatible combinations of Ruby 3.1 through 4.0, Mongoid 7 through 9, and MongoDB Server 4.4 through 8.0, including Ruby 4.0 / Mongoid 9 / MongoDB 8.0. See [the test matrix](.github/workflows/test.yml); this is not a Cartesian product of supported versions. The existing Ruby 3.1 minimum in this branch excludes the historical Ruby 2.x / Mongoid 5–6 combinations. Set `MONGOID_VERSION` to select a Mongoid major version and `MONGODB_HOST` to override the default `localhost:27017` when running tests.
|
|
16
|
-
|
|
17
13
|
```ruby
|
|
18
14
|
# Gemfile
|
|
19
15
|
gem 'mongoid-geospatial'
|
|
@@ -38,32 +34,33 @@ class Place
|
|
|
38
34
|
|
|
39
35
|
# To query on your points, don't forget to index:
|
|
40
36
|
# You may use a method:
|
|
41
|
-
sphere_index :location
|
|
37
|
+
sphere_index :location # 2dsphere
|
|
42
38
|
# or
|
|
43
39
|
spatial_index :location # 2d
|
|
44
40
|
|
|
45
41
|
# Or use a helper directly on the `field`:
|
|
46
|
-
field :location, type: Point, spatial: true
|
|
42
|
+
field :location, type: Point, spatial: true # 2d
|
|
47
43
|
# or
|
|
48
|
-
field :location, type: Point, sphere: true
|
|
44
|
+
field :location, type: Point, sphere: true # 2dsphere
|
|
49
45
|
end
|
|
50
46
|
```
|
|
51
47
|
|
|
52
48
|
A pin named `geom` on a 2dsphere index is one include:
|
|
53
49
|
|
|
54
50
|
```ruby
|
|
55
|
-
include Mongoid::Geospatial::Geom
|
|
51
|
+
include Mongoid::Geospatial::Geom # field :geom, type: Point, sphere: true
|
|
52
|
+
|
|
56
53
|
# or a named one:
|
|
57
54
|
geom :pick_up
|
|
58
55
|
```
|
|
59
56
|
|
|
60
57
|
Generate indexes on MongoDB via rake:
|
|
61
58
|
|
|
62
|
-
```
|
|
59
|
+
```sh
|
|
63
60
|
rake db:mongoid:create_indexes
|
|
64
61
|
```
|
|
65
62
|
|
|
66
|
-
Or
|
|
63
|
+
Or programmatically:
|
|
67
64
|
|
|
68
65
|
```ruby
|
|
69
66
|
Place.create_indexes
|
|
@@ -71,38 +68,37 @@ Place.create_indexes
|
|
|
71
68
|
|
|
72
69
|
## Points
|
|
73
70
|
|
|
74
|
-
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.
|
|
75
72
|
|
|
76
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:
|
|
77
74
|
|
|
78
75
|
- longitude latitude array in that order - [long,lat] ([x, y])
|
|
79
76
|
- an unordered hash with latitude key(:lat, :latitude) and a longitude key(:lon, :long, :lng, :longitude)
|
|
80
|
-
- an ordered hash with longitude as the first item and latitude as the second item; this hash does not
|
|
81
|
-
- 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
|
|
82
79
|
|
|
83
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._
|
|
84
81
|
|
|
85
82
|
We store data in the DB as a [x, y] array then reformat when it is returned to you
|
|
86
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
|
+
|
|
87
86
|
```ruby
|
|
88
|
-
cafe = Place.create(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
# or
|
|
92
|
-
location: {latitude: 40.703056, longitude: -74.026667}
|
|
93
|
-
#...
|
|
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 })
|
|
94
90
|
```
|
|
95
91
|
|
|
96
92
|
Now to access this spatial information we can do this
|
|
97
93
|
|
|
98
94
|
```ruby
|
|
99
|
-
cafe.location
|
|
95
|
+
cafe.location # => [-74.026667, 40.703056]
|
|
100
96
|
```
|
|
101
97
|
|
|
102
98
|
If you need a hash
|
|
103
99
|
|
|
104
100
|
```ruby
|
|
105
|
-
cafe.location.to_hsh
|
|
101
|
+
cafe.location.to_hsh # => { x: -74.026667, y: 40.703056 }
|
|
106
102
|
```
|
|
107
103
|
|
|
108
104
|
Commonly used
|
|
@@ -122,11 +118,11 @@ cafe.location.to_geo # => GeoRuby::Point
|
|
|
122
118
|
cafe.location.to_rgeo # => RGeo::Point
|
|
123
119
|
```
|
|
124
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
|
+
|
|
125
123
|
Conventions:
|
|
126
124
|
|
|
127
|
-
This lib uses #x and #y everywhere.
|
|
128
|
-
It's shorter than lat or lng or another variation that also confuses.
|
|
129
|
-
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.
|
|
130
126
|
|
|
131
127
|
Distance is `Point#distance` (haversine, km). Projections and heavier geometry still go to RGeo or GeoRuby. Some built in helpers for mongoid queries:
|
|
132
128
|
|
|
@@ -162,11 +158,11 @@ class CrazyGeom
|
|
|
162
158
|
field :route, type: Line
|
|
163
159
|
field :area, type: Polygon
|
|
164
160
|
|
|
165
|
-
field :square,
|
|
166
|
-
field :around,
|
|
161
|
+
field :square, type: Box
|
|
162
|
+
field :around, type: Circle
|
|
167
163
|
|
|
168
164
|
# default mongodb options
|
|
169
|
-
spatial_index :location, {bit: 24, min: -180, max: 180}
|
|
165
|
+
spatial_index :location, { bit: 24, min: -180, max: 180 }
|
|
170
166
|
|
|
171
167
|
# query by location
|
|
172
168
|
spatial_scope :location
|
|
@@ -175,31 +171,29 @@ end
|
|
|
175
171
|
|
|
176
172
|
## Helpers
|
|
177
173
|
|
|
178
|
-
You can use `spatial: true` to add a '2d' index automatically,
|
|
179
|
-
No need for `spatial_index :location`:
|
|
174
|
+
You can use `spatial: true` to add a '2d' index automatically, No need for `spatial_index :location`:
|
|
180
175
|
|
|
181
176
|
```ruby
|
|
182
|
-
field :location,
|
|
177
|
+
field :location, type: Point, spatial: true
|
|
183
178
|
```
|
|
184
179
|
|
|
185
180
|
And you can use `sphere: true` to add a '2dsphere' index automatically, no need for `spatial_sphere :location`:
|
|
186
181
|
|
|
187
182
|
```ruby
|
|
188
|
-
field :location,
|
|
183
|
+
field :location, type: Point, sphere: true
|
|
189
184
|
```
|
|
190
185
|
|
|
191
186
|
You can delegate some point methods to the instance itself:
|
|
192
187
|
|
|
193
188
|
```ruby
|
|
194
|
-
field :location,
|
|
189
|
+
field :location, type: Point, delegate: true
|
|
195
190
|
```
|
|
196
191
|
|
|
197
192
|
Now instead of `instance.location.x` you may call `instance.x`.
|
|
198
193
|
|
|
199
194
|
## Geometry
|
|
200
195
|
|
|
201
|
-
You can also store Circle, Box, Line (LineString) and Polygons.
|
|
202
|
-
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:
|
|
203
197
|
|
|
204
198
|
```ruby
|
|
205
199
|
# Returns a geometry bounding box
|
|
@@ -221,21 +215,21 @@ polygon.radius_sphere(5) # [[1.0, 1.0], 0.00048..]
|
|
|
221
215
|
|
|
222
216
|
You can use Geometry instance directly on any query:
|
|
223
217
|
|
|
224
|
-
###
|
|
218
|
+
### Near
|
|
225
219
|
|
|
226
220
|
```ruby
|
|
227
221
|
Bar.near(location: person.house)
|
|
228
222
|
Bar.where(:location.near => person.house)
|
|
229
223
|
```
|
|
230
224
|
|
|
231
|
-
###
|
|
225
|
+
### Near Sphere
|
|
232
226
|
|
|
233
227
|
```ruby
|
|
234
228
|
Bar.near_sphere(location: person.house)
|
|
235
229
|
Bar.where(:location.near_sphere => person.house)
|
|
236
230
|
```
|
|
237
231
|
|
|
238
|
-
###
|
|
232
|
+
### Nearby / Within
|
|
239
233
|
|
|
240
234
|
```ruby
|
|
241
235
|
Bar.nearby(person.house)
|
|
@@ -246,30 +240,20 @@ Ride.within(here, 5, field: :drop_up) # two pins? name the one you mean
|
|
|
246
240
|
City.where(:geom.near_sphere => Mongoid::Geospatial.near_query(geom, 50))
|
|
247
241
|
```
|
|
248
242
|
|
|
249
|
-
`within` caps by km, nearest first, chainable — on either index. `$nearSphere`
|
|
250
|
-
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:
|
|
251
244
|
|
|
252
|
-
```
|
|
245
|
+
```text
|
|
253
246
|
sphere: true { loc: { $nearSphere: { $geometry: {..}, $maxDistance: <metres> } } }
|
|
254
247
|
spatial: true { loc: { $nearSphere: [x, y], $maxDistance: <radians> } }
|
|
255
248
|
km / 6371
|
|
256
249
|
```
|
|
257
250
|
|
|
258
|
-
Hand the server the wrong one and it answers `NoQueryExecutionPlans` — not a
|
|
259
|
-
wrong count, a raise.
|
|
251
|
+
Hand the server the wrong one and it answers `NoQueryExecutionPlans` — not a wrong count, a raise.
|
|
260
252
|
|
|
261
|
-
**`within(..).first` is not the nearest one.** Mongoid's `#first` and `#last`
|
|
262
|
-
|
|
263
|
-
sort replaces the distance order `$near` put there. It reads as working every
|
|
264
|
-
time the closest document happens to be the oldest. Walk the criteria
|
|
265
|
-
(`.to_a.first`) or ask `nearest`. `Mongoid::Geospatial.near_selector(field, point, km,
|
|
266
|
-
sphere: <bool>)` is the one place both shapes are built; `near_query` is the
|
|
267
|
-
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.
|
|
268
255
|
|
|
269
|
-
**Don't call `#first` or `#last` on a `$near` criteria.** Mongoid sorts by
|
|
270
|
-
`_id` when a criteria carries no sort of its own, and that replaces the
|
|
271
|
-
distance order Mongo put there. Walk the criteria instead — `.to_a.first` —
|
|
272
|
-
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.
|
|
273
257
|
|
|
274
258
|
You can add a `spatial_scope` on your models. So you can query:
|
|
275
259
|
|
|
@@ -283,17 +267,15 @@ instead of
|
|
|
283
267
|
Bar.near(location: my.location)
|
|
284
268
|
```
|
|
285
269
|
|
|
286
|
-
|
|
270
|
+
Add it to your model:
|
|
287
271
|
|
|
288
272
|
```ruby
|
|
289
|
-
spatial_scope
|
|
273
|
+
spatial_scope :location
|
|
290
274
|
```
|
|
291
275
|
|
|
292
|
-
###
|
|
276
|
+
### Geo Near
|
|
293
277
|
|
|
294
|
-
The `geo_near` class method provides a more powerful way to query for documents based on proximity,
|
|
295
|
-
using MongoDB's `$geoNear` aggregation pipeline stage. This method allows for more complex
|
|
296
|
-
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.
|
|
297
279
|
|
|
298
280
|
```ruby
|
|
299
281
|
# Find places near [10, 20], using spherical calculations, up to 5km away,
|
|
@@ -332,25 +314,25 @@ The `geo_near` method returns an array of instantiated Mongoid documents, with t
|
|
|
332
314
|
|
|
333
315
|
- within_polygon
|
|
334
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
|
+
|
|
335
319
|
```ruby
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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)
|
|
339
324
|
```
|
|
340
325
|
|
|
341
326
|
- within_circle / within_spherical_circle
|
|
342
327
|
|
|
343
|
-
Mongoid
|
|
344
|
-
registers the two circle shapes, which is what `radius` and `radius_sphere`
|
|
345
|
-
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`.
|
|
346
329
|
|
|
347
330
|
```ruby
|
|
348
331
|
Bar.where(:location.within_spherical_circle => cafe.location.radius_sphere(5, :km))
|
|
349
|
-
Bar.where(:location.within_circle => cafe.location.radius(0.05))
|
|
332
|
+
Bar.where(:location.within_circle => cafe.location.radius(0.05)) # degrees, flat
|
|
350
333
|
```
|
|
351
334
|
|
|
352
|
-
`$centerSphere` reads radians (`radius_sphere` hands it those); `$center`
|
|
353
|
-
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.
|
|
354
336
|
|
|
355
337
|
- intersects_line
|
|
356
338
|
- intersects_point
|
|
@@ -358,26 +340,19 @@ reads the coordinate system's own units — degrees on a legacy pair.
|
|
|
358
340
|
|
|
359
341
|
## External Libraries
|
|
360
342
|
|
|
361
|
-
We currently support GeoRuby and RGeo.
|
|
362
|
-
If you require one of those, a #to_geo and #to_rgeo, respectivelly,
|
|
363
|
-
method(s) will be available to all spatial fields, returning the
|
|
364
|
-
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.
|
|
365
344
|
|
|
366
345
|
### Use RGeo?
|
|
367
346
|
|
|
368
347
|
<https://github.com/dazuma/rgeo>
|
|
369
348
|
|
|
370
|
-
RGeo is a Ruby wrapper for Proj/GEOS.
|
|
371
|
-
It's perfect when you need to work with complex calculations and projections.
|
|
372
|
-
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.
|
|
373
350
|
|
|
374
351
|
### Use GeoRuby?
|
|
375
352
|
|
|
376
353
|
<https://github.com/nofxx/georuby>
|
|
377
354
|
|
|
378
|
-
GeoRuby is a pure Ruby Geometry Library.
|
|
379
|
-
It's perfect if you want simple calculations and/or keep your stack in pure ruby.
|
|
380
|
-
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.
|
|
381
356
|
|
|
382
357
|
### Example
|
|
383
358
|
|
|
@@ -412,6 +387,8 @@ Mongoid::Geospatial.with_rgeo!
|
|
|
412
387
|
# Mongoid::Geospatial.factory = RGeo::Geographic.spherical_factory
|
|
413
388
|
```
|
|
414
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
|
+
|
|
415
392
|
With GeoRuby
|
|
416
393
|
|
|
417
394
|
```ruby
|
|
@@ -431,8 +408,7 @@ You will need to manually migrate any existing `Point` data if you change config
|
|
|
431
408
|
|
|
432
409
|
## This Fork
|
|
433
410
|
|
|
434
|
-
This fork is not backwards compatible with 'mongoid_spacial'.
|
|
435
|
-
This fork delegates calculations to external libs.
|
|
411
|
+
This fork is not backwards compatible with 'mongoid_spacial'. This fork delegates calculations to external libs.
|
|
436
412
|
|
|
437
413
|
Change in your models:
|
|
438
414
|
|
|
@@ -444,18 +420,19 @@ to
|
|
|
444
420
|
|
|
445
421
|
```ruby
|
|
446
422
|
include Mongoid::Geospatial
|
|
423
|
+
|
|
447
424
|
```
|
|
448
425
|
|
|
449
426
|
And for the fields:
|
|
450
427
|
|
|
451
428
|
```ruby
|
|
452
|
-
field :source,
|
|
429
|
+
field :source, type: Array, spacial: true
|
|
453
430
|
```
|
|
454
431
|
|
|
455
432
|
to
|
|
456
433
|
|
|
457
434
|
```ruby
|
|
458
|
-
field :source,
|
|
435
|
+
field :source, type: Point, spatial: true # or sphere: true
|
|
459
436
|
```
|
|
460
437
|
|
|
461
438
|
Beware the 't' and 'c' issue. It's spaTial.
|
|
@@ -466,19 +443,19 @@ Beware the 't' and 'c' issue. It's spaTial.
|
|
|
466
443
|
|
|
467
444
|
Indexes need to be created. Execute command:
|
|
468
445
|
|
|
469
|
-
```
|
|
446
|
+
```sh
|
|
470
447
|
rake db:mongoid:create_indexes
|
|
471
448
|
```
|
|
472
449
|
|
|
473
450
|
Programatically
|
|
474
451
|
|
|
475
|
-
```
|
|
452
|
+
```ruby
|
|
476
453
|
Model.create_indexes
|
|
477
454
|
```
|
|
478
455
|
|
|
479
456
|
## Contributing
|
|
480
457
|
|
|
481
|
-
See [CONTRIBUTING](CONTRIBUTING.md).
|
|
458
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), [CHANGELOG.md](CHANGELOG.md), and [RELEASING.md](RELEASING.md).
|
|
482
459
|
|
|
483
460
|
## License
|
|
484
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,7 +1,7 @@
|
|
|
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
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-
|
|
12
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: mongoid
|
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
74
|
version: '0'
|
|
75
75
|
requirements: []
|
|
76
|
-
rubygems_version: 3.5.
|
|
76
|
+
rubygems_version: 3.5.22
|
|
77
77
|
signing_key:
|
|
78
78
|
specification_version: 4
|
|
79
79
|
summary: Mongoid Extension that simplifies MongoDB Geospatial Operations.
|