mongoid-geospatial 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +93 -0
- data/.travis.yml +26 -20
- data/CHANGELOG.md +19 -0
- data/CONTRIBUTING.md +118 -0
- data/Dangerfile +1 -0
- data/Gemfile +26 -14
- data/Guardfile +2 -2
- data/MIT-LICENSE +2 -2
- data/README.md +186 -181
- data/RELEASING.md +62 -0
- data/Rakefile +4 -1
- data/bench/bench +1 -1
- data/lib/mongoid/geospatial.rb +6 -4
- data/lib/mongoid/geospatial/config.rb +29 -0
- data/lib/mongoid/geospatial/config/point.rb +19 -0
- data/lib/mongoid/geospatial/fields/circle.rb +3 -3
- data/lib/mongoid/geospatial/fields/point.rb +16 -9
- data/lib/mongoid/geospatial/geometry_field.rb +6 -4
- data/lib/mongoid/geospatial/version.rb +1 -1
- data/lib/mongoid/geospatial/wrappers/georuby.rb +1 -0
- data/mongoid-geospatial.gemspec +3 -4
- data/spec/models/event.rb +1 -1
- data/spec/models/farm.rb +1 -1
- data/spec/models/person.rb +2 -4
- data/spec/mongoid/geospatial/config_spec.rb +22 -0
- data/spec/mongoid/geospatial/fields/point_spec.rb +21 -2
- data/spec/mongoid/geospatial/geospatial_spec.rb +1 -1
- data/spec/mongoid/geospatial/helpers/core_spec.rb +6 -3
- data/spec/mongoid/geospatial/helpers/spatial_spec.rb +3 -4
- data/spec/mongoid/geospatial/helpers/sphere_spec.rb +4 -6
- data/spec/spec_helper.rb +2 -7
- data/spec/support/authentication.rb +0 -1
- metadata +16 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c947554ea1c07198ca1c8b7c649ed93464fd1a08c6c71a2b2752e826344f049
|
4
|
+
data.tar.gz: 49d2636d235a0b91671564db6807241a4600d40070089e3d2729dd598151b2d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8da975f59a71106fc991043f1438f5c7c910e1e7c2cc78f7e112062bee9fc34a966ecf80a39ec423230805aa6756f0c01e5882085fb5e701618b0ec7d4d6b6f5
|
7
|
+
data.tar.gz: 8c8c89eec0397d1a0e3bcae04ca972ef5b3aa82094d76b4b060c53c2bb6dbc4eb058bc80cfb0d9c5b5fbb7b217aaed973212b98193247c3cfe079fb5de67a489
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-11-09 16:09:41 -0500 using RuboCop version 0.60.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 4
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
12
|
+
Bundler/DuplicatedGem:
|
13
|
+
Exclude:
|
14
|
+
- 'Gemfile'
|
15
|
+
|
16
|
+
# Offense count: 2
|
17
|
+
Lint/DuplicateMethods:
|
18
|
+
Exclude:
|
19
|
+
- 'lib/mongoid/geospatial/fields/circle.rb'
|
20
|
+
|
21
|
+
# Offense count: 3
|
22
|
+
Metrics/AbcSize:
|
23
|
+
Max: 22
|
24
|
+
|
25
|
+
# Offense count: 21
|
26
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
27
|
+
# ExcludedMethods: refine
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Max: 216
|
30
|
+
|
31
|
+
# Offense count: 1
|
32
|
+
Metrics/CyclomaticComplexity:
|
33
|
+
Max: 7
|
34
|
+
|
35
|
+
# Offense count: 1
|
36
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
37
|
+
Metrics/MethodLength:
|
38
|
+
Max: 11
|
39
|
+
|
40
|
+
# Offense count: 1
|
41
|
+
Naming/AccessorMethodName:
|
42
|
+
Exclude:
|
43
|
+
- 'spec/models/address.rb'
|
44
|
+
|
45
|
+
# Offense count: 9
|
46
|
+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
47
|
+
# AllowedNames: io, id, to, by, on, in, at, ip, db
|
48
|
+
Naming/UncommunicativeMethodParamName:
|
49
|
+
Exclude:
|
50
|
+
- 'lib/mongoid/geospatial/fields/point.rb'
|
51
|
+
- 'lib/mongoid/geospatial/geometry_field.rb'
|
52
|
+
|
53
|
+
# Offense count: 3
|
54
|
+
Style/ClassVars:
|
55
|
+
Exclude:
|
56
|
+
- 'lib/mongoid/geospatial.rb'
|
57
|
+
|
58
|
+
# Offense count: 4
|
59
|
+
Style/CommentedKeyword:
|
60
|
+
Exclude:
|
61
|
+
- 'lib/mongoid/geospatial/fields/point.rb'
|
62
|
+
|
63
|
+
# Offense count: 6
|
64
|
+
Style/Documentation:
|
65
|
+
Exclude:
|
66
|
+
- 'spec/**/*'
|
67
|
+
- 'test/**/*'
|
68
|
+
- 'bench/bench'
|
69
|
+
- 'lib/mongoid/geospatial/config.rb'
|
70
|
+
- 'lib/mongoid/geospatial/config/point.rb'
|
71
|
+
|
72
|
+
# Offense count: 2
|
73
|
+
# Cop supports --auto-correct.
|
74
|
+
# Configuration parameters: EnforcedStyle.
|
75
|
+
# SupportedStyles: module_function, extend_self
|
76
|
+
Style/ModuleFunction:
|
77
|
+
Exclude:
|
78
|
+
- 'lib/mongoid/geospatial/config.rb'
|
79
|
+
- 'lib/mongoid/geospatial/config/point.rb'
|
80
|
+
|
81
|
+
# Offense count: 4
|
82
|
+
# Cop supports --auto-correct.
|
83
|
+
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
84
|
+
# SupportedStyles: slashes, percent_r, mixed
|
85
|
+
Style/RegexpLiteral:
|
86
|
+
Exclude:
|
87
|
+
- 'Guardfile'
|
88
|
+
|
89
|
+
# Offense count: 15
|
90
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
91
|
+
# URISchemes: http, https
|
92
|
+
Metrics/LineLength:
|
93
|
+
Max: 113
|
data/.travis.yml
CHANGED
@@ -1,27 +1,33 @@
|
|
1
|
+
sudo: false
|
2
|
+
|
1
3
|
language: ruby
|
2
|
-
|
4
|
+
|
5
|
+
cache: bundler
|
6
|
+
|
7
|
+
services: mongodb
|
8
|
+
|
3
9
|
rvm:
|
4
|
-
-
|
5
|
-
- 2.0.0
|
6
|
-
- 2.1.0
|
7
|
-
- 2.2.0
|
8
|
-
- ruby-head
|
9
|
-
- jruby
|
10
|
-
- jruby-head
|
11
|
-
- rbx-2
|
10
|
+
- 2.5.3
|
12
11
|
|
13
|
-
|
14
|
-
-
|
15
|
-
- openjdk7
|
12
|
+
before_install:
|
13
|
+
- gem update bundler
|
16
14
|
|
17
|
-
|
15
|
+
before_script:
|
16
|
+
- bundle exec danger
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
addons:
|
19
|
+
apt:
|
20
|
+
sources:
|
21
|
+
- mongodb-3.2-precise
|
22
|
+
packages:
|
23
|
+
- mongodb-org-server
|
23
24
|
|
24
|
-
|
25
|
-
-
|
25
|
+
env:
|
26
|
+
- MONGOID_VERSION=5
|
27
|
+
- MONGOID_VERSION=6
|
28
|
+
- MONGOID_VERSION=7
|
29
|
+
- MONGOID_VERSION=HEAD
|
26
30
|
|
27
|
-
|
31
|
+
matrix:
|
32
|
+
allow_failures:
|
33
|
+
- env: MONGOID_VERSION=HEAD
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## 5.1.0 (2018/11/09)
|
2
|
+
|
3
|
+
* [#61](https://github.com/mongoid/mongoid-geospatial/pull/64): Add global configuration for switching between LngLat and LatLng - [@dblock](https://github.com/dblock).
|
4
|
+
* [#59](https://github.com/mongoid/mongoid-geospatial/pull/59), [#65](https://github.com/mongoid/mongoid-geospatial/pull/65): Test against Mongoid 5, 6 and 7 - [@dblock](https://github.com/dblock).
|
5
|
+
* [#52](https://github.com/mongoid/mongoid-geospatial/pull/52), [#70](https://github.com/mongoid/mongoid-geospatial/pull/70): Added Danger and Rubocop, PR and code linters - [@dblock](https://github.com/dblock).
|
6
|
+
|
7
|
+
## 5.0.0 (2015/07/23)
|
8
|
+
|
9
|
+
* Mongoid 5 support - [@nofxx](https://github.com/nofxx).
|
10
|
+
|
11
|
+
## 4.0.1 (2015/03/04)
|
12
|
+
|
13
|
+
## 4.0.0 (2015/01/11)
|
14
|
+
|
15
|
+
* Mongoid 4 support - [@nofxx](https://github.com/nofxx).
|
16
|
+
|
17
|
+
## 3.9.0 (2014/12/22)
|
18
|
+
|
19
|
+
* Initial public release - [@nofxx](https://github.com/nofxx).
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
Contributing to Mongoid::Geospatial
|
2
|
+
===================================
|
3
|
+
|
4
|
+
Mongoid::Geospatial is work of [many of contributors](https://github.com/mongoid/mongoid-geospatial/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/mongoid/mongoid-geospatial/pulls), [propose features, ask questions and discuss issues](https://github.com/mongoid/mongoid-geospatial/issues).
|
5
|
+
|
6
|
+
#### Fork the Project
|
7
|
+
|
8
|
+
Fork the [project on Github](https://github.com/mongoid/mongoid-geospatial) and check out your copy.
|
9
|
+
|
10
|
+
```
|
11
|
+
git clone https://github.com/contributor/mongoid-geospatial.git
|
12
|
+
cd mongoid-geospatial
|
13
|
+
git remote add upstream https://github.com/mongoid/mongoid-geospatial.git
|
14
|
+
```
|
15
|
+
|
16
|
+
#### Create a Topic Branch
|
17
|
+
|
18
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
19
|
+
|
20
|
+
```
|
21
|
+
git checkout master
|
22
|
+
git pull upstream master
|
23
|
+
git checkout -b my-feature-branch
|
24
|
+
```
|
25
|
+
|
26
|
+
#### Bundle Install and Test
|
27
|
+
|
28
|
+
Ensure that you can build the project and run tests.
|
29
|
+
|
30
|
+
```
|
31
|
+
bundle install
|
32
|
+
bundle exec rake
|
33
|
+
```
|
34
|
+
|
35
|
+
#### Write Tests
|
36
|
+
|
37
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/mongoid-geospatial](spec/mongoid-geospatial).
|
38
|
+
|
39
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
40
|
+
|
41
|
+
#### Write Code
|
42
|
+
|
43
|
+
Implement your feature or bug fix.
|
44
|
+
|
45
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.
|
46
|
+
|
47
|
+
Make sure that `bundle exec rake` completes without errors.
|
48
|
+
|
49
|
+
#### Write Documentation
|
50
|
+
|
51
|
+
Document any external behavior in the [README](README.md).
|
52
|
+
|
53
|
+
#### Update Changelog
|
54
|
+
|
55
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
|
56
|
+
|
57
|
+
#### Commit Changes
|
58
|
+
|
59
|
+
Make sure git knows your name and email address:
|
60
|
+
|
61
|
+
```
|
62
|
+
git config --global user.name "Your Name"
|
63
|
+
git config --global user.email "contributor@example.com"
|
64
|
+
```
|
65
|
+
|
66
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
67
|
+
|
68
|
+
```
|
69
|
+
git add ...
|
70
|
+
git commit
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Push
|
74
|
+
|
75
|
+
```
|
76
|
+
git push origin my-feature-branch
|
77
|
+
```
|
78
|
+
|
79
|
+
#### Make a Pull Request
|
80
|
+
|
81
|
+
Go to https://github.com/contributor/mongoid-geospatial and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
82
|
+
|
83
|
+
#### Rebase
|
84
|
+
|
85
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
86
|
+
|
87
|
+
```
|
88
|
+
git fetch upstream
|
89
|
+
git rebase upstream/master
|
90
|
+
git push origin my-feature-branch -f
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Update CHANGELOG Again
|
94
|
+
|
95
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
96
|
+
|
97
|
+
```
|
98
|
+
* [#123](https://github.com/mongoid/mongoid-geospatial/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
99
|
+
```
|
100
|
+
|
101
|
+
Amend your previous commit and force push the changes.
|
102
|
+
|
103
|
+
```
|
104
|
+
git commit --amend
|
105
|
+
git push origin my-feature-branch -f
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Check on Your Pull Request
|
109
|
+
|
110
|
+
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
111
|
+
|
112
|
+
#### Be Patient
|
113
|
+
|
114
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
115
|
+
|
116
|
+
#### Thank You
|
117
|
+
|
118
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/Dangerfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
danger.import_dangerfile(gem: 'mongoid-danger')
|
data/Gemfile
CHANGED
@@ -1,25 +1,37 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
|
3
|
+
case version = ENV['MONGOID_VERSION'] || '7'
|
4
|
+
when 'HEAD'
|
5
|
+
gem 'mongoid', github: 'mongodb/mongoid'
|
6
|
+
when /^7/
|
7
|
+
gem 'mongoid', '~> 7.0.0'
|
8
|
+
when /^6/
|
9
|
+
gem 'mongoid', '~> 6.0.0'
|
10
|
+
when /^5/
|
11
|
+
gem 'mongoid', '~> 5.0'
|
12
|
+
else
|
13
|
+
gem 'mongoid', version
|
14
|
+
end
|
4
15
|
|
5
|
-
|
16
|
+
gemspec
|
6
17
|
|
7
|
-
group :test do
|
18
|
+
group :development, :test do
|
19
|
+
gem 'fuubar'
|
20
|
+
gem 'guard'
|
21
|
+
gem 'guard-rspec'
|
22
|
+
gem 'guard-rubocop'
|
8
23
|
gem 'pry'
|
24
|
+
gem 'rake'
|
9
25
|
gem 'yard'
|
10
|
-
|
26
|
+
end
|
11
27
|
|
28
|
+
group :test do
|
29
|
+
gem 'coveralls', require: false if ENV['CI']
|
12
30
|
gem 'dbf'
|
13
|
-
gem 'rgeo'
|
14
31
|
gem 'georuby'
|
15
|
-
|
32
|
+
gem 'mongoid-danger', '~> 0.1.0', require: false
|
33
|
+
gem 'nokogiri'
|
34
|
+
gem 'rgeo'
|
16
35
|
gem 'rspec'
|
17
|
-
|
18
|
-
gem 'rubocop'
|
19
|
-
gem 'fuubar'
|
20
|
-
gem 'guard'
|
21
|
-
gem 'guard-rubocop'
|
22
|
-
gem 'guard-rspec'
|
23
|
-
|
24
|
-
gem 'coveralls', require: false if ENV['CI']
|
36
|
+
gem 'rubocop', '0.60.0'
|
25
37
|
end
|
data/Guardfile
CHANGED
@@ -11,6 +11,6 @@ end
|
|
11
11
|
|
12
12
|
guard :rspec, cmd: 'bundle exec rspec', notification: true do
|
13
13
|
watch(/^spec\/.+_spec\.rb$/)
|
14
|
-
watch(/^lib\/(.+)\.rb$/)
|
15
|
-
watch('spec/spec_helper.rb')
|
14
|
+
watch(/^lib\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
|
15
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
16
16
|
end
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2009-
|
1
|
+
Copyright (c) 2009-2017 Mongoid Geospatial Authors
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,172 +1,161 @@
|
|
1
1
|
Mongoid Geospatial
|
2
2
|
==================
|
3
3
|
|
4
|
-
|
5
4
|
A Mongoid Extension that simplifies the use of MongoDB spatial features.
|
6
5
|
|
7
|
-
* Version 5.x -> Mongoid 5
|
8
|
-
* Version 4.x -> Mongoid 4
|
9
|
-
|
10
|
-
** Gem name has changed: 'mongoid-geospatial' (notice the hyphen) **
|
11
|
-
Please change the underscore to a hyphen.
|
12
|
-
That will require it correctly within bundler:
|
13
|
-
`require 'mongoid/geospatial'`
|
14
|
-
|
15
6
|
[![Gem Version](https://badge.fury.io/rb/mongoid-geospatial.svg)](http://badge.fury.io/rb/mongoid-geospatial)
|
16
|
-
[![Code Climate](https://codeclimate.com/github/
|
17
|
-
[![Coverage Status](https://coveralls.io/repos/
|
18
|
-
[![
|
19
|
-
[![Build Status](https://travis-ci.org/nofxx/mongoid-geospatial.svg?branch=master)](https://travis-ci.org/nofxx/mongoid-geospatial)
|
20
|
-
|
7
|
+
[![Code Climate](https://codeclimate.com/github/mongoid/mongoid-geospatial.svg)](https://codeclimate.com/github/mongoid/mongoid-geospatial)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/github/mongoid/mongoid-geospatial/badge.svg?branch=master)](https://coveralls.io/github/mongoid/mongoid-geospatial?branch=master)
|
9
|
+
[![Build Status](https://travis-ci.org/mongoid/mongoid-geospatial.svg?branch=master)](https://travis-ci.org/mongoid/mongoid-geospatial)
|
21
10
|
|
22
11
|
Quick Start
|
23
12
|
-----------
|
24
13
|
|
25
|
-
This gem
|
26
|
-
But you may also use an external Geometric/Spatial gem alongside.
|
27
|
-
|
28
|
-
# Gemfile
|
29
|
-
gem 'mongoid-geospatial'
|
14
|
+
This gem focuses on (making helpers for) MongoDB's spatial features using Mongoid 5, 6 and 7.
|
30
15
|
|
16
|
+
```ruby
|
17
|
+
# Gemfile
|
18
|
+
gem 'mongoid-geospatial'
|
19
|
+
```
|
31
20
|
|
32
21
|
A `Place` to illustrate `Point`, `Line` and `Polygon`
|
33
22
|
|
34
|
-
|
35
|
-
|
23
|
+
```ruby
|
24
|
+
class Place
|
25
|
+
include Mongoid::Document
|
36
26
|
|
37
|
-
|
38
|
-
|
27
|
+
# Include the module
|
28
|
+
include Mongoid::Geospatial
|
39
29
|
|
40
|
-
|
41
|
-
|
30
|
+
# Just like mongoid,
|
31
|
+
field :name, type: String
|
42
32
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# To query on your points, don't forget to index:
|
49
|
-
# You may use a method:
|
50
|
-
sphere_index :location # 2d
|
51
|
-
# or
|
52
|
-
spatial_index :location # 2dsphere
|
53
|
-
|
54
|
-
# Or use a helper directly on the `field`:
|
55
|
-
field :location, type: Point, spatial: true # 2d
|
56
|
-
# or
|
57
|
-
field :location, type: Point, sphere: true # 2dsphere
|
58
|
-
end
|
33
|
+
# define your field, but choose a geometry type:
|
34
|
+
field :location, type: Point
|
35
|
+
field :route, type: LineString
|
36
|
+
field :area, type: Polygon
|
59
37
|
|
38
|
+
# To query on your points, don't forget to index:
|
39
|
+
# You may use a method:
|
40
|
+
sphere_index :location # 2dsphere
|
41
|
+
# or
|
42
|
+
spatial_index :location # 2d
|
60
43
|
|
44
|
+
# Or use a helper directly on the `field`:
|
45
|
+
field :location, type: Point, spatial: true # 2d
|
46
|
+
# or
|
47
|
+
field :location, type: Point, sphere: true # 2dsphere
|
48
|
+
end
|
49
|
+
```
|
61
50
|
|
62
51
|
Generate indexes on MongoDB via rake:
|
63
52
|
|
64
|
-
|
65
|
-
|
66
|
-
|
53
|
+
```
|
54
|
+
rake db:mongoid:create_indexes
|
55
|
+
```
|
67
56
|
|
68
57
|
Or programatically:
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
59
|
+
```ruby
|
60
|
+
Place.create_indexes
|
61
|
+
```
|
74
62
|
|
75
63
|
Points
|
76
64
|
------
|
77
65
|
|
78
|
-
|
79
|
-
|
80
|
-
in the database. Here's is how you can input a point as:
|
66
|
+
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`s.
|
67
|
+
|
68
|
+
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:
|
81
69
|
|
82
70
|
* longitude latitude array in that order - [long,lat] ([x, y])
|
83
71
|
* an unordered hash with latitude key(:lat, :latitude) and a longitude key(:lon, :long, :lng, :longitude)
|
84
|
-
* an ordered hash with longitude as the first item and latitude as the second item
|
85
|
-
This hash does not have include the latitude and longitude keys
|
86
|
-
\*only works in ruby 1.9 and up because hashes below ruby 1.9 because they are not ordered
|
72
|
+
* an ordered hash with longitude as the first item and latitude as the second item; this hash does not have include the latitude and longitude keys
|
87
73
|
* anything with the a method #to_xy or #to_lng_lat that converts itself to [long, lat] array
|
88
74
|
|
89
|
-
|
75
|
+
_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._
|
90
76
|
|
77
|
+
We store data in the DB as a [x, y] array then reformat when it is returned to you
|
91
78
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
79
|
+
```ruby
|
80
|
+
cafe = Place.create(
|
81
|
+
name: 'Café Rider',
|
82
|
+
location: {:lat => 44.106667, :lng => -73.935833},
|
83
|
+
# or
|
84
|
+
location: {latitude: 40.703056, longitude: -74.026667}
|
85
|
+
#...
|
86
|
+
```
|
98
87
|
|
99
88
|
Now to access this spatial information we can do this
|
100
89
|
|
101
|
-
|
90
|
+
```ruby
|
91
|
+
cafe.location # => [-74.026667, 40.703056]
|
92
|
+
```
|
102
93
|
|
103
94
|
If you need a hash
|
104
95
|
|
105
|
-
|
96
|
+
```ruby
|
97
|
+
cafe.location.to_hsh # => { x: -74.026667, y: 40.703056 }
|
98
|
+
```
|
106
99
|
|
107
100
|
If you are using GeoRuby or RGeo
|
108
101
|
|
109
|
-
|
110
|
-
|
111
|
-
cafe.location.to_rgeo # => RGeo::Point
|
102
|
+
```ruby
|
103
|
+
cafe.location.to_geo # => GeoRuby::Point
|
112
104
|
|
105
|
+
cafe.location.to_rgeo # => RGeo::Point
|
106
|
+
```
|
113
107
|
|
114
108
|
Conventions:
|
115
109
|
|
116
110
|
This lib uses #x and #y everywhere.
|
117
111
|
It's shorter than lat or lng or another variation that also confuses.
|
118
|
-
A point is a 2D mathematical notation, longitude/latitude is when you
|
119
|
-
use that notation to map an sphere. In other words:
|
120
|
-
All longitudes are 'xs' where not all 'xs' are longitudes.
|
121
|
-
|
122
|
-
Distance and other geometrical calculations are delegated to the external
|
123
|
-
library of your choice. More info about using RGeo or GeoRuby below.
|
124
|
-
Some built in helpers for mongoid queries:
|
112
|
+
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
113
|
|
126
|
-
|
127
|
-
# Useful to search #within_circle
|
128
|
-
cafe.location.radius(5) # [[-74.., 40..], 5]
|
129
|
-
cafe.location.radius_sphere(5) # [[-74.., 40..], 0.00048..]
|
114
|
+
Distance and other geometrical calculations are delegated to the external library of your choice. More info about using RGeo or GeoRuby below. Some built in helpers for mongoid queries:
|
130
115
|
|
131
|
-
|
132
|
-
|
133
|
-
|
116
|
+
```ruby
|
117
|
+
# Returns middle point + radius
|
118
|
+
# Useful to search #within_circle
|
119
|
+
cafe.location.radius(5) # [[-74.., 40..], 5]
|
120
|
+
cafe.location.radius_sphere(5) # [[-74.., 40..], 0.00048..]
|
134
121
|
|
122
|
+
# Returns hash if needed
|
123
|
+
cafe.location.to_hsh # {:x => -74.., :y => 40..}
|
124
|
+
cafe.location.to_hsh(:lon, :lat) # {:lon => -74.., :lat => 40..}
|
125
|
+
```
|
135
126
|
|
136
127
|
And for polygons and lines:
|
137
128
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
129
|
+
```ruby
|
130
|
+
house.area.bbox # Returns polygon bounding_box (envelope)
|
131
|
+
house.area.center # Returns calculate middle point
|
132
|
+
```
|
144
133
|
|
145
134
|
Model Setup
|
146
135
|
-----------
|
147
136
|
|
148
137
|
You can create Point, Line, Circle, Box and Polygon on your models:
|
149
138
|
|
139
|
+
```ruby
|
140
|
+
class CrazyGeom
|
141
|
+
include Mongoid::Document
|
142
|
+
include Mongoid::Geospatial
|
150
143
|
|
151
|
-
|
152
|
-
include Mongoid::Document
|
153
|
-
include Mongoid::Geospatial
|
144
|
+
field :location, type: Point, spatial: true, delegate: true
|
154
145
|
|
155
|
-
|
146
|
+
field :route, type: Line
|
147
|
+
field :area, type: Polygon
|
156
148
|
|
157
|
-
|
158
|
-
|
149
|
+
field :square, type: Box
|
150
|
+
field :around, type: Circle
|
159
151
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
# default mongodb options
|
164
|
-
spatial_index :location, {bit: 24, min: -180, max: 180}
|
165
|
-
|
166
|
-
# query by location
|
167
|
-
spatial_scope :location
|
168
|
-
end
|
152
|
+
# default mongodb options
|
153
|
+
spatial_index :location, {bit: 24, min: -180, max: 180}
|
169
154
|
|
155
|
+
# query by location
|
156
|
+
spatial_scope :location
|
157
|
+
end
|
158
|
+
```
|
170
159
|
|
171
160
|
Helpers
|
172
161
|
-------
|
@@ -174,42 +163,44 @@ Helpers
|
|
174
163
|
You can use `spatial: true` to add a '2d' index automatically,
|
175
164
|
No need for `spatial_index :location`:
|
176
165
|
|
166
|
+
```ruby
|
167
|
+
field :location, type: Point, spatial: true
|
168
|
+
```
|
177
169
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
And you can use `sphere: true` to add a '2dsphere' index automatically,
|
182
|
-
No need for `spatial_sphere :location`:
|
183
|
-
|
184
|
-
|
185
|
-
field :location, type: Point, sphere: true
|
170
|
+
And you can use `sphere: true` to add a '2dsphere' index automatically, no need for `spatial_sphere :location`:
|
186
171
|
|
172
|
+
```ruby
|
173
|
+
field :location, type: Point, sphere: true
|
174
|
+
```
|
187
175
|
|
188
176
|
You can delegate some point methods to the instance itself:
|
189
177
|
|
190
|
-
|
191
|
-
|
192
|
-
|
178
|
+
```ruby
|
179
|
+
field :location, type: Point, delegate: true
|
180
|
+
```
|
193
181
|
|
194
182
|
Now instead of `instance.location.x` you may call `instance.x`.
|
195
183
|
|
196
|
-
|
197
184
|
Nearby
|
198
185
|
------
|
199
186
|
|
200
187
|
You can add a `spatial_scope` on your models. So you can query:
|
201
188
|
|
202
|
-
|
189
|
+
```ruby
|
190
|
+
Bar.nearby(my.location)
|
191
|
+
```
|
203
192
|
|
204
193
|
instead of
|
205
194
|
|
206
|
-
|
195
|
+
```ruby
|
196
|
+
Bar.near(location: my.location)
|
197
|
+
```
|
207
198
|
|
208
199
|
Good when you're drunk. Just add to your model:
|
209
200
|
|
210
|
-
|
211
|
-
|
212
|
-
|
201
|
+
```ruby
|
202
|
+
spatial_scope :<field>
|
203
|
+
```
|
213
204
|
|
214
205
|
Geometry
|
215
206
|
--------
|
@@ -217,28 +208,28 @@ Geometry
|
|
217
208
|
You can also store Circle, Box, Line (LineString) and Polygons.
|
218
209
|
Some helper methods are available to them:
|
219
210
|
|
211
|
+
```ruby
|
212
|
+
# Returns a geometry bounding box
|
213
|
+
# Useful to query #within_geometry
|
214
|
+
polygon.bbox
|
215
|
+
polygon.bounding_box
|
220
216
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
polygon.bounding_box
|
225
|
-
|
226
|
-
# Returns a geometry calculated middle point
|
227
|
-
# Useful to query for #near
|
228
|
-
polygon.center
|
229
|
-
|
230
|
-
# Returns middle point + radius
|
231
|
-
# Useful to search #within_circle
|
232
|
-
polygon.radius(5) # [[1.0, 1.0], 5]
|
233
|
-
polygon.radius_sphere(5) # [[1.0, 1.0], 0.00048..]
|
217
|
+
# Returns a geometry calculated middle point
|
218
|
+
# Useful to query for #near
|
219
|
+
polygon.center
|
234
220
|
|
221
|
+
# Returns middle point + radius
|
222
|
+
# Useful to search #within_circle
|
223
|
+
polygon.radius(5) # [[1.0, 1.0], 5]
|
224
|
+
polygon.radius_sphere(5) # [[1.0, 1.0], 0.00048..]
|
225
|
+
```
|
235
226
|
|
236
227
|
Query
|
237
228
|
-----
|
238
229
|
|
239
|
-
Before you
|
230
|
+
Before you proceed, make sure you have read this:
|
240
231
|
|
241
|
-
http://mongoid.
|
232
|
+
http://mongoid.github.io/old/en/origin/docs/selection.html#standard
|
242
233
|
|
243
234
|
All MongoDB queries are handled by Mongoid/Origin.
|
244
235
|
|
@@ -248,34 +239,31 @@ You can use Geometry instance directly on any query:
|
|
248
239
|
|
249
240
|
* near
|
250
241
|
|
251
|
-
|
252
|
-
```
|
242
|
+
```ruby
|
253
243
|
Bar.near(location: person.house)
|
254
244
|
Bar.where(:location.near => person.house)
|
255
245
|
```
|
256
246
|
|
257
247
|
* near_sphere
|
258
248
|
|
259
|
-
```
|
249
|
+
```ruby
|
260
250
|
Bar.near_sphere(location: person.house)
|
261
251
|
Bar.where(:location.near_sphere => person.house)
|
262
252
|
```
|
263
253
|
|
264
254
|
* within_polygon
|
265
255
|
|
266
|
-
```
|
256
|
+
```ruby
|
267
257
|
Bar.within_polygon(location: [[[x,y],...[x,y]]])
|
268
258
|
# or with a bbox
|
269
259
|
Bar.within_polygon(location: street.bbox)
|
270
260
|
```
|
271
261
|
|
272
|
-
|
273
262
|
* intersects_line
|
274
263
|
* intersects_point
|
275
264
|
* intersects_polygon
|
276
265
|
|
277
266
|
|
278
|
-
|
279
267
|
External Libraries
|
280
268
|
------------------
|
281
269
|
|
@@ -284,42 +272,42 @@ If you require one of those, a #to_geo and #to_rgeo, respectivelly,
|
|
284
272
|
method(s) will be available to all spatial fields, returning the
|
285
273
|
external library corresponding object.
|
286
274
|
|
287
|
-
|
288
275
|
### Use RGeo?
|
276
|
+
|
289
277
|
https://github.com/dazuma/rgeo
|
290
278
|
|
291
279
|
RGeo is a Ruby wrapper for Proj/GEOS.
|
292
280
|
It's perfect when you need to work with complex calculations and projections.
|
293
281
|
It'll require more stuff installed to compile/work.
|
294
282
|
|
295
|
-
|
296
283
|
### Use GeoRuby?
|
284
|
+
|
297
285
|
https://github.com/nofxx/georuby
|
298
286
|
|
299
287
|
GeoRuby is a pure Ruby Geometry Library.
|
300
288
|
It's perfect if you want simple calculations and/or keep your stack in pure ruby.
|
301
289
|
Albeit not full featured in maths it has a handful of methods and good import/export helpers.
|
302
290
|
|
303
|
-
|
304
291
|
### Example
|
305
292
|
|
306
|
-
|
307
|
-
|
308
|
-
|
293
|
+
```ruby
|
294
|
+
class Person
|
295
|
+
include Mongoid::Document
|
296
|
+
include Mongoid::Geospatial
|
309
297
|
|
310
|
-
|
311
|
-
|
298
|
+
field :location, type: Point
|
299
|
+
end
|
312
300
|
|
313
|
-
|
301
|
+
me = Person.new(location: [8, 8])
|
314
302
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
# Example with RGeo
|
320
|
-
point.class # Mongoid::Geospatial::Point
|
321
|
-
point.to_rgeo.class # RGeo::Geographic::SphericalPointImpl
|
303
|
+
# Example with GeoRuby
|
304
|
+
point.class # Mongoid::Geospatial::Point
|
305
|
+
point.to_geo.class # GeoRuby::SimpleFeatures::Point
|
322
306
|
|
307
|
+
# Example with RGeo
|
308
|
+
point.class # Mongoid::Geospatial::Point
|
309
|
+
point.to_rgeo.class # RGeo::Geographic::SphericalPointImpl
|
310
|
+
```
|
323
311
|
|
324
312
|
## Configure
|
325
313
|
|
@@ -327,23 +315,28 @@ Assemble it as you need (use a initializer file):
|
|
327
315
|
|
328
316
|
With RGeo
|
329
317
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
318
|
+
```ruby
|
319
|
+
Mongoid::Geospatial.with_rgeo!
|
320
|
+
# Optional
|
321
|
+
# Mongoid::Geospatial.factory = RGeo::Geographic.spherical_factory
|
322
|
+
```
|
334
323
|
|
335
324
|
With GeoRuby
|
336
325
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
Defaults (change if you know what you're doing)
|
326
|
+
```ruby
|
327
|
+
Mongoid::Geospatial.with_georuby!
|
328
|
+
```
|
341
329
|
|
342
|
-
|
343
|
-
Mongoid::Geospatial.lat_symbol = :y
|
344
|
-
Mongoid::Geospatial.earth_radius = EARTH_RADIUS
|
330
|
+
By default the convention of this library is LngLat, configure it for LatLng as follows.
|
345
331
|
|
332
|
+
```ruby
|
333
|
+
Mongoid::Geospatial.configure do |config|
|
334
|
+
config.point.x = Mongoid::Geospatial.lat_symbols
|
335
|
+
config.point.y = Mongoid::Geospatial.lng_symbols
|
336
|
+
end
|
337
|
+
```
|
346
338
|
|
339
|
+
You will need to manually migrate any existing `Point` data if you change configuration in an existing system.
|
347
340
|
|
348
341
|
This Fork
|
349
342
|
---------
|
@@ -353,27 +346,30 @@ This fork delegates calculations to external libs.
|
|
353
346
|
|
354
347
|
Change in your models:
|
355
348
|
|
356
|
-
|
349
|
+
```ruby
|
350
|
+
include Mongoid::Spacial::Document
|
351
|
+
```
|
357
352
|
|
358
353
|
to
|
359
354
|
|
360
|
-
|
361
|
-
|
355
|
+
```ruby
|
356
|
+
include Mongoid::Geospatial
|
357
|
+
```
|
362
358
|
|
363
359
|
And for the fields:
|
364
360
|
|
365
|
-
|
366
|
-
|
361
|
+
```ruby
|
362
|
+
field :source, type: Array, spacial: true
|
363
|
+
```
|
367
364
|
|
368
365
|
to
|
369
366
|
|
370
|
-
|
371
|
-
|
367
|
+
```ruby
|
368
|
+
field :source, type: Point, spatial: true # or sphere: true
|
369
|
+
```
|
372
370
|
|
373
371
|
Beware the 't' and 'c' issue. It's spaTial.
|
374
372
|
|
375
|
-
|
376
|
-
|
377
373
|
Troubleshooting
|
378
374
|
---------------
|
379
375
|
|
@@ -381,16 +377,25 @@ Troubleshooting
|
|
381
377
|
|
382
378
|
Indexes need to be created. Execute command:
|
383
379
|
|
384
|
-
|
380
|
+
```
|
381
|
+
rake db:mongoid:create_indexes
|
382
|
+
```
|
385
383
|
|
386
384
|
Programatically
|
387
385
|
|
388
|
-
|
389
|
-
|
386
|
+
```
|
387
|
+
Model.create_indexes
|
388
|
+
```
|
390
389
|
|
391
390
|
Contributing
|
392
391
|
------------
|
393
392
|
|
394
|
-
|
395
|
-
|
396
|
-
|
393
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
394
|
+
|
395
|
+
License
|
396
|
+
-------
|
397
|
+
|
398
|
+
Copyright (c) 2009-2017 Mongoid Geospatial Authors
|
399
|
+
|
400
|
+
MIT License, see [MIT-LICENSE](MIT-LICENSE).
|
401
|
+
|