postgis_adapter 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+
4
+ describe "Point" do
5
+
6
+ before(:all) do
7
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],123))
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]]],123))
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]]],123))
10
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],123))
11
+ @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],123))
12
+ @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],123))
13
+ @s4 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[10,8],[15,18]],123))
14
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,123))
15
+ @p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,123))
16
+ @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,123))
17
+ end
18
+
19
+
20
+ describe "BBox operations" do
21
+
22
+ it "should check stricly left" do
23
+ @p1.bbox("<<", @c1).should be_true
24
+ end
25
+
26
+ it "should check stricly right" do
27
+ @p1.bbox(">>", @c1).should be_false
28
+ end
29
+
30
+ it do
31
+ @p1.should be_strictly_left_of(@c1)
32
+ end
33
+
34
+ it do
35
+ @p1.should_not be_strictly_right_of(@c1)
36
+ end
37
+
38
+ it do
39
+ @p1.should_not be_overlaps_or_right_of(@c1)
40
+ end
41
+
42
+ it do
43
+ @p1.should be_overlaps_or_left_of(@c1)
44
+ end
45
+
46
+ it do
47
+ @p1.should_not be_completely_contained_by(@c1)
48
+ end
49
+
50
+ it do
51
+ @c2.completely_contains?(@p1).should be_false
52
+ end
53
+
54
+ it do
55
+ @p1.should be_overlaps_or_above(@c1)
56
+ end
57
+
58
+ it do
59
+ @p1.should be_overlaps_or_below(@c1)
60
+ end
61
+
62
+ it do
63
+ @p1.should_not be_strictly_above(@c1)
64
+ end
65
+
66
+ it do
67
+ @p1.should_not be_strictly_below(@c1)
68
+ end
69
+
70
+ it do
71
+ @p1.interacts_with?(@c1).should be_false
72
+ end
73
+
74
+ it do
75
+ @p1.binary_equal?(@c1).should be_false
76
+ end
77
+
78
+ it do
79
+ @p1.same_as?(@c1).should be_false
80
+ end
81
+
82
+
83
+ end
84
+ end
@@ -0,0 +1,219 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe "LineString" do
4
+
5
+ before(:all) do
6
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],123))
7
+ @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]]],123))
8
+ @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]]],123))
9
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],123))
10
+ @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],123))
11
+ @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],123))
12
+ @s4 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[10,8],[15,18]],123))
13
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,123))
14
+ @p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,123))
15
+ @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,123))
16
+ end
17
+
18
+ it "should sort by size" do
19
+ Street.by_length.first.data.should == "Street1"
20
+ Street.by_length.last.data.should == "Street3"
21
+ end
22
+
23
+ it "largest" do
24
+ Street.longest.data.should == "Street3"
25
+ end
26
+
27
+ describe "Length" do
28
+
29
+ it do
30
+ @s1.length.should be_close(1.4142135623731, 0.000001)
31
+ end
32
+
33
+ it do
34
+ @s2.length.should be_close(4.2, 0.1)
35
+ end
36
+
37
+ it do
38
+ @s3.length.should be_close(42.4264068, 0.001)
39
+ end
40
+
41
+ it "3d length" do
42
+ @s1.length_3d.should be_close(1.4142135623731,0.0001)
43
+ end
44
+
45
+ it do
46
+ @s1.length_spheroid.should be_close(156876.1381,0.0001)
47
+ end
48
+
49
+ # it do
50
+ # @s1.length_spheroid.in_miles.should be_close(156.876,0.001)
51
+ # end
52
+ end
53
+
54
+ it "should not cross s2" do
55
+ @s1.crosses?(@s2).should be_false
56
+ end
57
+
58
+ it "should cross s3" do
59
+ @s4.crosses?(@s3).should be_true
60
+ end
61
+
62
+ it do
63
+ @s1.touches?(@s2).should be_false
64
+ end
65
+
66
+ it do
67
+ @s4.touches?(@s3).should be_false
68
+ end
69
+
70
+ it "should intersect with linestring" do
71
+ @s4.intersects?(@s3).should be_true
72
+ end
73
+
74
+ it "should not intersect with this linestring" do
75
+ @s4.intersects?(@s1).should be_false
76
+ end
77
+
78
+
79
+ it "intersection with a point" do
80
+ @s1.intersection(@p2).should be_instance_of(GeometryCollection)
81
+ end
82
+
83
+
84
+ describe "Self" do
85
+
86
+ it do
87
+ @s1.envelope.should be_instance_of(Polygon)
88
+ end
89
+
90
+ it "should get a polygon for envelope" do
91
+ @s1.envelope.rings[0].points[0].should be_instance_of(Point)
92
+ end
93
+
94
+ it "should get the center" do
95
+ @s1.centroid.x.should be_close(1.5,0.01)
96
+ @s1.centroid.y.should be_close(1.5,0.01)
97
+ end
98
+
99
+ it "should get the center with the correct srid" do
100
+ @s1.centroid.srid.should eql(123)
101
+ end
102
+
103
+ it "number of points" do
104
+ @s3.num_points.should eql(6)
105
+ end
106
+
107
+ it "startpoint" do
108
+ @s3.start_point.should be_instance_of(Point)
109
+ @s3.start_point.x.should be_close(8.0, 0.1)
110
+ end
111
+
112
+ it "endpoint" do
113
+ @s2.end_point.should be_instance_of(Point)
114
+ @s2.end_point.x.should be_close(7.0, 0.1)
115
+ end
116
+
117
+ it do
118
+ @s1.should_not be_envelopes_intersect(@s2)
119
+ end
120
+
121
+
122
+ it do
123
+ @s1.boundary.should be_instance_of(MultiPoint)
124
+ end
125
+
126
+ end
127
+
128
+ describe "Distance" do
129
+
130
+ it do
131
+ @s1.distance_to(@p3).should be_close(8.48528137423857,0.0001)
132
+ end
133
+
134
+ it do
135
+ lambda { @p1.distance_spheroid_to(@c3) }.should raise_error
136
+ end
137
+
138
+ it do
139
+ lambda { @p3.distance_spheroid_to(@s1) }.should raise_error
140
+ end
141
+
142
+ it do
143
+ @s1.distance_to(@p3).should be_close(8.48,0.01)
144
+ end
145
+
146
+
147
+
148
+ end
149
+
150
+ it "should locate a point" do
151
+ @s1.locate_point(@p1).should eql(0.0)
152
+ end
153
+
154
+ it "should locate a point" do
155
+ @s1.locate_point(@p2).should eql(1.0)
156
+ end
157
+
158
+ it "should simplify a line" do
159
+ @s3.simplify.points.length.should eql(2)
160
+ end
161
+
162
+ it "should simplify the first correcty" do
163
+ @s3.simplify.points[0].y.should be_close(8.0, 0.1)
164
+ end
165
+
166
+ it "should simplify the last correcty" do
167
+ @s3.simplify.points[1].y.should be_close(38.0, 0.1)
168
+ end
169
+
170
+ it do
171
+ @s1.overlaps?(@c2).should be_false
172
+ end
173
+
174
+ it do
175
+ @s1.overlaps?(@s2).should be_false
176
+ end
177
+
178
+ it do
179
+ @s1.convex_hull.should be_instance_of(LineString)
180
+ end
181
+
182
+ it do
183
+ @s1.line_substring(0.2,0.5).should be_instance_of(LineString)
184
+ end
185
+
186
+ it do
187
+ @s1.interpolate_point(0.7).should be_instance_of(Point)
188
+ @s1.interpolate_point(0.7).x.should be_close(1.7,0.1)
189
+ end
190
+
191
+ it do
192
+ @s1.should be_simple #?.should be_true
193
+ end
194
+
195
+ it do
196
+ @s1.disjoint?(@s2).should be_true
197
+ end
198
+
199
+ it do
200
+ @s1.polygonize.should be_instance_of(GeometryCollection)
201
+ end
202
+
203
+ it do
204
+ @s3.polygonize.geometries.should be_empty
205
+ end
206
+
207
+ it do
208
+ @s2.locate_along_measure(1.6).should be_nil
209
+ end
210
+
211
+ it do
212
+ @s2.locate_between_measures(0.1,0.3).should be_nil
213
+ end
214
+
215
+ it "should build area" do
216
+ @s2.build_area.should be_nil
217
+ end
218
+
219
+ end
@@ -0,0 +1,136 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+
4
+ describe "Point" do
5
+
6
+ before(:all) do
7
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],123))
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]]],123))
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]]],123))
10
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],123))
11
+ @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],123))
12
+ @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],123))
13
+ @s4 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[10,8],[15,18]],123))
14
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,123))
15
+ @p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,123))
16
+ @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,123))
17
+ @p4 ||= Position.create!(:data => "Point5", :geom => Point.from_x_y(18.1,18,123))
18
+ end
19
+
20
+
21
+
22
+ it "should find the closest other point" do
23
+ Position.close_to(@p1.geom,123)[0].data.should == @p1.data
24
+ end
25
+
26
+ it "should find the closest other point" do
27
+ Position.closest_to(@p1.geom,123).data.should == @p1.data
28
+ end
29
+
30
+ it do
31
+ @p1.distance_to(@s2).should be_close(4.24264068711928, 0.0001)
32
+ end
33
+
34
+ it do
35
+ @p1.distance_to(@s3).should be_close(9.89949493661167, 0.0001)
36
+ end
37
+
38
+ it do
39
+ @p2.distance_to(@s3).should be_close(4.24264068711928, 0.0001)
40
+ end
41
+
42
+ it do
43
+ @p1.distance_to(@p2).should be_close(5.65685424949238, 0.0001)
44
+ end
45
+
46
+ it do
47
+ @p1.distance_sphere_to(@p2).should be_close(628516.874554178, 0.0001)
48
+ end
49
+
50
+ it do
51
+ @p1.distance_sphere_to(@p3).should be_close(1098726.61466584, 0.00001)
52
+ end
53
+
54
+ it do
55
+ @p1.distance_to(@c1).should be_close(3.0, 0.0001)
56
+ end
57
+
58
+ it do
59
+ @p1.distance_to(@c2).should be_close(21.0237960416286, 0.000001)
60
+ end
61
+
62
+ it do
63
+ @p1.distance_to(@s2).should be_close(4.24264068711928, 0.000001)
64
+ end
65
+
66
+ it do
67
+ @p1.distance_spheroid_to(@p2).should be_close(627129.45,0.01)
68
+ end
69
+
70
+ it do
71
+ @p1.distance_spheroid_to(@p2).should be_close(627129.457699803, 0.000001)
72
+ end
73
+
74
+ it do
75
+ @p1.distance_spheroid_to(@p3).should be_close(1096324.40267746, 0.000001)
76
+ end
77
+
78
+ it do
79
+ @p1.should_not be_inside(@c1)
80
+ end
81
+
82
+ it do
83
+ @p1.should be_outside(@c1)
84
+ end
85
+
86
+
87
+ it do
88
+ @p1.azimuth(@p2).should be_close(0.785398163397448,0.000001)
89
+ end
90
+
91
+ it do
92
+ @p1.azimuth(@s2).should raise_error
93
+ end
94
+
95
+ it "should see in what fraction of the ls it is" do
96
+ @p1.where_on_line(@s1).should eql(0.0)
97
+ end
98
+
99
+ it do
100
+ @p1.should be_inside_circle(2.0,2.0,20.0)
101
+ end
102
+
103
+ it do
104
+ @p1.should_not be_inside_circle(50,50,2)
105
+ end
106
+
107
+ it do
108
+ @p1.disjoint?(@s2).should be_true
109
+ end
110
+
111
+ it do
112
+ @p3.polygonize.geometries.should be_empty
113
+ end
114
+
115
+ it do
116
+ @p1.should be_in_bounds(@s1)
117
+ end
118
+
119
+ it "in bounds of a geometry? with option" do
120
+ @p3.should_not be_in_bounds(@s1, 1)
121
+ end
122
+
123
+ it { @p4.in_bounds?(@s3, 0.01).should be_false }
124
+
125
+ it { @p4.where_on_line(@s3).should be_close(0.335, 0.0001) }
126
+
127
+ it { @s3.locate_point(@p4).should be_close(0.335, 0.1)}
128
+
129
+ it { @s3.interpolate_point(0.335).x.should be_close(18.05, 0.01) }
130
+
131
+ it { @p1.relate?(@s3, "T*T***FF*").should be_false }
132
+
133
+ it { @p1.relate?(@s3).should eql("FF0FFF102") }
134
+
135
+ end
136
+
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+
4
+ describe "Point" do
5
+
6
+ before(:all) do
7
+ @c1 ||= City.create!(:data => "City1", :geom => Polygon.from_coordinates([[[12,45],[45,41],[4,1],[12,45]],[[2,5],[5,1],[14,1],[2,5]]],123))
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]]],123))
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]]],123))
10
+ @s1 ||= Street.create!(:data => "Street1", :geom => LineString.from_coordinates([[1,1],[2,2]],123))
11
+ @s2 ||= Street.create!(:data => "Street2", :geom => LineString.from_coordinates([[4,4],[7,7]],123))
12
+ @s3 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[8,8],[18,18],[20,20],[25,25],[30,30],[38,38]],123))
13
+ @s4 ||= Street.create!(:data => "Street3", :geom => LineString.from_coordinates([[10,8],[15,18]],123))
14
+ @p1 ||= Position.create!(:data => "Point1", :geom => Point.from_x_y(1,1,123))
15
+ @p2 ||= Position.create!(:data => "Point2", :geom => Point.from_x_y(5,5,123))
16
+ @p3 ||= Position.create!(:data => "Point3", :geom => Point.from_x_y(8,8,123))
17
+ @p4 ||= Position.create!(:data => "Point4", :geom => Point.from_x_y(30,30,123))
18
+
19
+ end
20
+
21
+
22
+
23
+
24
+ describe "Polygon" do
25
+
26
+ it "sort by area size" do
27
+ City.by_area.first.data.should == "City1" #[@c1, @c2, @c3]
28
+ end
29
+
30
+ it do
31
+ @c2.should be_closed
32
+ end
33
+
34
+ it do
35
+ @c3.area.should be_close(1093.270089, 0.1)
36
+ end
37
+
38
+ it do
39
+ @c2.area.should be_close(1159.5, 0.1)
40
+ end
41
+
42
+ it "dimension x" do
43
+ @c2.dimension.should eql(2)
44
+ end
45
+
46
+ it "perimter 2d" do
47
+ @c2.perimeter.should be_close(219.770013855493, 0.1)
48
+ end
49
+
50
+ it "perimter 3d" do
51
+ @c2.perimeter3d.should be_close(219.770013855493, 0.1)
52
+ end
53
+
54
+ it "contains points?" do
55
+ @c1.contains?(@p1).should be_false
56
+ end
57
+
58
+ it "contains created point?" do
59
+ @c1.contains?(@p4).should be_true
60
+ end
61
+
62
+ it do
63
+ @c1.should_not be_spatially_equal(@c2)
64
+ end
65
+
66
+ it "find all cities that contains a point" do
67
+ City.contains(@p1.geom, 123).should eql([])
68
+ end
69
+
70
+ it "should find one city (first) that contains a point" do
71
+ City.contain(@p4.geom, 123).data.should eql("City1")
72
+ end
73
+
74
+ it do
75
+ @c1.covers?(@p1).should be_false
76
+ end
77
+
78
+ it do
79
+ @c1.covers?(@p4).should be_true
80
+ end
81
+
82
+ it do
83
+ @c1.should_not be_within(@c2)
84
+ end
85
+
86
+ it "city overlaps point?" do
87
+ lambda { @c3.overlaps?(@c2) }.should raise_error # WHY??
88
+ end
89
+
90
+ it "should get a polygon for envelope" do
91
+ @c2.envelope.should be_instance_of(Polygon)
92
+ end
93
+
94
+ it "should get a polygon for envelope" do
95
+ @c2.envelope.rings[0].points[0].should be_instance_of(Point)
96
+ end
97
+
98
+ it "should get the center" do
99
+ @c2.centroid.x.should be_close(36.2945235015093,0.00001)
100
+ @c2.centroid.y.should be_close(48.3211154233146,0.00001)
101
+ end
102
+
103
+ it "should get the center with the correct srid" do
104
+ @c1.centroid.srid.should eql(123)
105
+ end
106
+
107
+ it "distance from another" do
108
+ @c1.distance_to(@c3).should eql(0.0)
109
+ end
110
+
111
+ it "distance to a linestring" do
112
+ @c1.distance_to(@s1).should be_close(1.8,0.001)
113
+ end
114
+
115
+ it "should simplify me" do
116
+ @c3.simplify.should be_instance_of(Polygon)
117
+ end
118
+
119
+ it "should simplify me number of points" do
120
+ @c3.simplify[0].length.should eql(4)
121
+ end
122
+
123
+ #Strange again.... s2 s3 ... error
124
+ it do
125
+ @c3.touches?(@s1).should be_false
126
+ end
127
+
128
+ it do
129
+ @c2.should be_simple
130
+ end
131
+
132
+ it do
133
+ @c2.disjoint?(@p2).should be_true
134
+ end
135
+
136
+ it do
137
+ @c3.polygonize.should have(2).geometries
138
+ end
139
+
140
+ # weird...
141
+ # it do
142
+ # @c1.disjoint?(@s2).should be_true
143
+ # end
144
+
145
+ end
146
+ end