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
@@ -1,222 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial do
|
4
|
-
context 'Class Stuff' do
|
5
|
-
it 'should have an lng_symbols accessor' do
|
6
|
-
expect(Mongoid::Geospatial.lng_symbols).to be_instance_of Array
|
7
|
-
expect(Mongoid::Geospatial.lng_symbols).to include :x
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should have an lat_symbols accessor' do
|
11
|
-
expect(Mongoid::Geospatial.lat_symbols).to be_instance_of Array
|
12
|
-
expect(Mongoid::Geospatial.lat_symbols).to include :y
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'Creating indexes' do
|
17
|
-
it 'should create a 2d index' do
|
18
|
-
Bar.create_indexes
|
19
|
-
expect(Bar.collection.indexes.get(location: '2d')).not_to be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should create a 2dsphere index' do
|
23
|
-
Alarm.create_indexes
|
24
|
-
expect(Alarm.collection.indexes.get(spot: '2dsphere')).not_to be_nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context '#nearby 2d' do
|
29
|
-
before do
|
30
|
-
Bar.create_indexes
|
31
|
-
end
|
32
|
-
after do
|
33
|
-
Bar.collection.indexes.drop_all
|
34
|
-
end
|
35
|
-
|
36
|
-
let!(:moes) do
|
37
|
-
Bar.create!(name: "Moe's", location: [-73.77694444, 40.63861111])
|
38
|
-
end
|
39
|
-
|
40
|
-
let!(:rose) do
|
41
|
-
Bar.create!(name: 'Rosa', location: [-118.40, 33.94])
|
42
|
-
end
|
43
|
-
|
44
|
-
let!(:jane) do
|
45
|
-
Bar.create!(name: "Jane's", location: [1, 1])
|
46
|
-
end
|
47
|
-
|
48
|
-
let!(:foo) do
|
49
|
-
Bar.create!(name: "Foo", location: [3, 3])
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should work specifing center and different location foo' do
|
53
|
-
expect(Bar.nearby(foo.location)).to be_a Mongoid::Criteria
|
54
|
-
expect(Bar.nearby(foo.location).selector).to eq({"location" => {"$near" => [3.0, 3.0]}})
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should work specifing center and different location moes' do
|
58
|
-
expect(Bar.nearby(moes.location).limit(2)).to eq([moes, rose])
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should work finding first' do
|
62
|
-
expect(Bar.nearby(moes.location).first).to eq(moes)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'really should work find first nearby' do
|
66
|
-
expect(Bar.count).to eq(4)
|
67
|
-
expect(Bar.nearby([1, 1]).to_a).to eq([jane, foo, moes, rose])
|
68
|
-
expect(Bar.nearby([2, 2]).to_a.first).to eq(jane)
|
69
|
-
# THIS WILL FAIL MONGOID ISSUE
|
70
|
-
# expect(Bar.nearby(rose.location).first).to eq(rose)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should work specifing first' do
|
74
|
-
bars = Bar.nearby(rose.location).to_a
|
75
|
-
expect(bars.first).to eq(rose)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should work specifing first' do
|
79
|
-
expect(Bar.nearby(rose.location).to_a.first).to eq(rose)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should work specifing first' do
|
83
|
-
expect(Bar.nearby(rose.location).to_a.first).to eq(rose)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should work specifing first' do
|
87
|
-
expect(Bar.nearby(rose.location).first).to eq(rose)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'returns the documents sorted closest to furthest' do
|
91
|
-
expect(Bar.closest_to_location(rose.location).to_a)
|
92
|
-
.to eq([rose, moes, jane, foo])
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'returns the documents sorted closest to furthest' do
|
96
|
-
expect(Bar.closest_to_location(rose.location).limit(2))
|
97
|
-
.to eq([rose, moes])
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'returns the documents sorted closest to furthest' do
|
101
|
-
expect(Bar.closest_to_location(rose.location).first).to eq(rose)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'returns the documents sorted closest to furthest' do
|
105
|
-
expect(Bar.closest_to_location(rose.location).to_a)
|
106
|
-
.to eq([rose, moes, jane, foo])
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should work specifing center and different location foo' do
|
110
|
-
expect(Bar.closest_to_location(foo.location)).to be_a Mongoid::Criteria
|
111
|
-
expect(Bar.closest_to_location(foo.location).selector).to eq({"location" => {"$near" => [3.0, 3.0]}})
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
context '#nearby 2dsphere' do
|
117
|
-
before do
|
118
|
-
Alarm.create_indexes
|
119
|
-
end
|
120
|
-
after do
|
121
|
-
Alarm.collection.indexes.drop_all
|
122
|
-
end
|
123
|
-
let!(:jfk) do
|
124
|
-
Alarm.create(name: 'jfk', spot: [-73.77694444, 40.63861111])
|
125
|
-
end
|
126
|
-
|
127
|
-
let!(:lax) do
|
128
|
-
Alarm.create(name: 'lax', spot: [-118.40, 33.94])
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'should work with specific center and different spot attribute' do
|
132
|
-
expect(Alarm.nearby(lax.spot)).to eq([lax, jfk])
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'should work with default origin' do
|
136
|
-
expect(Alarm.near_sphere(spot: lax.spot)).to eq([lax, jfk])
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'should work with default origin key' do
|
140
|
-
expect(Alarm.where(:spot.near_sphere => lax.spot)).to eq([lax, jfk])
|
141
|
-
end
|
142
|
-
|
143
|
-
context ':paginate' do
|
144
|
-
before do
|
145
|
-
Alarm.create_indexes
|
146
|
-
50.times do
|
147
|
-
Alarm.create(spot: [rand(1..10), rand(1..10)])
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'limits fine with 25' do
|
152
|
-
expect(Alarm.near_sphere(spot: [5, 5])
|
153
|
-
.limit(25).to_a.size).to eq 25
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'limits fine with 25 and skips' do
|
157
|
-
expect(Alarm.near_sphere(spot: [5, 5])
|
158
|
-
.skip(25).limit(25).to_a.size).to eq 25
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'paginates 50' do
|
162
|
-
page1 = Alarm.near_sphere(spot: [5, 5]).limit(25)
|
163
|
-
page2 = Alarm.near_sphere(spot: [5, 5]).skip(25).limit(25)
|
164
|
-
expect((page1 + page2).uniq.size).to eq(50)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context ':query' do
|
169
|
-
before do
|
170
|
-
Alarm.create_indexes
|
171
|
-
3.times do
|
172
|
-
Alarm.create(spot: [jfk.spot.x + rand(0), jfk.spot.y + rand(0)])
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'should filter using extra query option' do
|
177
|
-
query = Alarm.near_sphere(spot: jfk.spot).where(name: jfk.name)
|
178
|
-
expect(query.to_a).to eq [jfk]
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context ':maxDistance' do
|
183
|
-
it 'should get 1 item' do
|
184
|
-
spot = 2465 / Mongoid::Geospatial.earth_radius[:mi]
|
185
|
-
query = Alarm.near_sphere(spot: lax.spot).max_distance(spot: spot)
|
186
|
-
expect(query.to_a.size).to eq 1
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
# context ':distance_multiplier' do
|
191
|
-
# it "should multiply returned distance with multiplier" do
|
192
|
-
# Bar.geo_near(lax.location,
|
193
|
-
# ::distance_multiplier=> Mongoid::Geospatial.earth_radius[:mi])
|
194
|
-
# .second.geo[:distance].to_i.should be_within(1).of(2469)
|
195
|
-
# end
|
196
|
-
# end
|
197
|
-
|
198
|
-
# context ':unit' do
|
199
|
-
# it "should multiply returned distance with multiplier" do
|
200
|
-
# Bar.geo_near(lax.location, :spherical => true, :unit => :mi)
|
201
|
-
# .second.geo[:distance].to_i.should be_within(1).of(2469)
|
202
|
-
# end
|
203
|
-
|
204
|
-
# it "should convert max_distance to radians with unit" do
|
205
|
-
# Bar.geo_near(lax.location, :spherical => true,
|
206
|
-
# :max_distance => 2465, :unit => :mi).size.should == 1
|
207
|
-
# end
|
208
|
-
|
209
|
-
# end
|
210
|
-
|
211
|
-
# end
|
212
|
-
|
213
|
-
# context 'criteria chaining' do
|
214
|
-
# it "should filter by where" do
|
215
|
-
# Bar.where(:name => jfk.name).geo_near(jfk.location).should == [jfk]
|
216
|
-
# Bar.any_of({:name => jfk.name},{:name => lax.name})
|
217
|
-
# .geo_near(jfk.location).should == [jfk,lax]
|
218
|
-
# end
|
219
|
-
# end
|
220
|
-
# end
|
221
|
-
end
|
222
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module Geospatial
|
3
|
-
def self.from_array(ary)
|
4
|
-
ary[0..1].map(&:to_f)
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.from_hash(hsh)
|
8
|
-
raise 'Hash must have at least 2 items' if hsh.size < 2
|
9
|
-
|
10
|
-
[from_hash_x(hsh), from_hash_y(hsh)]
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.from_hash_y(hsh)
|
14
|
-
v = (Mongoid::Geospatial.lat_symbols & hsh.keys).first
|
15
|
-
return hsh[v].to_f if !v.nil? && hsh[v]
|
16
|
-
|
17
|
-
if Mongoid::Geospatial.lng_symbols.index(hsh.keys[1])
|
18
|
-
raise "Hash cannot contain #{Mongoid::Geospatial.lng_symbols.inspect} "\
|
19
|
-
"as second arg without #{Mongoid::Geospatial.lat_symbols.inspect}"
|
20
|
-
end
|
21
|
-
hsh.values[1].to_f
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.from_hash_x(hsh)
|
25
|
-
v = (Mongoid::Geospatial.lng_symbols & hsh.keys).first
|
26
|
-
return hsh[v].to_f if !v.nil? && hsh[v]
|
27
|
-
|
28
|
-
if Mongoid::Geospatial.lat_symbols.index(keys[0])
|
29
|
-
raise "Hash cannot contain #{Mongoid::Geospatial.lat_symbols.inspect} "\
|
30
|
-
"as first arg without #{Mongoid::Geospatial.lng_symbols.inspect}"
|
31
|
-
end
|
32
|
-
values[0].to_f
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Fields do
|
4
|
-
context 'delegate' do
|
5
|
-
before do
|
6
|
-
Bus.create_indexes
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'x, y helpers' do
|
10
|
-
let(:bus) { Bus.create!(name: 'Far', location: [7, 8]) }
|
11
|
-
|
12
|
-
it 'should set instance method x' do
|
13
|
-
expect(bus.x).to eq(7)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should set instance method y' do
|
17
|
-
expect(bus.y).to eq(8)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should set instance method x=' do
|
21
|
-
bus.x = 9
|
22
|
-
expect(bus.x).to eq(9)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should set instance method y=' do
|
26
|
-
bus.y = 9
|
27
|
-
expect(bus.y).to eq(9)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should set instance methods x= and y=' do
|
32
|
-
bus = Bus.create!(name: 'B', location: [7, 7])
|
33
|
-
bus.x = 8
|
34
|
-
bus.y = 9
|
35
|
-
expect(bus.location.to_a).to eq([8, 9])
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should work fine with default values' do
|
39
|
-
event = Event.create!(name: 'Bvent')
|
40
|
-
event.x = 8
|
41
|
-
event.y = 9
|
42
|
-
expect(event.location.to_a).to eq([8, 9])
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should not work fine with nils' do
|
46
|
-
bus = Bus.create!(name: 'B', location: nil)
|
47
|
-
expect do
|
48
|
-
bus.x = 9
|
49
|
-
bus.y = 9
|
50
|
-
end.to raise_error(NoMethodError)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should update point x' do
|
54
|
-
bus = Bus.create!(name: '0789', location: [1, 1])
|
55
|
-
bus.x = 2
|
56
|
-
expect(bus.save).to be_truthy
|
57
|
-
expect(Bus.first.location.to_a).to eq([2, 1])
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should update point y' do
|
61
|
-
bus = Bus.create!(name: '0987', location: [1, 1])
|
62
|
-
bus.y = 2
|
63
|
-
expect(bus.save).to be_truthy
|
64
|
-
expect(Bus.first.location.to_a).to eq([1.0, 2.0])
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Fields do
|
4
|
-
context 'spatial' do
|
5
|
-
before do
|
6
|
-
Bar.create_indexes
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should created indexes' do
|
10
|
-
expect(Bar.collection.indexes.get(location: '2d')).not_to be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should create correct indexes' do
|
14
|
-
expect(Bar.collection.indexes.get(location: '2d'))
|
15
|
-
.to eq('background' => false,
|
16
|
-
'key' => { 'location' => '2d' },
|
17
|
-
'name' => 'location_2d',
|
18
|
-
'v' => 2)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should set spatial fields' do
|
22
|
-
expect(Bar.spatial_fields).to eql([:location])
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should set some class methods' do
|
26
|
-
far = Bar.create!(name: 'Far', location: [7, 7])
|
27
|
-
near = Bar.create!(name: 'Near', location: [2, 2])
|
28
|
-
expect(Bar.nearby([1, 1])).to eq([near, far])
|
29
|
-
end
|
30
|
-
|
31
|
-
# it "should set some class methods" do
|
32
|
-
# far = Bar.create!(name: "Far", location: [7,7])
|
33
|
-
# near = Bar.create!(name: "Near", location: [2,2])
|
34
|
-
# Bar.near_location([1,1]).should eq([near, far])
|
35
|
-
# end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'geom' do
|
39
|
-
end
|
40
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Fields do
|
4
|
-
context 'spatial' do
|
5
|
-
before do
|
6
|
-
Alarm.create_indexes
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should created indexes' do
|
10
|
-
expect(Alarm.collection.indexes.get(spot: '2dsphere')).not_to be_nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should create correct indexes' do
|
14
|
-
expect(Alarm.collection.indexes.get(spot: '2dsphere'))
|
15
|
-
.to include('2dsphereIndexVersion' => 3,
|
16
|
-
'background' => false,
|
17
|
-
'key' => { 'spot' => '2dsphere' },
|
18
|
-
'name' => 'spot_2dsphere',
|
19
|
-
'v' => 2)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should set spatial fields' do
|
23
|
-
expect(Alarm.spatial_fields).to eql([:spot])
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should work fine indexed' do
|
27
|
-
far = Alarm.create!(name: 'Far', spot: [7, 7])
|
28
|
-
expect(far.spot).to be_instance_of(Mongoid::Geospatial::Point)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial::Point do
|
4
|
-
it 'should not interfer with mongoid' do
|
5
|
-
Place.create!(name: "Moe's")
|
6
|
-
expect(Place.count).to eql(1)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should not respond to distance before loading external gem' do
|
10
|
-
bar = Place.create!(location: [5, 5])
|
11
|
-
expect(bar.location).not_to respond_to(:distance)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'queryable' do
|
15
|
-
before do
|
16
|
-
Mongoid::Geospatial.with_georuby!
|
17
|
-
Place.create_indexes
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '(de)mongoize' do
|
21
|
-
it 'should mongoize array' do
|
22
|
-
geom = Place.new(location: [10, -9]).location
|
23
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Point)
|
24
|
-
expect(geom.to_geo.class).to eql(GeoRuby::SimpleFeatures::Point)
|
25
|
-
expect(geom.x).to be_within(0.1).of(10)
|
26
|
-
expect(geom.to_geo.y).to be_within(0.1).of(-9)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should mongoize hash' do
|
30
|
-
geom = Place.new(location: { x: 10, y: -9 }).location
|
31
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Point)
|
32
|
-
expect(geom.to_geo.class).to eql(GeoRuby::SimpleFeatures::Point)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should accept a GeoRuby point' do
|
36
|
-
point = GeoRuby::SimpleFeatures::Point.from_x_y 1, 2
|
37
|
-
bar = Place.create!(location: point)
|
38
|
-
expect(bar.location.x).to be_within(0.1).of(1)
|
39
|
-
expect(bar.location.y).to be_within(0.1).of(2)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should calculate 3d distances by default' do
|
43
|
-
bar = Place.create! location: [-73.77694444, 40.63861111]
|
44
|
-
bar2 = Place.create! location: [-118.40, 33.94] # ,:unit=>:mi, :spherical => true)
|
45
|
-
expect(bar.location.geo_distance(bar2.location).to_i).to be_within(1).of(3_973_808)
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'simple features' do
|
49
|
-
it 'should mongoize lines' do
|
50
|
-
river = River.new(course: [[1, 2], [3, 4], [5, 6]])
|
51
|
-
expect(river.course.to_geo)
|
52
|
-
.to be_instance_of(GeoRuby::SimpleFeatures::LineString)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should mongoize polygon' do
|
56
|
-
farm = Farm.new(area: [[1, 2], [3, 4], [5, 6]])
|
57
|
-
expect(farm.area.to_geo)
|
58
|
-
.to be_instance_of(GeoRuby::SimpleFeatures::Polygon)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'RGeo Wrapper' do
|
4
|
-
describe Mongoid::Geospatial::Point do
|
5
|
-
it 'should not interfer with mongoid' do
|
6
|
-
Bar.create!(name: "Moe's")
|
7
|
-
expect(Bar.count).to eql(1)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should not respond to distance before loading external' do
|
11
|
-
bar = Bar.create!(location: [5, 5])
|
12
|
-
expect(bar.location).not_to respond_to(:distance)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe Mongoid::Geospatial::Polygon do
|
17
|
-
it 'should not interfer with mongoid' do
|
18
|
-
Farm.create!(name: 'Springfield Nuclear Power Plant')
|
19
|
-
expect(Farm.count).to eql(1)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should respond to to_geo' do
|
23
|
-
farm = Farm.create!(area: [[5, 5], [6, 5], [6, 6], [5, 6]])
|
24
|
-
expect(farm.area).to respond_to(:to_geo)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Mongoid::Geospatial::LineString do
|
29
|
-
it 'should not interfer with mongoid' do
|
30
|
-
River.create!(name: 'Mississippi')
|
31
|
-
expect(River.count).to eql(1)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should respond to to_geo before loading external' do
|
35
|
-
river = River.create!(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
|
36
|
-
expect(river.course).to respond_to(:to_geo)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'queryable' do
|
41
|
-
before do
|
42
|
-
Mongoid::Geospatial.with_rgeo!
|
43
|
-
Bar.create_indexes
|
44
|
-
Farm.create_indexes
|
45
|
-
River.create_indexes
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '(de)mongoize' do
|
49
|
-
describe Mongoid::Geospatial::Point do
|
50
|
-
it 'should mongoize array' do
|
51
|
-
geom = Bar.new(location: [10, -9]).location
|
52
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Point)
|
53
|
-
expect(geom.x).to be_within(0.1).of(10)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should wrap to georuby' do
|
57
|
-
geom = Bar.new(location: [10, -9]).location
|
58
|
-
expect(geom.to_geo.class)
|
59
|
-
.to eql(GeoRuby::SimpleFeatures::Point)
|
60
|
-
expect(geom.to_geo.y).to be_within(0.1).of(-9)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should wrap to rgeo' do
|
64
|
-
geom = Bar.new(location: [10, -9]).location
|
65
|
-
expect(geom.to_rgeo.class)
|
66
|
-
.to eql(RGeo::Geographic::SphericalPointImpl)
|
67
|
-
expect(geom.to_rgeo.y).to be_within(0.1).of(-9)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should mongoize hash' do
|
71
|
-
geom = Bar.new(location: { x: 10, y: -9 }).location
|
72
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Point)
|
73
|
-
expect(geom.to_rgeo.class)
|
74
|
-
.to eql(RGeo::Geographic::SphericalPointImpl)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should accept an RGeo object' do
|
78
|
-
point = RGeo::Geographic.spherical_factory.point 1, 2
|
79
|
-
bar = Bar.create!(location: point)
|
80
|
-
expect(bar.location.x).to be_within(0.1).of(1)
|
81
|
-
expect(bar.location.y).to be_within(0.1).of(2)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should calculate 3d distances by default' do
|
85
|
-
bar = Bar.create! location: [-73.77694444, 40.63861111]
|
86
|
-
bar2 = Bar.create! location: [-118.40, 33.94] # ,:unit=>:mi
|
87
|
-
expect(bar.location.rgeo_distance(bar2.location).to_i)
|
88
|
-
.to be_within(1).of(3_978_262)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe Mongoid::Geospatial::Polygon do
|
93
|
-
it 'should mongoize array' do
|
94
|
-
geom = Farm.create!(area: [[5, 5], [6, 5], [6, 6], [5, 6]]).area
|
95
|
-
expect(geom.class).to eql(Mongoid::Geospatial::Polygon)
|
96
|
-
expect(geom.to_rgeo.class)
|
97
|
-
.to eql(RGeo::Geographic::SphericalPolygonImpl)
|
98
|
-
expect(geom.to_rgeo.to_s)
|
99
|
-
.to eq 'POLYGON ((5.0 5.0, 6.0 5.0, 6.0 6.0, 5.0 6.0, 5.0 5.0))'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe Mongoid::Geospatial::LineString do
|
104
|
-
it 'should mongoize array' do
|
105
|
-
geom = River.create!(course: [[5, 5], [6, 5], [6, 6], [5, 6]]).course
|
106
|
-
expect(geom.class).to eql(Mongoid::Geospatial::LineString)
|
107
|
-
expect(geom.to_rgeo.class)
|
108
|
-
.to eql(RGeo::Geographic::SphericalLineStringImpl)
|
109
|
-
expect(geom.to_rgeo.to_s)
|
110
|
-
.to eq 'LINESTRING (5.0 5.0, 6.0 5.0, 6.0 6.0, 5.0 6.0)'
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|