mongoid-geospatial 7.0.0 → 7.1.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 +61 -30
- data/lib/mongoid/geospatial/config/point.rb +5 -2
- data/lib/mongoid/geospatial/config.rb +2 -0
- data/lib/mongoid/geospatial/ext/rgeo_spherical_point_impl.rb +2 -0
- data/lib/mongoid/geospatial/fields/box.rb +2 -0
- data/lib/mongoid/geospatial/fields/circle.rb +2 -2
- data/lib/mongoid/geospatial/fields/line_string.rb +2 -0
- data/lib/mongoid/geospatial/fields/point.rb +18 -15
- data/lib/mongoid/geospatial/fields/polygon.rb +2 -0
- data/lib/mongoid/geospatial/geometry_field.rb +4 -2
- data/lib/mongoid/geospatial/helpers/delegate.rb +2 -0
- data/lib/mongoid/geospatial/helpers/spatial.rb +2 -0
- data/lib/mongoid/geospatial/helpers/sphere.rb +2 -0
- data/lib/mongoid/geospatial/version.rb +3 -1
- data/lib/mongoid/geospatial/wrappers/georuby.rb +2 -0
- data/lib/mongoid/geospatial/wrappers/rgeo.rb +2 -0
- data/lib/mongoid/geospatial.rb +144 -12
- metadata +5 -75
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -49
- data/.hound.yml +0 -2
- data/.rspec +0 -3
- data/.rubocop.yml +0 -8
- data/.travis.yml +0 -33
- data/CHANGELOG.md +0 -23
- data/CONTRIBUTING.md +0 -118
- data/Gemfile +0 -17
- data/Guardfile +0 -16
- data/RELEASING.md +0 -62
- data/Rakefile +0 -20
- data/mongoid-geospatial.gemspec +0 -18
- data/spec/bench +0 -64
- data/spec/models/address.rb +0 -69
- data/spec/models/alarm.rb +0 -12
- data/spec/models/bar.rb +0 -14
- data/spec/models/bus.rb +0 -12
- data/spec/models/event.rb +0 -18
- data/spec/models/farm.rb +0 -13
- data/spec/models/person.rb +0 -91
- data/spec/models/phone.rb +0 -8
- data/spec/models/place.rb +0 -13
- data/spec/models/river.rb +0 -22
- data/spec/mongoid/geospatial/config_spec.rb +0 -22
- data/spec/mongoid/geospatial/fields/box_spec.rb +0 -8
- data/spec/mongoid/geospatial/fields/circle_spec.rb +0 -8
- data/spec/mongoid/geospatial/fields/line_string_spec.rb +0 -78
- data/spec/mongoid/geospatial/fields/point_spec.rb +0 -296
- data/spec/mongoid/geospatial/fields/polygon_spec.rb +0 -87
- data/spec/mongoid/geospatial/geospatial_spec.rb +0 -222
- data/spec/mongoid/geospatial/helpers/core_spec.rb +0 -35
- data/spec/mongoid/geospatial/helpers/delegate_spec.rb +0 -67
- data/spec/mongoid/geospatial/helpers/spatial_spec.rb +0 -40
- data/spec/mongoid/geospatial/helpers/sphere_spec.rb +0 -31
- data/spec/mongoid/geospatial/wrappers/georuby_spec.rb +0 -63
- data/spec/mongoid/geospatial/wrappers/rgeo_spec.rb +0 -115
- data/spec/mongoid.yml +0 -298
- data/spec/spec_helper.rb +0 -42
- data/spec/support/authentication.rb +0 -28
- data/spec/support/mongod.conf +0 -3
- data/spec/support/mongoid.yml +0 -19
data/spec/models/place.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Sample spec class
|
2
|
-
class Place
|
3
|
-
include Mongoid::Document
|
4
|
-
include Mongoid::Geospatial
|
5
|
-
|
6
|
-
field :name, type: String
|
7
|
-
field :location, type: Point, spatial: true
|
8
|
-
|
9
|
-
has_one :rating, as: :ratable
|
10
|
-
|
11
|
-
spatial_index :location
|
12
|
-
spatial_scope :location
|
13
|
-
end
|
data/spec/models/river.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# Sample spec class
|
2
|
-
class River
|
3
|
-
include Mongoid::Document
|
4
|
-
include Mongoid::Geospatial
|
5
|
-
|
6
|
-
field :name, type: String
|
7
|
-
field :length, type: Integer
|
8
|
-
field :discharge, type: Integer
|
9
|
-
field :course, type: LineString, spatial: true
|
10
|
-
# set return_array to true if you do not want a hash returned all the time
|
11
|
-
field :source, type: Point, spatial: true
|
12
|
-
field :mouth, type: Point, spatial: { lat: 'latitude', lng: 'longitude' }
|
13
|
-
field :mouth_array, type: Array, spatial: { return_array: true }
|
14
|
-
|
15
|
-
# simplified spatial indexing
|
16
|
-
# you can only index one field in mongodb < 1.9
|
17
|
-
spatial_index :source
|
18
|
-
# alternatives
|
19
|
-
# index [[ :spatial, Mongo::GEO2D ]], {min:-400, max:400}
|
20
|
-
# index [[ :spatial, Mongo::GEO2D ]], {bit:32}
|
21
|
-
# index [[ :spatial, Mongo::GEO2D ],:name]
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial::Config do
|
4
|
-
context 'point' do
|
5
|
-
it 'uses LonLat by default' do
|
6
|
-
expect(Mongoid::Geospatial.config.point.x).to eq Mongoid::Geospatial.lng_symbols
|
7
|
-
expect(Mongoid::Geospatial.config.point.y).to eq Mongoid::Geospatial.lat_symbols
|
8
|
-
end
|
9
|
-
context 'configured as latlon' do
|
10
|
-
before do
|
11
|
-
Mongoid::Geospatial.configure do |config|
|
12
|
-
config.point.x = Mongoid::Geospatial.lat_symbols
|
13
|
-
config.point.y = Mongoid::Geospatial.lng_symbols
|
14
|
-
end
|
15
|
-
end
|
16
|
-
it 'uses latlon' do
|
17
|
-
expect(Mongoid::Geospatial.config.point.x).to eq Mongoid::Geospatial.lat_symbols
|
18
|
-
expect(Mongoid::Geospatial.config.point.y).to eq Mongoid::Geospatial.lng_symbols
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial::LineString do
|
4
|
-
describe '(de)mongoize' do
|
5
|
-
it 'should support a field mapped as linestring' do
|
6
|
-
river = River.new(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
|
7
|
-
expect(river.course).to be_a Mongoid::Geospatial::LineString
|
8
|
-
expect(river.course).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should update line string too' do
|
12
|
-
river = River.create!(name: 'Amazonas')
|
13
|
-
river.course = [[1, 1], [1, 1], [9, 9], [9, 9]]
|
14
|
-
river.save
|
15
|
-
expect(River.first.course).to eq(river.course)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should line_string += point nicely' do
|
19
|
-
river = River.create!(name: 'Amazonas', course: [[1, 1], [9, 9]])
|
20
|
-
river.course += [[10, 10]]
|
21
|
-
river.save
|
22
|
-
expect(River.first.course).to eq([[1, 1], [9, 9], [10, 10]])
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should NOT parent.line_string << point nicely (mongoid doesnt track <<)' do
|
26
|
-
river = River.create!(name: 'Amazonas', course: [[1, 1], [9, 9]])
|
27
|
-
river.course << [10, 10]
|
28
|
-
river.save
|
29
|
-
expect(River.first.course).to eq([[1, 1], [9, 9]])
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should have same obj id' do
|
33
|
-
pending 'Mongoid Issue #...'
|
34
|
-
river = River.create!(name: 'Amazonas', course: [[1, 1], [9, 9]])
|
35
|
-
expect(river.course.object_id).to eq(river.course.object_id)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should have same obj id ary' do
|
39
|
-
river = River.create!(name: 'Amazonas', mouth_array: [[1, 1], [9, 9]])
|
40
|
-
expect(river.mouth_array.object_id).to eq(river.mouth_array.object_id)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should support a field mapped as linestring' do
|
44
|
-
River.create!(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
|
45
|
-
expect(River.first.course).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should have a bounding box' do
|
49
|
-
l = Mongoid::Geospatial::LineString.new [[1, 5], [6, 5], [6, 6], [5, 6]]
|
50
|
-
expect(l.bbox).to eq([[1, 5], [6, 6]])
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should have a geom box' do
|
54
|
-
l = Mongoid::Geospatial::LineString.new [[1, 1], [5, 5]]
|
55
|
-
expect(l.geom_box).to eq([[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]])
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should have a geom box' do
|
59
|
-
l = Mongoid::Geospatial::LineString.new [[1, 1], [2, 2], [3, 4], [5, 5]]
|
60
|
-
expect(l.geom_box).to eq([[1, 1], [1, 5], [5, 5], [5, 1], [1, 1]])
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should have a center point' do
|
64
|
-
l = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
|
65
|
-
expect(l.center).to eq([5.0, 5.0])
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should have a radius helper' do
|
69
|
-
l = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
|
70
|
-
expect(l.radius(10)).to eq([[5.0, 5.0], 10])
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should have a radius sphere' do
|
74
|
-
l = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
|
75
|
-
expect(l.radius_sphere(10)[1]).to be_within(0.001).of(0.001569)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,296 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial::Point do
|
4
|
-
describe "Moe's Bar" do
|
5
|
-
let(:bar) { Bar.create!(name: "Moe's") }
|
6
|
-
|
7
|
-
it 'should not interfer with mongoid' do
|
8
|
-
expect(bar.class.count).to eql(1)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should not fail if point is nil' do
|
12
|
-
expect(bar.location).to be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should set point methodically' do
|
16
|
-
bar.location = Mongoid::Geospatial::Point.new(8, 9)
|
17
|
-
expect(bar.save).to be_truthy
|
18
|
-
expect(Bar.first.location.x).to eq(8)
|
19
|
-
expect(Bar.first.location.y).to eq(9)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should set point with comma separated text' do
|
23
|
-
bar.location = '2.99,3.99'
|
24
|
-
expect(bar.location.mongoize).to eq([2.99, 3.99])
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should set point with space separated text' do
|
28
|
-
bar.location = '2.99 3.99'
|
29
|
-
expect(bar.location.mongoize).to eq([2.99, 3.99])
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should set point with space comma separated text' do
|
33
|
-
bar.location = '2.99 , 3.99'
|
34
|
-
expect(bar.location.mongoize).to eq([2.99, 3.99])
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should set point from hash' do
|
38
|
-
bar.location = { latitude: 2.99, longitude: 3.99 }
|
39
|
-
expect(bar.location.mongoize).to eq([3.99, 2.99])
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'configured as latlon' do
|
43
|
-
before do
|
44
|
-
Mongoid::Geospatial.configure do |config|
|
45
|
-
config.point.x = Mongoid::Geospatial.lat_symbols
|
46
|
-
config.point.y = Mongoid::Geospatial.lng_symbols
|
47
|
-
end
|
48
|
-
end
|
49
|
-
it 'should set point from hash' do
|
50
|
-
bar.location = { latitude: 2.99, longitude: 3.99 }
|
51
|
-
expect(bar.location.mongoize).to eq([2.99, 3.99])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should have a to_s method" do
|
57
|
-
bar = Bar.create!(name: "Moe's", location: [1, 2])
|
58
|
-
expect(bar.location.to_s).to eq('1.0, 2.0')
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should have a to_s method" do
|
62
|
-
bar = Bar.create!(name: "Moe's", location: [1.0009, 21.009])
|
63
|
-
expect(bar.location.to_s).to eq('1.0009, 21.009')
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should have a to_geo_json method" do
|
67
|
-
bar = Bar.create!(name: "Moe's", location: [1.0009, 21.009])
|
68
|
-
expect(bar.location.to_geo_json).to eq({
|
69
|
-
type: "Point", coordinates: [1.0009, 21.009]
|
70
|
-
})
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should have a to_json method" do
|
74
|
-
bar = Bar.create!(name: "Moe's", location: [1.0009, 21.009])
|
75
|
-
expect(bar.location.to_json).to eq("[1.0009,21.009]")
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should have #reverse to get lat, lon' do
|
79
|
-
bar = Bar.create!(name: "Moe's", location: [1, 2])
|
80
|
-
expect(bar.location.reverse).to eq([2, 1])
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should set point to nil' do
|
84
|
-
bar = Bar.create!(name: "Moe's", location: [1, 1])
|
85
|
-
bar.location = nil
|
86
|
-
expect(bar.location).to be_nil
|
87
|
-
expect(bar.save).to be_truthy
|
88
|
-
expect(Bar.where(location: nil).first).to eq(bar)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should update point x' do
|
92
|
-
bar = Bar.create!(name: "Moe's", location: [1, 1])
|
93
|
-
bar.location = [2, 3]
|
94
|
-
expect(bar.save).to be_truthy
|
95
|
-
expect(Bar.first.location.to_a).to eq([2, 3])
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should set point empty string to nil' do
|
99
|
-
bar = Bar.create!(name: "Moe's", location: [1, 1])
|
100
|
-
bar.location = ''
|
101
|
-
expect(bar.location).to be_nil
|
102
|
-
expect(bar.save).to be_truthy
|
103
|
-
expect(Bar.where(location: nil).first).to eq(bar)
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should set point empty array to nil' do
|
107
|
-
bar = Bar.create!(name: "Moe's", location: [1, 1])
|
108
|
-
bar.location = []
|
109
|
-
expect(bar.location).to be_nil
|
110
|
-
expect(bar.save).to be_truthy
|
111
|
-
expect(Bar.where(location: nil).first).to eq(bar)
|
112
|
-
end
|
113
|
-
|
114
|
-
describe 'methods' do
|
115
|
-
let(:bar) { Bar.create!(location: [3, 2]) }
|
116
|
-
|
117
|
-
it 'should have a .to_a' do
|
118
|
-
expect(bar.location.to_a[0..1]).to eq([3.0, 2.0])
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should have an array [] accessor' do
|
122
|
-
expect(bar.location[0]).to eq(3.0)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should have an ActiveModel symbol accessor' do
|
126
|
-
expect(bar[:location].to_a).to eq([3, 2])
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should have a radius helper' do
|
130
|
-
expect(bar.location.radius).to eql([[3.0, 2.0], 1])
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should have a radius sphere helper' do
|
134
|
-
expect(bar.location.radius_sphere[1])
|
135
|
-
.to be_within(0.0001).of(0.00015)
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should have a radius sphere helper in meters' do
|
139
|
-
expect(bar.location.radius_sphere(1000, :m)[1])
|
140
|
-
.to be_within(0.0001).of(0.00015)
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should have a radius sphere helper in miles' do
|
144
|
-
expect(bar.location.radius_sphere(1, :mi)[1])
|
145
|
-
.to be_within(0.0001).of(0.00025)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe 'queryable' do
|
150
|
-
before do
|
151
|
-
Bar.create_indexes
|
152
|
-
end
|
153
|
-
|
154
|
-
describe ':near :near_sphere' do
|
155
|
-
let!(:berlin) do
|
156
|
-
Bar.create(name: :berlin, location: [52.30, 13.25])
|
157
|
-
end
|
158
|
-
|
159
|
-
let!(:prague) do
|
160
|
-
Bar.create(name: :prague, location: [50.5, 14.26])
|
161
|
-
end
|
162
|
-
|
163
|
-
let!(:paris) do
|
164
|
-
Bar.create(name: :paris, location: [48.48, 2.20])
|
165
|
-
end
|
166
|
-
|
167
|
-
let!(:jim) do
|
168
|
-
Person.new(location: [41.23, 2.9])
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'returns the documents sorted closest to furthest' do
|
172
|
-
expect(Bar.closest_to_location(jim.location).to_a)
|
173
|
-
.to eq([paris, prague, berlin])
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'returns the documents sorted closest to furthest' do
|
177
|
-
expect(Bar.where(:location.near => jim.location).to_a)
|
178
|
-
.to eq([paris, prague, berlin])
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'returns the documents sorted closest to furthest' do
|
182
|
-
expect(Bar.near(location: jim.location))
|
183
|
-
.to eq([paris, prague, berlin])
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'returns the documents sorted closest to furthest sphere' do
|
187
|
-
person = Person.new(location: [41.23, 2.9])
|
188
|
-
expect(Bar.near_sphere(location: person.location))
|
189
|
-
.to eq([paris, prague, berlin])
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'returns the documents sorted closest to furthest sphere' do
|
193
|
-
person = Person.new(location: [41.23, 2.9])
|
194
|
-
expect(Bar.where(:location.near_sphere => person.location))
|
195
|
-
.to eq([paris, prague, berlin])
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'returns the documents sorted closest to furthest with max' do
|
199
|
-
expect(Bar.near(location: jim.location).max_distance(location: 10).to_a)
|
200
|
-
.to eq([paris]) # , prague, berlin ]
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe ':within_circle :within_spherical_circle' do
|
205
|
-
let!(:mile1) do
|
206
|
-
Bar.create(name: 'mile1', location: [-73.997345, 40.759382])
|
207
|
-
end
|
208
|
-
|
209
|
-
let!(:mile3) do
|
210
|
-
Bar.create(name: 'mile3', location: [-73.927088, 40.752151])
|
211
|
-
end
|
212
|
-
|
213
|
-
let!(:mile7) do
|
214
|
-
Bar.create(name: 'mile7', location: [-74.0954913, 40.7161472])
|
215
|
-
end
|
216
|
-
|
217
|
-
let!(:mile9) do
|
218
|
-
Bar.create(name: 'mile9', location: [-74.0604951, 40.9178011])
|
219
|
-
end
|
220
|
-
|
221
|
-
let!(:elvis) do
|
222
|
-
Person.new(location: [-73.98, 40.75])
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'returns the documents within a circle' do
|
226
|
-
pending 'Circle'
|
227
|
-
l = [elvis.location, 500.0 / Mongoid::Geospatial::EARTH_RADIUS_KM]
|
228
|
-
expect(Bar.where(:location.within_circle => l).to_a).to include(mile3)
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'returns the documents within a spherical circle' do
|
232
|
-
pending 'Circle'
|
233
|
-
expect(Bar.where(:location.within_spherical_circle =>
|
234
|
-
[elvis.location, 0.0005]).to_a).to eq([mile1])
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'returns the documents within a center circle' do
|
238
|
-
pending 'Circle'
|
239
|
-
expect(Bar.where(:location.within_center_circle =>
|
240
|
-
[elvis.location, 0.0005]).to_a).to eq([mile1])
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'returns the documents within a box' do
|
244
|
-
poly = Mongoid::Geospatial::LineString.new(
|
245
|
-
[elvis.location.map { |c| c + 1 },
|
246
|
-
elvis.location.map { |c| c - 1 }]
|
247
|
-
)
|
248
|
-
expect(Bar.where(:location.within_polygon => [poly.geom_box]).to_a)
|
249
|
-
.to include(mile3)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe '(de)mongoize' do
|
255
|
-
it 'should mongoize array' do
|
256
|
-
bar = Bar.new(location: [10, -9])
|
257
|
-
expect(bar.location.class).to eql(Mongoid::Geospatial::Point)
|
258
|
-
expect(bar.location.x).to be_within(0.1).of(10)
|
259
|
-
expect(bar.location.y).to be_within(0.1).of(-9)
|
260
|
-
end
|
261
|
-
|
262
|
-
it 'should mongoize hash' do
|
263
|
-
geom = Bar.new(location: { x: 10, y: -9 }).location
|
264
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Point)
|
265
|
-
expect(geom.x).to be_within(0.1).of(10)
|
266
|
-
expect(geom.y).to be_within(0.1).of(-9)
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'should mongoize hash with symbols in any order' do
|
270
|
-
geom = Bar.new(location: { y: -9, x: 10 }).location
|
271
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Point)
|
272
|
-
expect(geom.x).to be_within(0.1).of(10)
|
273
|
-
expect(geom.y).to be_within(0.1).of(-9)
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'should mongoize hash with string keys in any order' do
|
277
|
-
geom = Bar.new(location: { 'y' => -9, 'x' => 10 }).location
|
278
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Point)
|
279
|
-
expect(geom.x).to be_within(0.1).of(10)
|
280
|
-
expect(geom.y).to be_within(0.1).of(-9)
|
281
|
-
end
|
282
|
-
|
283
|
-
# should raise
|
284
|
-
# geom.to_geo
|
285
|
-
|
286
|
-
describe 'with rgeo' do
|
287
|
-
describe 'instantiated' do
|
288
|
-
let(:bar) { Bar.new(name: 'Vitinho', location: [10, 10]) }
|
289
|
-
|
290
|
-
it 'should demongoize to rgeo' do
|
291
|
-
expect(bar.location.class).to eql(Mongoid::Geospatial::Point)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial::Polygon do
|
4
|
-
it 'should have correct indexes on farm' do
|
5
|
-
Farm.create_indexes
|
6
|
-
expect(Farm.collection.indexes.get(geom: '2dsphere')).not_to be_nil
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '(de)mongoize' do
|
10
|
-
it 'should support a field mapped as polygon' do
|
11
|
-
farm = Farm.new(area: [[5, 5], [6, 5], [6, 6], [5, 6]])
|
12
|
-
expect(farm.area).to be_a Mongoid::Geospatial::Polygon
|
13
|
-
expect(farm.area).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should store as array on mongo' do
|
17
|
-
Farm.create(area: [[5, 5], [6, 5], [6, 6], [5, 6]])
|
18
|
-
expect(Farm.first.area).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should have a bounding box' do
|
22
|
-
geom = Mongoid::Geospatial::Polygon.new [[1, 5], [6, 5], [6, 6], [5, 6]]
|
23
|
-
expect(geom.bbox).to eq([[1, 5], [6, 6]])
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should have a center point' do
|
27
|
-
geom = Mongoid::Geospatial::Polygon.new [[1, 1], [1, 1], [9, 9], [9, 9]]
|
28
|
-
expect(geom.center).to eq([5.0, 5.0])
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should have a radius helper' do
|
32
|
-
geom = Mongoid::Geospatial::Polygon.new [[1, 1], [1, 1], [9, 9], [9, 9]]
|
33
|
-
expect(geom.radius(10)).to eq([[5.0, 5.0], 10])
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should have a radius sphere' do
|
37
|
-
geom = Mongoid::Geospatial::Polygon.new [[1, 1], [1, 1], [9, 9], [9, 9]]
|
38
|
-
expect(geom.radius_sphere(10)[1]).to be_within(0.001).of(0.001569)
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'with rgeo' do
|
42
|
-
# farm.area.should be_a RGeo::Geographic::SphericalPolygonImpl
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'query' do
|
47
|
-
context ':box, :polygon' do
|
48
|
-
before do
|
49
|
-
Farm.create_indexes
|
50
|
-
end
|
51
|
-
|
52
|
-
let(:ranch) do
|
53
|
-
Farm.create!(name: 'Ranch',
|
54
|
-
area: [[1, 1], [3, 3], [3, 1], [1, 1]],
|
55
|
-
geom: [2, 2])
|
56
|
-
end
|
57
|
-
|
58
|
-
let(:farm) do
|
59
|
-
Farm.create!(name: 'Farm',
|
60
|
-
area: [[47, 1], [48, 1.5], [49, 3], [49, 1], [47, 1]],
|
61
|
-
geom: [48, 1.28])
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'returns the documents within a box' do
|
65
|
-
query = Farm.geo_spatial(:geom.within_polygon => [ranch.area])
|
66
|
-
expect(query.to_a).to eq([ranch])
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns the documents within a polygon' do
|
70
|
-
query = Farm.where(:geom.within_polygon => [farm.area])
|
71
|
-
expect(query.to_a).to eq([farm])
|
72
|
-
end
|
73
|
-
|
74
|
-
# it 'returns the documents within a center' do
|
75
|
-
# pending 'Moped'
|
76
|
-
# expect(Farm.where(:geom.within_circle =>
|
77
|
-
# [ranch.geom, 0.4]).first).to eq(ranch)
|
78
|
-
# end
|
79
|
-
|
80
|
-
# it 'returns the documents within a center_sphere' do
|
81
|
-
# pending 'Moped'
|
82
|
-
# expect(Farm.where(:geom.within_spherical_circle =>
|
83
|
-
# [ranch.geom, 0.1]).first).to eq(ranch)
|
84
|
-
# end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|