gotime-postgis_adapter 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +13 -0
- data/Gemfile.lock +31 -0
- data/History.txt +6 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +380 -0
- data/Rakefile +70 -0
- data/lib/postgis_adapter/acts_as_geom.rb +43 -0
- data/lib/postgis_adapter/common_spatial_adapter.rb +105 -0
- data/lib/postgis_adapter/functions/bbox.rb +130 -0
- data/lib/postgis_adapter/functions/class.rb +67 -0
- data/lib/postgis_adapter/functions/common.rb +921 -0
- data/lib/postgis_adapter/functions.rb +174 -0
- data/lib/postgis_adapter/railtie.rb +7 -0
- data/lib/postgis_adapter.rb +446 -0
- data/postgis_adapter.gemspec +19 -0
- data/rails/init.rb +28 -0
- data/spec/db/models_postgis.rb +65 -0
- data/spec/db/schema_postgis.rb +98 -0
- data/spec/postgis_adapter/acts_as_geom_spec.rb +30 -0
- data/spec/postgis_adapter/common_spatial_adapter_spec.rb +254 -0
- data/spec/postgis_adapter/functions/bbox_spec.rb +45 -0
- data/spec/postgis_adapter/functions/class_spec.rb +79 -0
- data/spec/postgis_adapter/functions/common_spec.rb +428 -0
- data/spec/postgis_adapter/functions_spec.rb +60 -0
- data/spec/postgis_adapter_spec.rb +238 -0
- data/spec/spec_helper.rb +45 -0
- metadata +93 -0
@@ -0,0 +1,428 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Common Functions" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@poly = Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]], 4326)
|
7
|
+
@c1 ||= City.create!(:data => "City1", :geom => @poly)
|
8
|
+
@c2 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[22,66],[65,65],[20,10],[22,66]],[[10,15],[15,11],[34,14],[10,15]]],4326))
|
9
|
+
@c3 ||= City.create!(:data => "City3", :geom => Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]],4326))
|
10
|
+
@s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],4326))
|
11
|
+
@sx ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[2,2],[4,4]],4326))
|
12
|
+
@s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],4326))
|
13
|
+
@s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],4326))
|
14
|
+
@s4 ||= Street.create!(:data => "Street4", :geom => LineString.from_coordinates([[10,8],[15,18]],4326))
|
15
|
+
@p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,4326))
|
16
|
+
@p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,4326))
|
17
|
+
@p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,4326))
|
18
|
+
@p4 ||= Position.create!(:data => "Point4", :geom => Point.from_x_y(18.1,18,4326))
|
19
|
+
@p5 ||= Position.create!(:data => "Point5", :geom => Point.from_x_y(30,30,4326))
|
20
|
+
@m1 ||= Road.create(:data => "MG-050", :geom => MultiLineString.from_line_strings([@s1.geom, @sx.geom]))
|
21
|
+
@m2 ||= Road.create(:data => "MG-050", :geom => MultiLineString.from_line_strings([@s3.geom, @s4.geom]))
|
22
|
+
@p6 ||= Position.create!(:data => "Point6", :geom => Point.from_x_y(30.9999,30.9999,4326))
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Point" do
|
26
|
+
|
27
|
+
it "should find the closest other point" do
|
28
|
+
Position.close_to(@p1.geom)[0].data.should == @p1.data
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should find the closest other point" do
|
32
|
+
Position.closest_to(@p1.geom).data.should == @p1.data
|
33
|
+
end
|
34
|
+
|
35
|
+
it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.0001) }
|
36
|
+
it { @p1.distance_to(@s3).should be_close(9.89949493661167, 0.0001) }
|
37
|
+
it { @p2.distance_to(@s3).should be_close(4.24264068711928, 0.0001) }
|
38
|
+
it { @p1.distance_to(@p2).should be_close(5.65685424949238, 0.0001) }
|
39
|
+
it { @p1.distance_to(@c1).should be_close(3.0, 0.0001) }
|
40
|
+
it { @p1.distance_to(@c2).should be_close(21.0237960416286, 0.000001) }
|
41
|
+
it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.000001) }
|
42
|
+
it { @p1.distance_sphere_to(@p2).should be_close(628519.033787529, 0.0001) }
|
43
|
+
it { @p1.distance_sphere_to(@p3).should be_close(1098730.38927754, 0.00001) }
|
44
|
+
it { @p1.distance_spheroid_to(@p2).should be_close(627129.50,0.01) }
|
45
|
+
it { @p1.distance_spheroid_to(@p2).should be_close(627129.502561203, 0.000001) }
|
46
|
+
it { @p1.distance_spheroid_to(@p3).should be_close(1096324.48105195, 0.000001) }
|
47
|
+
|
48
|
+
it "should find the distance from a unsaved point" do
|
49
|
+
@p1.distance_to(@p2).should be_close(5.65685424949238,0.001)
|
50
|
+
@p1.distance_to(Point.from_x_y(5,5,4326)).should be_close(5.65685424949238,0.001)
|
51
|
+
end
|
52
|
+
|
53
|
+
it { @p1.should_not be_inside(@c1) }
|
54
|
+
it { @p1.should be_outside(@c1) }
|
55
|
+
it { @p1.should be_inside_circle(2.0,2.0,20.0) }
|
56
|
+
it { @p1.should_not be_inside_circle(50,50,2) }
|
57
|
+
it { @p1.should be_in_bounds(@s1) }
|
58
|
+
it { @p3.should_not be_in_bounds(@s1, 1) }
|
59
|
+
it { @p4.in_bounds?(@s3, 0.01).should be_false }
|
60
|
+
|
61
|
+
it { @p1.azimuth(@p2).should be_close(0.785398163397448,0.000001) }
|
62
|
+
it { @p1.azimuth(@s2).should raise_error }
|
63
|
+
it { @p1.disjoint?(@s2).should be_true }
|
64
|
+
it { @p3.polygonize.geometries.should be_empty }
|
65
|
+
it { @p4.where_on_line(@s3).should be_close(0.335, 0.0001) }
|
66
|
+
it { @s3.locate_point(@p4).should be_close(0.335, 0.1)}
|
67
|
+
it { @s3.interpolate_point(0.335).x.should be_close(18.05, 0.01) }
|
68
|
+
|
69
|
+
it { @p1.relate?(@s3, "T*T***FF*").should be_false }
|
70
|
+
it { @p1.relate?(@s3).should eql("FF0FFF102") }
|
71
|
+
|
72
|
+
it "should transform srid" do
|
73
|
+
@p1.geom = @p1.transform(29101)
|
74
|
+
@p1.geom.srid.should eql(29101)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should transform non saved srid geoms" do
|
78
|
+
pt = Point.from_x_y(11121381.4586196,10161852.0494475, 29101)
|
79
|
+
pos = Position.new(:geom => pt)
|
80
|
+
pos.transform!(4326)
|
81
|
+
pos.geom.x.should be_close(1.00000000000005, 0.00001)
|
82
|
+
pos.geom.y.should be_close(1.00000000000005, 0.00001)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should see in what fraction of the ls it is" do
|
86
|
+
@p1.where_on_line(@s1).should eql(0.0)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should see in what fraction of the ls it is" do
|
90
|
+
@p2.where_on_line(@s2).should be_close(0.3333, 0.1)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have a srid getter" do
|
94
|
+
@p1.srid.should eql(29101)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should calculate the UTM srid" do
|
98
|
+
@p2.utm_zone.should eql(32731)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should convert to utm zone" do
|
102
|
+
lambda { @p2.to_utm! }.should change(@p2, :srid)
|
103
|
+
end
|
104
|
+
|
105
|
+
if PG_VERSION >= "8.4.0"
|
106
|
+
it "should export as GeoJSON" do
|
107
|
+
@p1.as_geo_json.should eql("{\"type\":\"Point\",\"coordinates\":[1,1]}")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should export as GeoJSON with variable precision" do
|
111
|
+
@p6.as_geo_json(1).should eql("{\"type\":\"Point\",\"coordinates\":[31,31]}")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should export as GeoJSON with variable precision and bounding box" do
|
115
|
+
@p6.as_geo_json(1,1).should eql("{\"type\":\"Point\",\"bbox\":[31.0,31.0,31.0,31.0],\"coordinates\":[31,31]}")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
# it { @p3.x.should be_close(8.0, 0.1) }
|
122
|
+
# it { @p3.y.should be_close(8.0, 0.1) }
|
123
|
+
# it { @p3.z.should be_close(0.0, 0.1) }
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "Polygon" do
|
128
|
+
|
129
|
+
it { City.first.data.should eql("City1") }
|
130
|
+
|
131
|
+
it "sort by area size" do
|
132
|
+
City.by_area.first.data.should == "City1" #[@c1, @c2, @c3]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "find all cities that contains a point" do
|
136
|
+
City.contains(@p1.geom, 4326).should eql([])
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should find one city (first) that contains a point" do
|
140
|
+
City.contain(@p4.geom, 4326).data.should eql("City1")
|
141
|
+
end
|
142
|
+
|
143
|
+
it { @c2.should be_closed }
|
144
|
+
it { @c2.dimension.should eql(2) }
|
145
|
+
|
146
|
+
it { @c3.area.should be_close(1093.270089, 0.1) }
|
147
|
+
it { @c2.area.should be_close(1159.5, 0.1) }
|
148
|
+
it { @c2.area(32640).should be_close(5852791139841.2, 0.01) }
|
149
|
+
|
150
|
+
it { @c2.perimeter.should be_close(219.770013855493, 0.1) }
|
151
|
+
it { @c2.perimeter(32640).should be_close(23061464.4268903, 0.1) }
|
152
|
+
it { @c2.perimeter3d.should be_close(219.770013855493, 0.1) }
|
153
|
+
|
154
|
+
it { @c1.contains?(@p1).should be_false }
|
155
|
+
it { @c1.contains?(@p4).should be_true }
|
156
|
+
|
157
|
+
it { @c1.should_not be_spatially_equal(@c2) }
|
158
|
+
|
159
|
+
it { @c1.covers?(@p1).should be_false }
|
160
|
+
it { @c1.covers?(@p4).should be_true }
|
161
|
+
it { @c1.within?(@c2).should be_false }
|
162
|
+
|
163
|
+
it "city overlaps point?" do
|
164
|
+
lambda { @c3.overlaps?(@c2) }.should raise_error # WHY??
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should get a polygon for envelope" do
|
168
|
+
@c2.envelope.should be_instance_of(Polygon)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should get a polygon for envelope" do
|
172
|
+
@c2.envelope.rings[0].points[0].should be_instance_of(Point)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should get the center" do
|
176
|
+
@c2.centroid.x.should be_close(36.2945235015093,0.00001)
|
177
|
+
@c2.centroid.y.should be_close(48.3211154233146,0.00001)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should get the center with the correct srid" do
|
181
|
+
@c1.centroid.srid.should eql(4326)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "distance from another" do
|
185
|
+
@c1.distance_to(@c3).should eql(0.0)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "distance to a linestring" do
|
189
|
+
@c1.distance_to(@s1).should be_close(2.146,0.001)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should simplify me" do
|
193
|
+
@c3.simplify.should be_instance_of(Polygon)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should simplify me number of points" do
|
197
|
+
@c3.simplify[0].length.should eql(4)
|
198
|
+
end
|
199
|
+
|
200
|
+
#Strange again.... s2 s3 ... error
|
201
|
+
it { @c3.touches?(@s1).should be_false }
|
202
|
+
it { @c2.should be_simple }
|
203
|
+
it { @c2.disjoint?(@p2).should be_true }
|
204
|
+
it { @c3.polygonize.should have(2).geometries }
|
205
|
+
|
206
|
+
it "should acts as jack" do
|
207
|
+
@c2.segmentize(0.1).should be_instance_of(Polygon)
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
# weird...
|
212
|
+
# it do
|
213
|
+
# @c1.disjoint?(@p2).should be_true
|
214
|
+
# end
|
215
|
+
|
216
|
+
it "should check overlaps" do
|
217
|
+
@c2.contains?(@c1).should be_false
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should check overlaps non saved" do
|
221
|
+
@c2.contains?(@poly).should be_false
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should find the UTM zone" do
|
225
|
+
@c2.utm_zone.should eql(32737)
|
226
|
+
end
|
227
|
+
|
228
|
+
if PG_VERSION >= "8.4.0"
|
229
|
+
it "should export as GeoJSON" do
|
230
|
+
@c1.as_geo_json.should eql("{\"type\":\"Polygon\",\"coordinates\":[[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]]}")
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "LineString" do
|
237
|
+
|
238
|
+
describe "Length" do
|
239
|
+
it { @s1.length.should be_close(1.4142135623731, 0.000001) }
|
240
|
+
it { @s2.length.should be_close(4.2, 0.1) }
|
241
|
+
it { @s3.length.should be_close(42.4264068, 0.001) }
|
242
|
+
it { @s1.length_spheroid.should be_close(156876.1494,0.0001) }
|
243
|
+
it { @s1.length_3d.should be_close(1.4142135623731,0.0001) }
|
244
|
+
end
|
245
|
+
|
246
|
+
it { @s1.crosses?(@s2).should be_false }
|
247
|
+
it { @s4.crosses?(@s3).should be_true }
|
248
|
+
it { @s1.touches?(@s2).should be_false }
|
249
|
+
it { @s4.touches?(@s3).should be_false }
|
250
|
+
|
251
|
+
if PG_VERSION >= "8.4.0"
|
252
|
+
it "should calculate crossing direction" do
|
253
|
+
@s4.line_crossing_direction(@s3).should eql("1")
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should have 1 geometry" do
|
258
|
+
@s1.should_not respond_to(:geometries)
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should intersect with linestring" do
|
262
|
+
@s4.intersects?(@s3).should be_true
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should not intersect with this linestring" do
|
266
|
+
@s4.intersects?(@s1).should be_false
|
267
|
+
end
|
268
|
+
|
269
|
+
it "intersection with a point" do
|
270
|
+
@s1.intersection(@p2).should be_instance_of(GeometryCollection)
|
271
|
+
end
|
272
|
+
|
273
|
+
it "have a point on surface" do
|
274
|
+
@s3.point_on_surface.should be_a GeoRuby::SimpleFeatures::Point
|
275
|
+
end
|
276
|
+
|
277
|
+
describe "Self" do
|
278
|
+
|
279
|
+
it do
|
280
|
+
@s1.envelope.should be_instance_of(Polygon)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should get a polygon for envelope" do
|
284
|
+
@s1.envelope.rings[0].points[0].should be_instance_of(Point)
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should get the center" do
|
288
|
+
@s1.centroid.x.should be_close(1.5,0.01)
|
289
|
+
@s1.centroid.y.should be_close(1.5,0.01)
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should get the center with the correct srid" do
|
293
|
+
@s1.centroid.srid.should eql(4326)
|
294
|
+
end
|
295
|
+
|
296
|
+
it "number of points" do
|
297
|
+
@s3.num_points.should eql(6)
|
298
|
+
end
|
299
|
+
|
300
|
+
it "startpoint" do
|
301
|
+
@s3.start_point.should be_instance_of(Point)
|
302
|
+
@s3.start_point.x.should be_close(8.0, 0.1)
|
303
|
+
end
|
304
|
+
|
305
|
+
it "endpoint" do
|
306
|
+
@s2.end_point.should be_instance_of(Point)
|
307
|
+
@s2.end_point.x.should be_close(7.0, 0.1)
|
308
|
+
end
|
309
|
+
|
310
|
+
it { @s1.should_not be_envelopes_intersect(@s2) }
|
311
|
+
it { @s1.boundary.should be_instance_of(MultiPoint) }
|
312
|
+
|
313
|
+
|
314
|
+
if PG_VERSION >= "8.4.0"
|
315
|
+
it "should export as GeoJSON" do
|
316
|
+
@s1.as_geo_json.should eql("{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]}")
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe "More Distance" do
|
322
|
+
|
323
|
+
it { @s1.distance_to(@p3).should be_close(8.48528137423857,0.0001) }
|
324
|
+
it { @s1.distance_to(@p3).should be_close(8.48,0.01) }
|
325
|
+
it { @p1.distance_spheroid_to(@c3).should be_close(384735.205204477, 1) }
|
326
|
+
it { @p3.distance_spheroid_to(@s1).should be_close(939450.671670147,1) }
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
it do @s1.locate_point(@p1).should eql(0.0) end
|
331
|
+
it do @s1.locate_point(@p2).should eql(1.0) end
|
332
|
+
|
333
|
+
it "should simplify a line" do
|
334
|
+
@s3.simplify.points.length.should eql(2)
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should simplify the first correcty" do
|
338
|
+
@s3.simplify.points[0].y.should be_close(8.0, 0.1)
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should simplify the last correcty" do
|
342
|
+
@s3.simplify.points[1].y.should be_close(38.0, 0.1)
|
343
|
+
end
|
344
|
+
|
345
|
+
it { @s1.overlaps?(@c2).should be_false }
|
346
|
+
it { @s1.overlaps?(@s2).should be_false }
|
347
|
+
it { @s1.convex_hull.should be_instance_of(LineString) }
|
348
|
+
it { @s1.line_substring(0.2,0.5).should be_instance_of(LineString) }
|
349
|
+
|
350
|
+
it do
|
351
|
+
@s1.interpolate_point(0.7).should be_instance_of(Point)
|
352
|
+
@s1.interpolate_point(0.7).x.should be_close(1.7,0.1)
|
353
|
+
end
|
354
|
+
|
355
|
+
it { @s1.should be_simple }
|
356
|
+
it { @s1.disjoint?(@s2).should be_true }
|
357
|
+
it { @s1.polygonize.should be_instance_of(GeometryCollection) }
|
358
|
+
it { @s3.polygonize.geometries.should be_empty }
|
359
|
+
|
360
|
+
# TODO: Starting with Pgis 1.5 this fail.. need to check
|
361
|
+
it do
|
362
|
+
lambda { @s2.locate_along_measure(1.6) }.should raise_error
|
363
|
+
end
|
364
|
+
|
365
|
+
it do
|
366
|
+
lambda { @s2.locate_between_measures(0.1,0.3).should be_nil }.should raise_error
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should build area" do
|
370
|
+
@s2.build_area.should be_nil
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should acts as jack" do
|
374
|
+
@s2.segmentize(0.1).should be_instance_of(LineString)
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should find the UTM zone" do
|
378
|
+
@s2.utm_zone.should eql(32731)
|
379
|
+
end
|
380
|
+
|
381
|
+
it "should find the UTM zone" do
|
382
|
+
@s2.transform!(29101)
|
383
|
+
@s2.utm_zone.should eql(32732)
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should transform non saved" do
|
387
|
+
ls = LineString.from_coordinates([[11435579.3992231,10669620.8116516],[11721337.4281638,11210714.9524106]],29101)
|
388
|
+
str = Street.new(:geom => ls)
|
389
|
+
str.transform!(4326)
|
390
|
+
str.geom[0].x.should be_close(4,0.0000001)
|
391
|
+
str.geom[0].y.should be_close(4,0.0000001)
|
392
|
+
str.geom[1].x.should be_close(7,0.0000001)
|
393
|
+
str.geom[1].y.should be_close(7,0.0000001)
|
394
|
+
end
|
395
|
+
|
396
|
+
describe "MultiLineString" do
|
397
|
+
|
398
|
+
it "should write nicely" do
|
399
|
+
@m1.geom.should be_instance_of(MultiLineString)
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should have 2 geometries" do
|
403
|
+
@m1.geom.should have(2).geometries
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should have 2 points on the geometry" do
|
407
|
+
@m1.geom.geometries[0].length.should eql(2)
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should calculate multi line string length" do
|
411
|
+
@m1.length_spheroid.should be_close(470464.54, 0.01)
|
412
|
+
end
|
413
|
+
|
414
|
+
it "should line merge!" do
|
415
|
+
merged = @m1.line_merge
|
416
|
+
merged.should be_instance_of(LineString)
|
417
|
+
merged.length.should eql(3)
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should line merge collect" do
|
421
|
+
pending
|
422
|
+
co = @m2.line_merge
|
423
|
+
co.should be_instance_of(LineString)
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe "PostgisFunctions" do
|
4
|
+
before(:all) do
|
5
|
+
@c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,42],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],4326))
|
6
|
+
@s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[-43,-20],[-42,-28]],4326))
|
7
|
+
@p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(-43,-22,4326))
|
8
|
+
@cg ||= CommonGeo.create!(:data => "Point1", :geom => Point.from_x_y(-43,-22,4326))
|
9
|
+
@px = DiffName.create!(:data => "Hey", :the_geom => Point.from_x_y(10,20, 4326))
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Common Mix" do
|
13
|
+
|
14
|
+
it "should calculate distance point to line" do
|
15
|
+
@p1.distance_to(@s1).should be_within(0.00000001).of(0.248069469178417)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should calculate distance point to line" do
|
19
|
+
@cg.distance_to(@s1).should be_within(0.00000001).of(0.248069469178417)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should calculate distance point to line" do
|
23
|
+
@p1.geom.as_kml.should eql("<Point>\n<coordinates>-43,-22</coordinates>\n</Point>\n")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should calculate inside a city" do
|
27
|
+
@p1.should_not be_inside(@c1)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should find the distance from a unsaved point" do
|
31
|
+
@p1.distance_to(Point.from_x_y(5,5,4326)).should be_within(0.00001).of(55.0726792520575)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should work with unsaved objects" do
|
35
|
+
ss = Street.new(:data => "Street1", :geom => LineString.from_coordinates([[-44,-21],[-43,-29]],4326))
|
36
|
+
ss.length_spheroid.should be_within(0.01).of(891908.39)
|
37
|
+
end
|
38
|
+
|
39
|
+
it { @c1.area(32640).should be_within(0.01).of(9165235788987.37) }
|
40
|
+
|
41
|
+
it { @c1.area.should be_within(0.1).of(720.0) }
|
42
|
+
|
43
|
+
it "should be strictly left of city" do
|
44
|
+
@p1.should be_strictly_left_of(@c1)
|
45
|
+
end
|
46
|
+
|
47
|
+
it { @s1.length.should be_within(0.0001).of(8.06225774829855) }
|
48
|
+
|
49
|
+
it { @s1.length_spheroid.should be_within(0.0001).of(891883.597963462) }
|
50
|
+
|
51
|
+
it "should work with a diff column name" do
|
52
|
+
px2 = DiffName.create!(:data => "Hey 2", :the_geom => Point.from_x_y(20,20, 4326))
|
53
|
+
@px.distance_to(px2).should be_within(0.01).of(10.0)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should work with mixed column names" do
|
57
|
+
@px.distance_to(@s1).should be_within(0.1).of(66.4)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|