mongoid_geospatial 2.8.1 → 2.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40a6843731a3832611eb19ca69e9008580660fb8
4
- data.tar.gz: e3aecc3c1f01dbb4ddda4e7c4401bd45c03c792a
3
+ metadata.gz: 5ac994cd87075d0e5e38f5bee7c1fa62d2d6bc0f
4
+ data.tar.gz: 444d017b5c507586baa79cca90878abc86dee177
5
5
  SHA512:
6
- metadata.gz: 2f33b113b83240f8fbef94eb645c4d380a66c2587b3eb7886fe9db08502df7bf998af9ce99c2c2ede38a64297a6caed57b5d13f706954a3e39dd48b7599f66da
7
- data.tar.gz: 2cecc4bb71f7562f73318cc0915264fe2c7368c5fb441f4a13122d67742ec14f77bcf82ab86f0c9ea5f05320af78bd14b2e686f5b717663024da738a2e57976d
6
+ metadata.gz: 6d654768a8e1099c1fd4675f5a390faead85e32718f395889f9fc973a298efef3a64faf41fa8a2336f27535de63d673e11dd477238decfd90cab5af25ca6109f
7
+ data.tar.gz: 9a2c7861e3f54530ebece165b7ec6b7ca2d93dc9b4c0db6200753fc6af01dc9c420ed6301791d391772ab5144d3ca3bc84e14749faa28c76a750109e47b2d91e
@@ -2,8 +2,8 @@ module Mongoid
2
2
  module Geospatial
3
3
  extend ActiveSupport::Concern
4
4
 
5
- LNG_SYMBOLS = [:x, :lon, :long, :lng, :longitude]
6
- LAT_SYMBOLS = [:y, :lat, :latitude]
5
+ LNG_SYMBOLS = [:x, :lon, :long, :lng, :longitude, 'x', 'lon', 'long', 'longitude']
6
+ LAT_SYMBOLS = [:y, :lat, :latitude, 'y', 'lat', 'latitude']
7
7
 
8
8
  EARTH_RADIUS_KM = 6371 # taken directly from mongodb
9
9
  RAD_PER_DEG = Math::PI / 180
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Geospatial
3
- VERSION = "2.8.1"
3
+ VERSION = "2.8.2"
4
4
  end
5
5
  end
@@ -28,15 +28,17 @@ module Mongoid
28
28
 
29
29
 
30
30
  class Line < GeometryField
31
+
31
32
  def to_geo
32
- GeoRuby::SimpleFeatures::LineString.from_array(self)
33
+ GeoRuby::SimpleFeatures::LineString.from_coordinates([self])
33
34
  end
34
35
 
35
36
  end
36
37
 
37
38
  class Polygon < GeometryField
39
+
38
40
  def to_geo
39
- GeoRuby::SimpleFeatures::Polygon.from_array(self)
41
+ GeoRuby::SimpleFeatures::Polygon.from_coordinates([self])
40
42
  end
41
43
 
42
44
  end
data/spec/models/river.rb CHANGED
@@ -5,8 +5,9 @@ class River
5
5
  field :name, type: String
6
6
  field :length, type: Integer
7
7
  field :average_discharge, type: Integer
8
- field :source, type: Line, spatial: true
8
+ field :course, type: Line, spatial: true
9
9
  # set return_array to true if you do not want a hash returned all the time
10
+ field :source, type: Point, spatial: true
10
11
  field :mouth, type: Point, spatial: {lat: 'latitude', lng: 'longitude'}
11
12
  field :mouth_array, type: Array, spatial: {return_array: true}
12
13
 
@@ -12,8 +12,20 @@ describe "Core Extensions" do
12
12
 
13
13
  describe Hash do
14
14
 
15
- it "should have a #to_xy method" do
16
- { x: 1.1, y: 2.1 }.to_xy.should eql([1.1, 2.1])
15
+ it "converts hash with symbol keys x,y to array with x,y" do
16
+ { x: 1.1, y: 2.1 }.to_xy.should eql([1.1, 2.1])
17
+ end
18
+
19
+ it "converts hash with symbol keys y,x to array with x,y" do
20
+ { y: 2.1, x: 1.1 }.to_xy.should eql([1.1, 2.1])
21
+ end
22
+
23
+ it "converts hash with string keys x,y to array with x,y" do
24
+ { 'x' => 1.1, 'y' => 2.1 }.to_xy.should eql([1.1, 2.1])
25
+ end
26
+
27
+ it "converts hash with string keys y,x to array with x,y" do
28
+ { 'y' => 2.1, 'x' => 1.1 }.to_xy.should eql([1.1, 2.1])
17
29
  end
