ppe-postgis-adapter 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/History.txt +6 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +347 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/postgis_adapter/acts_as_geom.rb +39 -0
- data/lib/postgis_adapter/common_spatial_adapter.rb +184 -0
- data/lib/postgis_adapter.rb +423 -0
- data/lib/postgis_functions/bbox.rb +128 -0
- data/lib/postgis_functions/class.rb +63 -0
- data/lib/postgis_functions/common.rb +886 -0
- data/lib/postgis_functions.rb +169 -0
- data/postgis_adapter.gemspec +75 -0
- data/rails/init.rb +9 -0
- data/spec/db/models_postgis.rb +61 -0
- data/spec/db/schema_postgis.rb +92 -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_spec.rb +224 -0
- data/spec/postgis_functions/bbox_spec.rb +45 -0
- data/spec/postgis_functions/class_spec.rb +65 -0
- data/spec/postgis_functions/common_spec.rb +374 -0
- data/spec/postgis_functions_spec.rb +53 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +26 -0
- metadata +90 -0
@@ -0,0 +1,374 @@
|
|
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
|
+
@s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],4326))
|
12
|
+
@s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],4326))
|
13
|
+
@s4 ||= Street.create!(:data => "Street4", :geom => LineString.from_coordinates([[10,8],[15,18]],4326))
|
14
|
+
@p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,4326))
|
15
|
+
@p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,4326))
|
16
|
+
@p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,4326))
|
17
|
+
@p4 ||= Position.create!(:data => "Point4", :geom => Point.from_x_y(18.1,18,4326))
|
18
|
+
@p5 ||= Position.create!(:data => "Point5", :geom => Point.from_x_y(30,30,4326))
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Point" do
|
22
|
+
|
23
|
+
it "should find the closest other point" do
|
24
|
+
Position.close_to(@p1.geom)[0].data.should == @p1.data
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should find the closest other point" do
|
28
|
+
Position.closest_to(@p1.geom).data.should == @p1.data
|
29
|
+
end
|
30
|
+
|
31
|
+
it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.0001) }
|
32
|
+
it { @p1.distance_to(@s3).should be_close(9.89949493661167, 0.0001) }
|
33
|
+
it { @p2.distance_to(@s3).should be_close(4.24264068711928, 0.0001) }
|
34
|
+
it { @p1.distance_to(@p2).should be_close(5.65685424949238, 0.0001) }
|
35
|
+
it { @p1.distance_to(@c1).should be_close(3.0, 0.0001) }
|
36
|
+
it { @p1.distance_to(@c2).should be_close(21.0237960416286, 0.000001) }
|
37
|
+
it { @p1.distance_to(@s2).should be_close(4.24264068711928, 0.000001) }
|
38
|
+
it { @p1.distance_sphere_to(@p2).should be_close(628516.874554178, 0.0001) }
|
39
|
+
it { @p1.distance_sphere_to(@p3).should be_close(1098726.61466584, 0.00001) }
|
40
|
+
it { @p1.distance_spheroid_to(@p2).should be_close(627129.50,0.01) }
|
41
|
+
it { @p1.distance_spheroid_to(@p2).should be_close(627129.502639041, 0.000001) }
|
42
|
+
it { @p1.distance_spheroid_to(@p3).should be_close(1096324.48117672, 0.000001) }
|
43
|
+
|
44
|
+
it "should find the distance from a unsaved point" do
|
45
|
+
@p1.distance_to(@p2).should be_close(5.65685424949238,0.001)
|
46
|
+
@p1.distance_to(Point.from_x_y(5,5,4326)).should be_close(5.65685424949238,0.001)
|
47
|
+
end
|
48
|
+
|
49
|
+
it { @p1.should_not be_inside(@c1) }
|
50
|
+
it { @p1.should be_outside(@c1) }
|
51
|
+
it { @p1.should be_inside_circle(2.0,2.0,20.0) }
|
52
|
+
it { @p1.should_not be_inside_circle(50,50,2) }
|
53
|
+
it { @p1.should be_in_bounds(@s1) }
|
54
|
+
it { @p3.should_not be_in_bounds(@s1, 1) }
|
55
|
+
it { @p4.in_bounds?(@s3, 0.01).should be_false }
|
56
|
+
|
57
|
+
it { @p1.azimuth(@p2).should be_close(0.785398163397448,0.000001) }
|
58
|
+
it { @p1.azimuth(@s2).should raise_error }
|
59
|
+
it { @p1.disjoint?(@s2).should be_true }
|
60
|
+
it { @p3.polygonize.geometries.should be_empty }
|
61
|
+
it { @p4.where_on_line(@s3).should be_close(0.335, 0.0001) }
|
62
|
+
it { @s3.locate_point(@p4).should be_close(0.335, 0.1)}
|
63
|
+
it { @s3.interpolate_point(0.335).x.should be_close(18.05, 0.01) }
|
64
|
+
|
65
|
+
it { @p1.relate?(@s3, "T*T***FF*").should be_false }
|
66
|
+
it { @p1.relate?(@s3).should eql("FF0FFF102") }
|
67
|
+
|
68
|
+
it "should transform srid" do
|
69
|
+
@p1.geom = @p1.transform(29101)
|
70
|
+
@p1.geom.srid.should eql(29101)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should transform non saved srid geoms" do
|
74
|
+
pt = Point.from_x_y(11121381.4586196,10161852.0494475, 29101)
|
75
|
+
pos = Position.new(:geom => pt)
|
76
|
+
pos.transform(4326)
|
77
|
+
pos.geom.x.should be_close(1.00000000000005, 0.00001)
|
78
|
+
pos.geom.y.should be_close(1.00000000000005, 0.00001)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should see in what fraction of the ls it is" do
|
82
|
+
@p1.where_on_line(@s1).should eql(0.0)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should see in what fraction of the ls it is" do
|
86
|
+
@p2.where_on_line(@s2).should be_close(0.3333, 0.1)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have a srid getter" do
|
90
|
+
@p1.srid.should eql(29101)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should calculate the UTM srid" do
|
94
|
+
@p2.utm_zone.should eql(32731)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should convert to utm zone" do
|
98
|
+
lambda { @p2.to_utm! }.should change(@p2, :srid)
|
99
|
+
end
|
100
|
+
|
101
|
+
if PG_VERSION >= "8.4.0"
|
102
|
+
it "should export as GeoJSON" do
|
103
|
+
@p1.as_geo_json.should eql("{\"type\":\"Point\",\"coordinates\":[1,1]}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
# it { @p3.x.should be_close(8.0, 0.1) }
|
109
|
+
# it { @p3.y.should be_close(8.0, 0.1) }
|
110
|
+
# it { @p3.z.should be_close(0.0, 0.1) }
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "Polygon" do
|
115
|
+
|
116
|
+
it "sort by area size" do
|
117
|
+
City.by_area.first.data.should == "City1" #[@c1, @c2, @c3]
|
118
|
+
end
|
119
|
+
|
120
|
+
it "find all cities that contains a point" do
|
121
|
+
City.contains(@p1.geom, 4326).should eql([])
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should find one city (first) that contains a point" do
|
125
|
+
City.contain(@p4.geom, 4326).data.should eql("City1")
|
126
|
+
end
|
127
|
+
|
128
|
+
it { @c2.should be_closed }
|
129
|
+
it { @c2.dimension.should eql(2) }
|
130
|
+
|
131
|
+
it { @c3.area.should be_close(1093.270089, 0.1) }
|
132
|
+
it { @c2.area.should be_close(1159.5, 0.1) }
|
133
|
+
it { @c2.area(32640).should be_close(5852791139841.2, 0.01) }
|
134
|
+
|
135
|
+
it { @c2.perimeter.should be_close(219.770013855493, 0.1) }
|
136
|
+
it { @c2.perimeter(32640).should be_close(23061464.4268903, 0.1) }
|
137
|
+
it { @c2.perimeter3d.should be_close(219.770013855493, 0.1) }
|
138
|
+
|
139
|
+
it { @c1.contains?(@p1).should be_false }
|
140
|
+
it { @c1.contains?(@p4).should be_true }
|
141
|
+
|
142
|
+
it { @c1.should_not be_spatially_equal(@c2) }
|
143
|
+
|
144
|
+
it { @c1.covers?(@p1).should be_false }
|
145
|
+
it { @c1.covers?(@p4).should be_true }
|
146
|
+
it { @c1.should_not be_within(@c2) }
|
147
|
+
|
148
|
+
it "city overlaps point?" do
|
149
|
+
lambda { @c3.overlaps?(@c2) }.should raise_error # WHY??
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should get a polygon for envelope" do
|
153
|
+
@c2.envelope.should be_instance_of(Polygon)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should get a polygon for envelope" do
|
157
|
+
@c2.envelope.rings[0].points[0].should be_instance_of(Point)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should get the center" do
|
161
|
+
@c2.centroid.x.should be_close(36.2945235015093,0.00001)
|
162
|
+
@c2.centroid.y.should be_close(48.3211154233146,0.00001)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should get the center with the correct srid" do
|
166
|
+
@c1.centroid.srid.should eql(4326)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "distance from another" do
|
170
|
+
@c1.distance_to(@c3).should eql(0.0)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "distance to a linestring" do
|
174
|
+
@c1.distance_to(@s1).should be_close(1.8,0.001)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should simplify me" do
|
178
|
+
@c3.simplify.should be_instance_of(Polygon)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should simplify me number of points" do
|
182
|
+
@c3.simplify[0].length.should eql(4)
|
183
|
+
end
|
184
|
+
|
185
|
+
#Strange again.... s2 s3 ... error
|
186
|
+
it { @c3.touches?(@s1).should be_false }
|
187
|
+
it { @c2.should be_simple }
|
188
|
+
it { @c2.disjoint?(@p2).should be_true }
|
189
|
+
it { @c3.polygonize.should have(2).geometries }
|
190
|
+
|
191
|
+
it "should acts as jack" do
|
192
|
+
@c2.segmentize(0.1).should be_instance_of(Polygon)
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
# weird...
|
197
|
+
# it do
|
198
|
+
# @c1.disjoint?(@p2).should be_true
|
199
|
+
# end
|
200
|
+
|
201
|
+
it "should check overlaps" do
|
202
|
+
@c2.contains?(@c1).should be_false
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should check overlaps non saved" do
|
206
|
+
@c2.contains?(@poly).should be_false
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should find the UTM zone" do
|
210
|
+
@c2.utm_zone.should eql(32737)
|
211
|
+
end
|
212
|
+
|
213
|
+
if PG_VERSION >= "8.4.0"
|
214
|
+
it "should export as GeoJSON" do
|
215
|
+
@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]]]}")
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "LineString" do
|
222
|
+
|
223
|
+
describe "Length" do
|
224
|
+
it { @s1.length.should be_close(1.4142135623731, 0.000001) }
|
225
|
+
it { @s2.length.should be_close(4.2, 0.1) }
|
226
|
+
it { @s3.length.should be_close(42.4264068, 0.001) }
|
227
|
+
it { @s1.length_spheroid.should be_close(156876.1494,0.0001) }
|
228
|
+
it { @s1.length_3d.should be_close(1.4142135623731,0.0001) }
|
229
|
+
end
|
230
|
+
|
231
|
+
it { @s1.crosses?(@s2).should be_false }
|
232
|
+
it { @s4.crosses?(@s3).should be_true }
|
233
|
+
it { @s1.touches?(@s2).should be_false }
|
234
|
+
it { @s4.touches?(@s3).should be_false }
|
235
|
+
|
236
|
+
if PG_VERSION >= "8.4.0"
|
237
|
+
it "should calculate crossing direction" do
|
238
|
+
@s4.line_crossing_direction(@s3).should eql("1")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should intersect with linestring" do
|
243
|
+
@s4.intersects?(@s3).should be_true
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should not intersect with this linestring" do
|
247
|
+
@s4.intersects?(@s1).should be_false
|
248
|
+
end
|
249
|
+
|
250
|
+
it "intersection with a point" do
|
251
|
+
@s1.intersection(@p2).should be_instance_of(GeometryCollection)
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "Self" do
|
255
|
+
|
256
|
+
it do
|
257
|
+
@s1.envelope.should be_instance_of(Polygon)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should get a polygon for envelope" do
|
261
|
+
@s1.envelope.rings[0].points[0].should be_instance_of(Point)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should get the center" do
|
265
|
+
@s1.centroid.x.should be_close(1.5,0.01)
|
266
|
+
@s1.centroid.y.should be_close(1.5,0.01)
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should get the center with the correct srid" do
|
270
|
+
@s1.centroid.srid.should eql(4326)
|
271
|
+
end
|
272
|
+
|
273
|
+
it "number of points" do
|
274
|
+
@s3.num_points.should eql(6)
|
275
|
+
end
|
276
|
+
|
277
|
+
it "startpoint" do
|
278
|
+
@s3.start_point.should be_instance_of(Point)
|
279
|
+
@s3.start_point.x.should be_close(8.0, 0.1)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "endpoint" do
|
283
|
+
@s2.end_point.should be_instance_of(Point)
|
284
|
+
@s2.end_point.x.should be_close(7.0, 0.1)
|
285
|
+
end
|
286
|
+
|
287
|
+
it { @s1.should_not be_envelopes_intersect(@s2) }
|
288
|
+
it { @s1.boundary.should be_instance_of(MultiPoint) }
|
289
|
+
|
290
|
+
|
291
|
+
if PG_VERSION >= "8.4.0"
|
292
|
+
it "should export as GeoJSON" do
|
293
|
+
@s1.as_geo_json.should eql("{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]}")
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
describe "Distance" do
|
300
|
+
|
301
|
+
it { @s1.distance_to(@p3).should be_close(8.48528137423857,0.0001) }
|
302
|
+
it { @s1.distance_to(@p3).should be_close(8.48,0.01) }
|
303
|
+
|
304
|
+
it do
|
305
|
+
lambda { @p1.distance_spheroid_to(@c3) }.should raise_error
|
306
|
+
end
|
307
|
+
|
308
|
+
it do
|
309
|
+
lambda { @p3.distance_spheroid_to(@s1) }.should raise_error
|
310
|
+
end
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
it do @s1.locate_point(@p1).should eql(0.0) end
|
315
|
+
it do @s1.locate_point(@p2).should eql(1.0) end
|
316
|
+
|
317
|
+
it "should simplify a line" do
|
318
|
+
@s3.simplify.points.length.should eql(2)
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should simplify the first correcty" do
|
322
|
+
@s3.simplify.points[0].y.should be_close(8.0, 0.1)
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should simplify the last correcty" do
|
326
|
+
@s3.simplify.points[1].y.should be_close(38.0, 0.1)
|
327
|
+
end
|
328
|
+
|
329
|
+
it { @s1.overlaps?(@c2).should be_false }
|
330
|
+
it { @s1.overlaps?(@s2).should be_false }
|
331
|
+
it { @s1.convex_hull.should be_instance_of(LineString) }
|
332
|
+
it { @s1.line_substring(0.2,0.5).should be_instance_of(LineString) }
|
333
|
+
|
334
|
+
it do
|
335
|
+
@s1.interpolate_point(0.7).should be_instance_of(Point)
|
336
|
+
@s1.interpolate_point(0.7).x.should be_close(1.7,0.1)
|
337
|
+
end
|
338
|
+
|
339
|
+
it { @s1.should be_simple }
|
340
|
+
it { @s1.disjoint?(@s2).should be_true }
|
341
|
+
it { @s1.polygonize.should be_instance_of(GeometryCollection) }
|
342
|
+
it { @s3.polygonize.geometries.should be_empty }
|
343
|
+
it { @s2.locate_along_measure(1.6).should be_nil }
|
344
|
+
it { @s2.locate_between_measures(0.1,0.3).should be_nil }
|
345
|
+
|
346
|
+
it "should build area" do
|
347
|
+
@s2.build_area.should be_nil
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should acts as jack" do
|
351
|
+
@s2.segmentize(0.1).should be_instance_of(LineString)
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should find the UTM zone" do
|
355
|
+
@s2.utm_zone.should eql(32731)
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should find the UTM zone" do
|
359
|
+
@s2.transform!(29101)
|
360
|
+
@s2.utm_zone.should eql(32732)
|
361
|
+
end
|
362
|
+
|
363
|
+
it "should transform non saved" do
|
364
|
+
ls = LineString.from_coordinates([[11435579.3992231,10669620.8116516],[11721337.4281638,11210714.9524106]],29101)
|
365
|
+
str = Street.new(:geom => ls)
|
366
|
+
str.transform(4326)
|
367
|
+
str.geom[0].x.should be_close(4,0.0000001)
|
368
|
+
str.geom[0].y.should be_close(4,0.0000001)
|
369
|
+
str.geom[1].x.should be_close(7,0.0000001)
|
370
|
+
str.geom[1].y.should be_close(7,0.0000001)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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_close(0.248069469178417, 0.00000001)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should calculate distance point to line" do
|
19
|
+
@cg.distance_to(@s1).should be_close(0.248069469178417, 0.00000001)
|
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_close(55.0726792520575, 0.001)
|
32
|
+
end
|
33
|
+
|
34
|
+
it { @c1.area(32640).should be_close(9165235788987.37, 0.01) }
|
35
|
+
|
36
|
+
it { @c1.area.should be_close(720.0, 0.1) }
|
37
|
+
|
38
|
+
it { @p1.should be_strictly_left_of(@c1) }
|
39
|
+
|
40
|
+
it { @s1.length.should be_close(8.06225774829855, 0.001) }
|
41
|
+
|
42
|
+
it { @s1.length_spheroid.should be_close(891883.597963462,0.0001) }
|
43
|
+
|
44
|
+
it "should work with a diff column name" do
|
45
|
+
px2 = DiffName.create!(:data => "Hey 2", :the_geom => Point.from_x_y(20,20, 4326))
|
46
|
+
@px.distance_to(px2).should be_close(10.0, 0.1)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should work with mixed column names" do
|
50
|
+
@px.distance_to(@s1).should be_close(66.4,1)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'pg'
|
4
|
+
require 'activerecord'
|
5
|
+
$:.unshift((File.join(File.dirname(__FILE__), '..', 'lib')))
|
6
|
+
gem 'activerecord', "=2.3.4"
|
7
|
+
gem 'nofxx-georuby'
|
8
|
+
require 'postgis_adapter'
|
9
|
+
|
10
|
+
# Monkey patch Schema.define logger
|
11
|
+
$logger = Logger.new(StringIO.new)
|
12
|
+
def $logger.write(d); self.info(d); end
|
13
|
+
# $stdout = $logger
|
14
|
+
|
15
|
+
GeoRuby::SimpleFeatures.srid = -1
|
16
|
+
|
17
|
+
ActiveRecord::Base.logger = $logger
|
18
|
+
ActiveRecord::Base.establish_connection({ :adapter => "postgresql", :database => "postgis_adapter",
|
19
|
+
:username => "postgres", :password => "" })
|
20
|
+
|
21
|
+
PG_VERSION = ActiveRecord::Base.connection.select_value("SELECT version()").scan(/PostgreSQL ([\d\.]*)/)[0][0]
|
22
|
+
|
23
|
+
puts "Running against PostgreSQL #{PG_VERSION}"
|
24
|
+
|
25
|
+
require File.dirname(__FILE__) + '/db/schema_postgis.rb'
|
26
|
+
require File.dirname(__FILE__) + '/db/models_postgis.rb'
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ppe-postgis-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcos Piccinini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-18 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Execute PostGIS functions on Active Record
|
17
|
+
email: x@nofxx.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- History.txt
|
27
|
+
- MIT-LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- init.rb
|
32
|
+
- lib/postgis_adapter.rb
|
33
|
+
- lib/postgis_adapter/acts_as_geom.rb
|
34
|
+
- lib/postgis_adapter/common_spatial_adapter.rb
|
35
|
+
- lib/postgis_functions.rb
|
36
|
+
- lib/postgis_functions/bbox.rb
|
37
|
+
- lib/postgis_functions/class.rb
|
38
|
+
- lib/postgis_functions/common.rb
|
39
|
+
- postgis_adapter.gemspec
|
40
|
+
- rails/init.rb
|
41
|
+
- spec/db/models_postgis.rb
|
42
|
+
- spec/db/schema_postgis.rb
|
43
|
+
- spec/postgis_adapter/acts_as_geom_spec.rb
|
44
|
+
- spec/postgis_adapter/common_spatial_adapter_spec.rb
|
45
|
+
- spec/postgis_adapter_spec.rb
|
46
|
+
- spec/postgis_functions/bbox_spec.rb
|
47
|
+
- spec/postgis_functions/class_spec.rb
|
48
|
+
- spec/postgis_functions/common_spec.rb
|
49
|
+
- spec/postgis_functions_spec.rb
|
50
|
+
- spec/spec.opts
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/nofxx/postgis_adapter
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project: postgis_adapter
|
76
|
+
rubygems_version: 1.3.5
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: PostGIS Adapter for Active Record
|
80
|
+
test_files:
|
81
|
+
- spec/db/models_postgis.rb
|
82
|
+
- spec/db/schema_postgis.rb
|
83
|
+
- spec/postgis_adapter/acts_as_geom_spec.rb
|
84
|
+
- spec/postgis_adapter/common_spatial_adapter_spec.rb
|
85
|
+
- spec/postgis_functions_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/postgis_adapter_spec.rb
|
88
|
+
- spec/postgis_functions/class_spec.rb
|
89
|
+
- spec/postgis_functions/common_spec.rb
|
90
|
+
- spec/postgis_functions/bbox_spec.rb
|