georuby-ext 0.0.1

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.
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe GeoRuby::SimpleFeatures::MultiPolygon do
4
+
5
+ describe "#to_wgs84" do
6
+
7
+ let(:polygon_google) {polygon(point(0,0), point(0,1), point(1,0), point(0,0))}
8
+ let(:polygon_wgs84) { GeoRuby::SimpleFeatures::Polygon.from_points([[point(0, 0, 4326), point(0, 0.000008983152840993819, 4326), point(0.000008983152841195214, 0, 4326), point(0, 0, 4326)]], 4326)}
9
+ let(:multi_polygon_google) {multi_polygon(polygon_google, polygon_google)}
10
+ let(:multi_polygon_wgs84) {GeoRuby::SimpleFeatures::MultiPolygon.from_polygons([polygon_wgs84, polygon_wgs84], 4326)}
11
+
12
+ it "should return a polygon in wgs84 coordinates" do
13
+ multi_polygon_google.to_wgs84.should == multi_polygon_wgs84
14
+ end
15
+
16
+ it "should return same srid" do
17
+ multi_polygon_google.to_wgs84.srid.should == multi_polygon_wgs84.srid
18
+ end
19
+ end
20
+
21
+ describe "#polygons" do
22
+ let(:georuby_polygon){ polygon(point(0.0,0.0), point(0.0,2.0), point(2.0,2.0), point(2.0,0.0), point(0.0,0.0))}
23
+ let(:georuby_multi_polygon){multi_polygon(georuby_polygon, georuby_polygon)}
24
+ it "should return an array of polygons" do
25
+ georuby_multi_polygon.polygons.should == [georuby_polygon, georuby_polygon]
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoRuby::SimpleFeatures::Point do
4
+
5
+ describe "to_rgeo" do
6
+ it "should create a RGeo::Feature::Point" do
7
+ point(0,0).to_rgeo.should == rgeo_point(0,0)
8
+ end
9
+ end
10
+
11
+ describe "centroid" do
12
+
13
+ def centroid(*args)
14
+ GeoRuby::SimpleFeatures::Point.centroid *args
15
+ end
16
+
17
+ it "should return nil if no points in input" do
18
+ centroid([]).should be_nil
19
+ end
20
+
21
+ it "should return point in input if only one" do
22
+ centroid([point(0,0)]).should == point(0,0)
23
+ end
24
+
25
+ it "should return middle if two points in input" do
26
+ centroid([point(0.0,0.0), point(1.0,0.0)]).should == point(0.5,0.0)
27
+ end
28
+
29
+ it "should return centroid of given points" do
30
+ centroid([point(0,0), point(0,2), point(2,2), point(2,0)]).should == point(1,1)
31
+ end
32
+
33
+ end
34
+
35
+ describe "#to_wgs84" do
36
+ it "should return true when we compare points coordinates" do
37
+ point(1, 1).to_wgs84.should == point(0.000008983152841195214, 0.000008983152840993819, 4326)
38
+ end
39
+
40
+ it "should return a point with 4326 srid" do
41
+ point.to_wgs84.srid.should == 4326
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoRuby::SimpleFeatures::Polygon do
4
+ describe "circle" do
5
+
6
+ let(:center) {p(1,1)}
7
+ let(:radius) {1}
8
+ let(:sides) {8}
9
+
10
+ def p(x,y)
11
+ GeoRuby::SimpleFeatures::Point.from_x_y x,y
12
+ end
13
+
14
+ def circle(arguments = {})
15
+ arguments = { :center => center, :radius => radius, :sides => sides }.merge(arguments)
16
+ GeoRuby::SimpleFeatures::Polygon.circle(*arguments.values_at(:center, :radius, :sides))
17
+ end
18
+
19
+ it "should create a square" do
20
+ p1 = GeoRuby::SimpleFeatures::Point.from_lat_lng(center.to_lat_lng.endpoint(45, radius, {:units => :kms}))
21
+ p2 = GeoRuby::SimpleFeatures::Point.from_lat_lng(center.to_lat_lng.endpoint(135, radius, {:units => :kms}))
22
+ p3 = GeoRuby::SimpleFeatures::Point.from_lat_lng(center.to_lat_lng.endpoint(225, radius, {:units => :kms}))
23
+ p4 = GeoRuby::SimpleFeatures::Point.from_lat_lng(center.to_lat_lng.endpoint(315, radius, {:units => :kms}))
24
+ circle(:sides => 4).should be_same_polygon([[p1.x,p1.y], [p2.x,p2.y], [p3.x,p3.y], [p4.x,p4.y], [p1.x, p1.y]])
25
+ end
26
+
27
+ it "should have the given side count" do
28
+ circle(:sides => 16).side_count.should == 16
29
+ end
30
+
31
+ it "should be closed" do
32
+ circle(:sides => 16).rings.each do |ring|
33
+ ring.is_closed.should be_true
34
+ end
35
+ end
36
+
37
+ it "should have all its points as the radius distance of the center" do
38
+ first_distance = circle.points.first.euclidian_distance(center)
39
+ circle.points.collect do |point|
40
+ point.euclidian_distance(center)
41
+ end.each do |distance|
42
+ #puts distance
43
+ #puts first_distance
44
+ distance.should be_within(0.0001).of(first_distance)
45
+ end
46
+ end
47
+
48
+ it "should have the same distance between all its points" do
49
+ points = circle.points.dup
50
+ previous = points.shift
51
+ distances = points.collect do |point|
52
+ previous.euclidian_distance(point).tap do |distance|
53
+ previous = point
54
+ end
55
+ end
56
+
57
+ average_distance = distances.sum / distances.size
58
+
59
+ distances.each do |distance|
60
+ distance.should be_within(0.01).of(average_distance)
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "#to_wgs84" do
66
+ let(:polygon_google) {polygon(point(0,0), point(0,1), point(1,0), point(0,0))}
67
+ let(:polygon_wgs84) { GeoRuby::SimpleFeatures::Polygon.from_points([[point(0, 0, 4326), point(0, 0.000008983152840993819, 4326), point(0.000008983152841195214, 0, 4326), point(0, 0, 4326)]], 4326)}
68
+
69
+ it "should return a polygon in wgs84 coordinates" do
70
+ polygon_google.to_wgs84.should == polygon_wgs84
71
+ end
72
+
73
+ it "should return same srid" do
74
+ polygon_google.to_wgs84.srid.should == polygon_wgs84.srid
75
+ end
76
+ end
77
+
78
+ describe "to_rgeo" do
79
+
80
+ let(:result) {factory = RGeo::Geos::Factory.create
81
+ factory.polygon(factory.line_string([factory.point(0, 0), factory.point(0, 2), factory.point(2, 2), factory.point(2, 0), factory.point(0, 0)]))}
82
+
83
+ let(:georuby_polygon){ polygon(point(0,0), point(0,2), point(2,2), point(2,0), point(0,0))}
84
+ it "should return a polygon RGeo::Feature::Polygon" do
85
+ georuby_polygon.to_rgeo.should == result
86
+ end
87
+ end
88
+
89
+ describe "centroid" do
90
+ let(:georuby_polygon){ polygon(point(0,0), point(0,2), point(2,2), point(2,0), point(0,0))}
91
+
92
+ it "should return centroid for a polygon" do
93
+ georuby_polygon.centroid.should == point(1,1)
94
+ end
95
+
96
+ end
97
+
98
+
99
+ describe "union" do
100
+
101
+ let(:result){ polygon(point(0.0,0.0), point(0.0,2.0), point(0.0,4.0), point(2.0,4.0), point(2.0,2.0), point(2.0,0.0), point(0.0,0.0))}
102
+ let(:georuby_polygon){ polygon(point(0.0,0.0), point(0.0,2.0), point(2.0,2.0), point(2.0,0.0), point(0.0,0.0))}
103
+ let(:georuby_polygon2){ polygon(point(0.0,0.0), point(0.0,4.0), point(2.0,4.0), point(2.0,0.0), point(0.0,0.0))}
104
+
105
+ it "should return the same polygon than in input" do
106
+ test = GeoRuby::SimpleFeatures::Polygon.union([georuby_polygon, georuby_polygon])
107
+ GeoRuby::SimpleFeatures::Polygon.union([georuby_polygon, georuby_polygon]).text_representation.should == georuby_polygon.text_representation
108
+ end
109
+
110
+ it "should return union of polygons" do
111
+ GeoRuby::SimpleFeatures::Polygon.union([georuby_polygon, georuby_polygon2]).text_representation.should == result.text_representation
112
+ end
113
+
114
+ end
115
+
116
+ describe "intersect" do
117
+ let(:georuby_polygon){ polygon(point(0.0,0.0), point(0.0,2.0), point(2.0,2.0), point(2.0,0.0), point(0.0,0.0))}
118
+ let(:georuby_polygon2){ polygon(point(0.0,0.0), point(0.0,4.0), point(2.0,4.0), point(2.0,0.0), point(0.0,0.0))}
119
+
120
+ it "should return intersect of polygons" do
121
+ test = GeoRuby::SimpleFeatures::Polygon.intersection([georuby_polygon, georuby_polygon2])
122
+ GeoRuby::SimpleFeatures::Polygon.intersection([georuby_polygon, georuby_polygon2]).text_representation.should == georuby_polygon.text_representation
123
+ end
124
+ end
125
+
126
+ describe "#==" do
127
+
128
+ it "should be true when points are same" do
129
+ geometry("POLYGON((0 0,1 1))").should == geometry("POLYGON((0 0,1 1))")
130
+ end
131
+
132
+ end
133
+
134
+ end
@@ -0,0 +1,81 @@
1
+ require "spec_helper"
2
+
3
+ describe RGeo::Geos::PointImpl do
4
+
5
+ subject { rgeo_point }
6
+
7
+ describe "#to_georuby" do
8
+
9
+ it "should return a GeoRuby::SimpleFeatures::Point" do
10
+ subject.to_georuby.should be_instance_of(GeoRuby::SimpleFeatures::Point)
11
+ end
12
+
13
+ it "should have the same x" do
14
+ subject.to_georuby.x.should == subject.x
15
+ end
16
+
17
+ it "should have the same y" do
18
+ subject.to_georuby.y.should == subject.y
19
+ end
20
+
21
+ it "should have the same srid" do
22
+ subject.to_georuby.srid.should == subject.srid
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ describe RGeo::Geos::LineImpl do
30
+
31
+ subject { rgeometry("LINESTRING(0 0, 1 1)") }
32
+
33
+ describe "#to_georuby" do
34
+
35
+ it "should return a GeoRuby::SimpleFeatures::LineString" do
36
+ subject.to_georuby.should be_instance_of(GeoRuby::SimpleFeatures::LineString)
37
+ end
38
+
39
+ it "should return a LineString with the same information" do
40
+ subject.to_georuby.should == geometry("LINESTRING(0 0, 1 1)")
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ describe RGeo::Geos::PolygonImpl do
48
+
49
+ subject { rgeometry("POLYGON((0 0,1 0,0 1,0 0))") }
50
+
51
+ describe "#to_georuby" do
52
+
53
+ it "should return a GeoRuby::SimpleFeatures::Polygon" do
54
+ subject.to_georuby.should be_instance_of(GeoRuby::SimpleFeatures::Polygon)
55
+ end
56
+
57
+ it "should return a Polygon with the same information" do
58
+ subject.to_georuby.should == geometry("POLYGON((0 0,1 0,0 1,0 0))")
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ describe RGeo::Geos::MultiPolygonImpl do
66
+
67
+ subject { rgeometry("MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))") }
68
+
69
+ describe "#to_georuby" do
70
+
71
+ it "should return a GeoRuby::SimpleFeatures::MultiPolygon" do
72
+ subject.to_georuby.should be_instance_of(GeoRuby::SimpleFeatures::MultiPolygon)
73
+ end
74
+
75
+ it "should return a MultiPolygon with the same information" do
76
+ subject.to_georuby.should == geometry("MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))")
77
+ end
78
+
79
+ end
80
+
81
+ end
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'rspec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'rspec'
6
+ end
7
+
8
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
9
+
10
+ require 'georuby-ext'
11
+ require 'georuby-ext/rspec_helper'
12
+
13
+ RSpec::Matchers.define :have_same do |*attributes|
14
+ chain :than do |other|
15
+ @other = other
16
+ end
17
+
18
+ match do |model|
19
+ attributes.all? do |attribute|
20
+ model.send(attribute) == @other.send(attribute)
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,227 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: georuby-ext
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Marc Florisson
14
+ - Luc Donnet
15
+ - Alban Peignier
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-10-11 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ name: rspec
33
+ type: :development
34
+ prerelease: false
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ name: rake
47
+ type: :development
48
+ prerelease: false
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ name: guard
61
+ type: :development
62
+ prerelease: false
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ name: rcov
75
+ type: :development
76
+ prerelease: false
77
+ requirement: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ name: GeoRuby
89
+ type: :runtime
90
+ prerelease: false
91
+ requirement: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ version_requirements: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ name: geokit
103
+ type: :runtime
104
+ prerelease: false
105
+ requirement: *id006
106
+ - !ruby/object:Gem::Dependency
107
+ version_requirements: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ name: rgeo
117
+ type: :runtime
118
+ prerelease: false
119
+ requirement: *id007
120
+ - !ruby/object:Gem::Dependency
121
+ version_requirements: &id008 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ name: proj4rb
131
+ type: :runtime
132
+ prerelease: false
133
+ requirement: *id008
134
+ - !ruby/object:Gem::Dependency
135
+ version_requirements: &id009 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ name: activesupport
145
+ type: :runtime
146
+ prerelease: false
147
+ requirement: *id009
148
+ description: Use together GeoRuby, rgeo, geokit, proj4j (and others)
149
+ email:
150
+ - marc@dryade.net
151
+ - luc@dryade.net
152
+ - alban@dryade.net
153
+ executables: []
154
+
155
+ extensions: []
156
+
157
+ extra_rdoc_files: []
158
+
159
+ files:
160
+ - .gitignore
161
+ - Gemfile
162
+ - Guardfile
163
+ - README.rdoc
164
+ - Rakefile
165
+ - georuby-ext.gemspec
166
+ - lib/georuby-ext.rb
167
+ - lib/georuby-ext/geokit.rb
168
+ - lib/georuby-ext/georuby/envelope.rb
169
+ - lib/georuby-ext/georuby/geometry.rb
170
+ - lib/georuby-ext/georuby/line_string.rb
171
+ - lib/georuby-ext/georuby/locators.rb
172
+ - lib/georuby-ext/georuby/multi_polygon.rb
173
+ - lib/georuby-ext/georuby/point.rb
174
+ - lib/georuby-ext/georuby/polygon.rb
175
+ - lib/georuby-ext/proj4.rb
176
+ - lib/georuby-ext/rgeo.rb
177
+ - lib/georuby-ext/rspec_helper.rb
178
+ - spec/georuby/line_string_spec.rb
179
+ - spec/georuby/linear_ring_spec.rb
180
+ - spec/georuby/locators_spec.rb
181
+ - spec/georuby/multi_polygon_spec.rb
182
+ - spec/georuby/point_spec.rb
183
+ - spec/georuby/polygon_spec.rb
184
+ - spec/rgeo_spec.rb
185
+ - spec/spec_helper.rb
186
+ homepage: http://github.com/dryade/georuby-ext
187
+ licenses: []
188
+
189
+ post_install_message:
190
+ rdoc_options: []
191
+
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ none: false
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ hash: 3
200
+ segments:
201
+ - 0
202
+ version: "0"
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ none: false
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ hash: 3
209
+ segments:
210
+ - 0
211
+ version: "0"
212
+ requirements: []
213
+
214
+ rubyforge_project: georuby-ext
215
+ rubygems_version: 1.7.2
216
+ signing_key:
217
+ specification_version: 3
218
+ summary: Extension to Ruby geometry libraries
219
+ test_files:
220
+ - spec/georuby/line_string_spec.rb
221
+ - spec/georuby/linear_ring_spec.rb
222
+ - spec/georuby/locators_spec.rb
223
+ - spec/georuby/multi_polygon_spec.rb
224
+ - spec/georuby/point_spec.rb
225
+ - spec/georuby/polygon_spec.rb
226
+ - spec/rgeo_spec.rb
227
+ - spec/spec_helper.rb