18
30
 
19
31
  end
@@ -5,14 +5,14 @@ describe Mongoid::Geospatial::Line do
5
5
  describe "(de)mongoize" do
6
6
 
7
7
  it "should support a field mapped as linestring" do
8
- river = River.new(source: [[5,5],[6,5],[6,6],[5,6]])
9
- river.source.should be_a Mongoid::Geospatial::Line
10
- river.source.should eq([[5,5],[6,5],[6,6],[5,6]])
8
+ river = River.new(course: [[5,5],[6,5],[6,6],[5,6]])
9
+ river.course.should be_a Mongoid::Geospatial::Line
10
+ river.course.should eq([[5,5],[6,5],[6,6],[5,6]])
11
11
  end
12
12
 
13
13
  it "should support a field mapped as linestring" do
14
- River.create!(source: [[5,5],[6,5],[6,6],[5,6]])
15
- River.first.source.should eq([[5,5],[6,5],[6,6],[5,6]])
14
+ River.create!(course: [[5,5],[6,5],[6,6],[5,6]])
15
+ River.first.course.should eq([[5,5],[6,5],[6,6],[5,6]])
16
16
  end
17
17
 
18
18
  it "should have a bounding box" do
@@ -162,7 +162,19 @@ describe Mongoid::Geospatial::Point do
162
162
  geom.y.should be_within(0.1).of(-9)
163
163
  end
164
164
 
165
+ it "should mongoize hash with symbols in any order" do
166
+ geom = Bar.new(location: {y: -9, x: 10}).location
167
+ geom.class.should eql(Mongoid::Geospatial::Point)
168
+ geom.x.should be_within(0.1).of(10)
169
+ geom.y.should be_within(0.1).of(-9)
170
+ end
165
171
 
172
+ it "should mongoize hash with string keys in any order" do
173
+ geom = Bar.new(location: {'y' => -9, 'x' => 10}).location
174
+ geom.class.should eql(Mongoid::Geospatial::Point)
175
+ geom.x.should be_within(0.1).of(10)
176
+ geom.y.should be_within(0.1).of(-9)
177
+ end
166
178
 
167
179
  # should raise
168
180
  # geom.to_geo
@@ -57,6 +57,19 @@ describe Mongoid::Geospatial::Point do
57
57
  bar.location.distance(bar2.location).to_i.should be_within(1).of(3973808)
58
58
  end
59
59
 
60
+ describe "simple features" do
61
+
62
+ it "should mongoize lines" do
63
+ river = River.new(course: [[1,2],[3,4],[5,6]])
64
+ river.course.to_geo.should be_instance_of(GeoRuby::SimpleFeatures::LineString)
65
+ end
66
+
67
+ it "should mongoize polygon" do
68
+ farm = Farm.new(area: [[1,2],[3,4],[5,6]])
69
+ farm.area.to_geo.should be_instance_of(GeoRuby::SimpleFeatures::Polygon)
70
+ end
71
+
72
+ end
60
73
  end
61
74
  end
62
75
  end
@@ -52,8 +52,8 @@ describe "RGeo Wrapper" do
52
52
  end
53
53
 
54
54
  it "should not respond to to_geo before loading external" do
55
- river = River.create!(source: [[5,5],[6,5],[6,6],[5,6]])
56
- river.source.should_not respond_to(:to_geo)
55
+ river = River.create!(course: [[5,5],[6,5],[6,6],[5,6]])
56
+ river.course.should_not respond_to(:to_geo)
57
57
  end
58
58
  end
59
59
 
@@ -108,7 +108,7 @@ describe "RGeo Wrapper" do
108
108
 
109
109
  describe Mongoid::Geospatial::Line do
110
110
  it "should mongoize array" do
111
- geom = River.create!(source: [[5,5],[6,5],[6,6],[5,6]]).source
111
+ geom = River.create!(course: [[5,5],[6,5],[6,6],[5,6]]).course
112
112
  geom.class.should eql(Mongoid::Geospatial::Line)
113
113
  geom.to_geo.class.should eql(RGeo::Geographic::SphericalLineStringImpl)
114
114
  geom.to_geo.to_s.should eq "LINESTRING (5.0 5.0, 6.0 5.0, 6.0 6.0, 5.0 6.0)"
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: 2.8.1
4
+ version: 2.8.2
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: 2013-07-21 00:00:00.000000000 Z
12
+ date: 2013-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid