jsl-GeoRuby 1.3.3

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.
Files changed (43) hide show
  1. data/MIT-LICENSE +7 -0
  2. data/README +83 -0
  3. data/georuby.gemspec +37 -0
  4. data/lib/geo_ruby.rb +16 -0
  5. data/lib/geo_ruby/shp4r/dbf.rb +180 -0
  6. data/lib/geo_ruby/shp4r/shp.rb +701 -0
  7. data/lib/geo_ruby/simple_features/envelope.rb +134 -0
  8. data/lib/geo_ruby/simple_features/ewkb_parser.rb +216 -0
  9. data/lib/geo_ruby/simple_features/ewkt_parser.rb +336 -0
  10. data/lib/geo_ruby/simple_features/geometry.rb +225 -0
  11. data/lib/geo_ruby/simple_features/geometry_collection.rb +136 -0
  12. data/lib/geo_ruby/simple_features/geometry_factory.rb +81 -0
  13. data/lib/geo_ruby/simple_features/georss_parser.rb +135 -0
  14. data/lib/geo_ruby/simple_features/helper.rb +18 -0
  15. data/lib/geo_ruby/simple_features/line_string.rb +166 -0
  16. data/lib/geo_ruby/simple_features/linear_ring.rb +12 -0
  17. data/lib/geo_ruby/simple_features/multi_line_string.rb +39 -0
  18. data/lib/geo_ruby/simple_features/multi_point.rb +41 -0
  19. data/lib/geo_ruby/simple_features/multi_polygon.rb +38 -0
  20. data/lib/geo_ruby/simple_features/point.rb +236 -0
  21. data/lib/geo_ruby/simple_features/polygon.rb +150 -0
  22. data/rakefile.rb +44 -0
  23. data/test/data/multipoint.dbf +0 -0
  24. data/test/data/multipoint.shp +0 -0
  25. data/test/data/multipoint.shx +0 -0
  26. data/test/data/point.dbf +0 -0
  27. data/test/data/point.shp +0 -0
  28. data/test/data/point.shx +0 -0
  29. data/test/data/polygon.dbf +0 -0
  30. data/test/data/polygon.shp +0 -0
  31. data/test/data/polygon.shx +0 -0
  32. data/test/data/polyline.dbf +0 -0
  33. data/test/data/polyline.shp +0 -0
  34. data/test/data/polyline.shx +0 -0
  35. data/test/test_ewkb_parser.rb +171 -0
  36. data/test/test_ewkt_parser.rb +193 -0
  37. data/test/test_georss_kml.rb +231 -0
  38. data/test/test_shp.rb +76 -0
  39. data/test/test_shp_write.rb +150 -0
  40. data/test/test_simple_features.rb +506 -0
  41. data/tools/db.yml +6 -0
  42. data/tools/shp2sql.rb +92 -0
  43. metadata +95 -0
@@ -0,0 +1,506 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'geo_ruby'
4
+ require 'test/unit'
5
+
6
+ include GeoRuby::SimpleFeatures
7
+
8
+ class TestSimpleFeatures < Test::Unit::TestCase
9
+
10
+ def test_geometry_creation
11
+ geometry = Geometry::new
12
+ assert_equal(DEFAULT_SRID,geometry.srid)
13
+
14
+ geometry = Geometry::new(225)
15
+ assert_equal(225,geometry.srid)
16
+
17
+ point = Geometry.from_hex_ewkb("01010000207B000000CDCCCCCCCCCC28406666666666A64640")
18
+ assert_equal(Point,point.class)
19
+ assert_equal(12.4,point.x)
20
+
21
+ end
22
+ def test_point_creation
23
+ point= Point::new(456)
24
+ assert_equal(456,point.srid)
25
+ assert(!point.with_z)
26
+ assert(!point.with_m)
27
+ assert_equal(0.0,point.x)
28
+ assert_equal(0.0,point.y)
29
+ assert_equal(0.0,point.z)
30
+ assert_equal(0.0,point.m)
31
+
32
+ point.set_x_y_z(2.6,56.6,12)
33
+ assert_equal(2.6,point.x)
34
+ assert_equal(56.6,point.y)
35
+ assert_equal(12.0,point.z)
36
+
37
+ point= Point.from_coordinates([1.6,2.8],123)
38
+ assert_equal(1.6,point.x)
39
+ assert_equal(2.8,point.y)
40
+ assert(!point.with_z)
41
+ assert_equal(0.0,point.z)
42
+ assert_equal(123,point.srid)
43
+
44
+ point=Point.from_coordinates([1.6,2.8,3.4],123,true)
45
+ assert_equal(1.6,point.x)
46
+ assert_equal(2.8,point.y)
47
+ assert(point.with_z)
48
+ assert_equal(3.4,point.z)
49
+ assert_equal(123,point.srid)
50
+
51
+ point=Point.from_coordinates([1.6,2.8,3.4,15],DEFAULT_SRID,true,true)
52
+ assert_equal(1.6,point.x)
53
+ assert_equal(2.8,point.y)
54
+ assert(point.with_z)
55
+ assert_equal(3.4,point.z)
56
+ assert(point.with_m)
57
+ assert_equal(15,point.m)
58
+ assert_equal(DEFAULT_SRID,point.srid)
59
+
60
+ point= Point.from_x_y(1.6,2.8,123)
61
+ assert_equal(1.6,point.x)
62
+ assert_equal(2.8,point.y)
63
+ assert(!point.with_z)
64
+ assert_equal(0,point.z)
65
+ assert_equal(123,point.srid)
66
+
67
+ point= Point.from_x_y_z(-1.6,2.8,-3.4,123)
68
+ assert_equal(-1.6,point.x)
69
+ assert_equal(2.8,point.y)
70
+ assert_equal(-3.4,point.z)
71
+ assert_equal(123,point.srid)
72
+
73
+ point= Point.from_x_y_m(-1.6,2.8,-3.4,123)
74
+ assert_equal(-1.6,point.x)
75
+ assert_equal(2.8,point.y)
76
+ assert_equal(-3.4,point.m)
77
+ assert_equal(123,point.srid)
78
+
79
+ point= Point.from_x_y_z_m(-1.6,2.8,-3.4,15,123)
80
+ assert_equal(-1.6,point.x)
81
+ assert_equal(2.8,point.y)
82
+ assert_equal(-3.4,point.z)
83
+ assert_equal(15,point.m)
84
+ assert_equal(123,point.srid)
85
+
86
+ bbox = Point.from_x_y_z_m(-1.6,2.8,-3.4,15,123).bounding_box
87
+ assert_equal(2,bbox.length)
88
+ assert_equal(Point.from_x_y_z(-1.6,2.8,-3.4),bbox[0])
89
+ assert_equal(Point.from_x_y_z(-1.6,2.8,-3.4),bbox[1])
90
+ end
91
+
92
+ def test_point_equal
93
+ point1= Point::new
94
+ point1.set_x_y(1.5,45.4)
95
+ point2= Point::new
96
+ point2.set_x_y(1.5,45.4)
97
+ point3= Point::new
98
+ point3.set_x_y(4.5,12.3)
99
+ point4= Point::new
100
+ point4.set_x_y_z(1.5,45.4,423)
101
+ point5= Point::new
102
+ point5.set_x_y(1.5,45.4)
103
+ point5.m=15
104
+ geometry= Geometry::new
105
+
106
+ assert(point1==point2)
107
+ assert(point1!=point3)
108
+ assert(point1!=point4)
109
+ assert(point1!=point5)
110
+ assert(point1!=geometry)
111
+ end
112
+
113
+ def test_point_binary
114
+ point = Point.from_x_y(12.4,45.3,123)
115
+ assert_equal("01010000207B000000CDCCCCCCCCCC28406666666666A64640", point.as_hex_ewkb)
116
+
117
+ point = Point.from_x_y_z(12.4,45.3,-3.5,123)
118
+ assert_equal("01010000A07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC0", point.as_hex_ewkb)
119
+
120
+ point = Point.from_x_y_z_m(12.4,45.3,-3.5,15,123)
121
+ assert_equal("01010000E07B000000CDCCCCCCCCCC28406666666666A646400000000000000CC00000000000002E40", point.as_hex_ewkb)
122
+
123
+ assert_equal("0101000000CDCCCCCCCCCC28406666666666A64640", point.as_hex_wkb)
124
+ end
125
+
126
+ def test_point_text
127
+ point = Point.from_x_y(12.4,45.3,123)
128
+ assert_equal("SRID=123;POINT(12.4 45.3)", point.as_ewkt)
129
+
130
+ point = Point.from_x_y_z(12.4,45.3,-3.5,123)
131
+ assert_equal("SRID=123;POINT(12.4 45.3 -3.5)", point.as_ewkt)
132
+ assert_equal("POINT(12.4 45.3)", point.as_wkt)
133
+ assert_equal("POINT(12.4 45.3 -3.5)", point.as_ewkt(false,true))
134
+
135
+ point = Point.from_x_y_m(12.4,45.3,-3.5,123)
136
+ assert_equal("SRID=123;POINTM(12.4 45.3 -3.5)", point.as_ewkt)
137
+ assert_equal("SRID=123;POINT(12.4 45.3)", point.as_ewkt(true,true,false))
138
+ end
139
+
140
+ def test_point_distance
141
+ point1 = Point.from_x_y(0,0)
142
+ point2 = Point.from_x_y(3,4)
143
+ assert_equal(5,point1.euclidian_distance(point2))
144
+
145
+ assert_in_delta(554058.924,point1.ellipsoidal_distance(point2),0.001)
146
+
147
+ assert_in_delta(555811.68,point1.spherical_distance(point2),0.01)
148
+ end
149
+
150
+ def point_subclassable
151
+ place = Class.new(Point)
152
+ p = place.from_x_y(0.0,0.0)
153
+ assert p.is_a?(place)
154
+ end
155
+
156
+ def test_line_string_creation
157
+ line_string = LineString::new
158
+ line_string.concat([Point.from_x_y(12.4,45.3),Point.from_x_y(45.4,41.6)])
159
+
160
+ assert_equal(2,line_string.length)
161
+ assert_equal(Point.from_x_y(12.4,45.3),line_string[0])
162
+
163
+ point=Point.from_x_y(123,45.8777)
164
+ line_string[0]=point
165
+ assert_equal(point,line_string[0])
166
+
167
+ points=[Point.from_x_y(123,45.8777),Point.from_x_y(45.4,41.6)]
168
+ line_string.each_index {|i| assert_equal(points[i],line_string[i]) }
169
+
170
+ point=Point.from_x_y(22.4,13.56)
171
+ line_string << point
172
+ assert_equal(3,line_string.length)
173
+ assert_equal(point,line_string[2])
174
+
175
+ line_string = LineString.from_points([Point.from_x_y(12.4,-45.3),Point.from_x_y(45.4,41.6)],123)
176
+ assert_equal(LineString,line_string.class)
177
+ assert_equal(2,line_string.length)
178
+ assert_equal(Point.from_x_y(12.4,-45.3),line_string[0])
179
+ assert_equal(Point.from_x_y(45.4,41.6),line_string[1])
180
+
181
+ line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
182
+ assert_equal(LineString,line_string.class)
183
+ assert_equal(3,line_string.length)
184
+ assert_equal(Point.from_x_y(12.4,-45.3),line_string[0])
185
+ assert_equal(Point.from_x_y(45.4,41.6),line_string[1])
186
+
187
+
188
+ line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
189
+ assert_equal(LineString,line_string.class)
190
+ assert_equal(3,line_string.length)
191
+ assert_equal(Point.from_x_y_z(12.4,-45.3,123,123),line_string[0])
192
+
193
+ line_string = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true)
194
+ assert_equal(LineString,line_string.class)
195
+ assert_equal(3,line_string.length)
196
+ assert_equal(Point.from_x_y_z(12.4,-45.3,123,123),line_string[0])
197
+
198
+ bbox = LineString.from_coordinates([[12.4,-45.3,123],[45.4,41.6,333],[4.456,1.0698,987]],123,true).bounding_box
199
+ assert_equal(2,bbox.length)
200
+ assert_equal(Point.from_x_y_z(4.456,-45.3,123),bbox[0])
201
+ assert_equal(Point.from_x_y_z(45.4,41.6,987),bbox[1])
202
+
203
+ end
204
+
205
+ def test_line_string_equal
206
+ line_string1 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123)
207
+ line_string2 = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],123)
208
+ point = Point.from_x_y(12.4,-45.3,123)
209
+
210
+ assert(LineString.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698]],123) == line_string1)
211
+ assert(line_string1 != line_string2)
212
+ assert(line_string1 != point)
213
+ end
214
+
215
+ def test_line_string_binary
216
+ line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
217
+ assert_equal("01020000200001000002000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC4440",line_string.as_hex_ewkb)
218
+
219
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
220
+ assert_equal("01020000A00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A641403333333333B34640CDCCCCCCCCCC44409A99999999992840",line_string.as_hex_ewkb)
221
+
222
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3,45.1],[45.4,41.6,12.3,40.23]],256,true,true)
223
+ assert_equal("01020000E00001000002000000CDCCCCCCCCCC28406666666666A646C06666666666A64140CDCCCCCCCC8C46403333333333B34640CDCCCCCCCCCC44409A999999999928403D0AD7A3701D4440",line_string.as_hex_ewkb)
224
+ end
225
+
226
+ def test_line_string_text
227
+ line_string = LineString.from_coordinates([[12.4,-45.3],[45.4,41.6]],256)
228
+ assert_equal("SRID=256;LINESTRING(12.4 -45.3,45.4 41.6)",line_string.as_ewkt)
229
+
230
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,true)
231
+ assert_equal("SRID=256;LINESTRING(12.4 -45.3 35.3,45.4 41.6 12.3)",line_string.as_ewkt)
232
+
233
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3],[45.4,41.6,12.3]],256,false,true)
234
+ assert_equal("SRID=256;LINESTRINGM(12.4 -45.3 35.3,45.4 41.6 12.3)",line_string.as_ewkt)
235
+
236
+ line_string = LineString.from_coordinates([[12.4,-45.3,35.3,25.2],[45.4,41.6,12.3,13.75]],256,true,true)
237
+ assert_equal("SRID=256;LINESTRING(12.4 -45.3 35.3 25.2,45.4 41.6 12.3 13.75)",line_string.as_ewkt)
238
+
239
+ end
240
+
241
+ def test_linear_ring_creation
242
+ #testing just the constructor helpers since the rest is the same as for line_string
243
+ linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],345)
244
+ assert_equal(LinearRing,linear_ring.class)
245
+ assert_equal(4,linear_ring.length)
246
+ assert(linear_ring.is_closed)
247
+ assert_equal(Point.from_x_y(45.4,41.6,345),linear_ring[1])
248
+ end
249
+ #no test of the binary representation for linear_rings : always with polygons and like line_string
250
+ def test_polygon_creation
251
+ linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
252
+ linear_ring2 = LinearRing.from_coordinates([[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]],256)
253
+ point1 = Point.from_x_y(12.4,-45.3,256)
254
+ point2 = Point.from_x_y(45.4,41.6,256)
255
+ point3 = Point.from_x_y(4.456,1.0698,256)
256
+ point4 = Point.from_x_y(12.4,-45.3,256)
257
+ point5 = Point.from_x_y(2.4,5.3,256)
258
+ point6 = Point.from_x_y(5.4,1.4263,256)
259
+ point7 = Point.from_x_y(14.46,1.06,256)
260
+ point8 = Point.from_x_y(2.4,5.3,256)
261
+
262
+ polygon = Polygon::new(256)
263
+ assert_equal(0,polygon.length)
264
+
265
+ polygon << linear_ring1
266
+ assert_equal(1,polygon.length)
267
+ assert_equal(linear_ring1,polygon[0])
268
+
269
+ #the validity of the hole is not checked : just for the sake of example
270
+ polygon << linear_ring2
271
+ assert_equal(2,polygon.length)
272
+ assert_equal(linear_ring2,polygon[1])
273
+
274
+ polygon = Polygon.from_linear_rings([linear_ring1,linear_ring2],256)
275
+ assert_equal(Polygon,polygon.class)
276
+ assert_equal(2,polygon.length)
277
+ assert_equal(linear_ring1,polygon[0])
278
+ assert_equal(linear_ring2,polygon[1])
279
+
280
+ polygon = 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]]],256)
281
+ assert_equal(Polygon,polygon.class)
282
+ assert_equal(2,polygon.length)
283
+ assert_equal(linear_ring1,polygon[0])
284
+ assert_equal(linear_ring2,polygon[1])
285
+
286
+ polygon = Polygon.from_points([[point1,point2,point3,point4],[point5,point6,point7,point8]],256)
287
+ assert_equal(2,polygon.length)
288
+ assert_equal(linear_ring1,polygon[0])
289
+ assert_equal(linear_ring2,polygon[1])
290
+
291
+ polygon = Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true)
292
+ assert_equal(Polygon,polygon.class)
293
+ assert_equal(2,polygon.length)
294
+
295
+ linear_ring1 = LinearRing.from_coordinates([[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],256,true)
296
+ linear_ring2 = LinearRing.from_coordinates([[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]],256,true)
297
+
298
+ assert_equal(linear_ring1,polygon[0])
299
+ assert_equal(linear_ring2,polygon[1])
300
+
301
+ bbox = Polygon.from_coordinates([[[12.4,-45.3,15.2],[45.4,41.6,2.4],[4.456,1.0698,5.6],[12.4,-45.3,6.1]],[[2.4,5.3,4.5],[5.4,1.4263,4.2],[14.46,1.06,123.1],[2.4,5.3,4.4]]],256,true).bounding_box
302
+ assert_equal(2,bbox.length)
303
+ assert_equal(Point.from_x_y_z(4.456,-45.3,2.4),bbox[0])
304
+ assert_equal(Point.from_x_y_z(45.4,41.6,123.1),bbox[1])
305
+
306
+
307
+
308
+ end
309
+ def test_polygon_equal
310
+ polygon1 = 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]]],256)
311
+ polygon2 = 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]]])
312
+ point = Point.from_x_y(12.4,-45.3,123)
313
+
314
+ assert(polygon1 == 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]]],256))
315
+ assert(polygon1 != polygon2)
316
+ assert(polygon1 != point)
317
+ end
318
+ def test_polygon_binary
319
+ polygon = Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
320
+ #taken from PostGIS answer
321
+ assert_equal("0103000020000100000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F",polygon.as_hex_ewkb)
322
+
323
+ polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true)
324
+ #taken from PostGIS answer
325
+ assert_equal("01030000A000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040",polygon.as_hex_ewkb);
326
+
327
+
328
+ polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true)
329
+ assert_equal("010300006000010000020000000500000000000000000000000000000000000000000000000000004000000000000010400000000000000000000000000000004000000000000010400000000000001040000000000000004000000000000000000000000000001040000000000000004000000000000000000000000000000000000000000000004005000000000000000000F03F000000000000F03F00000000000000400000000000000840000000000000F03F0000000000000040000000000000084000000000000008400000000000000040000000000000F03F00000000000008400000000000000040000000000000F03F000000000000F03F0000000000000040",polygon.as_hex_ewkb);
330
+
331
+ polygon = Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true)
332
+ assert_equal("01030000E0000100000200000005000000000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C00000000000001040000000000000000000000000000000400000000000001440000000000000104000000000000010400000000000000040AE47E17A14AE1240000000000000000000000000000010400000000000000040713D0AD7A370F53F000000000000000000000000000000000000000000000040CDCCCCCCCC8C46C005000000000000000000F03F000000000000F03F00000000000000409A999999999928400000000000000840000000000000F03F00000000000000400000000000C05E400000000000000840000000000000084000000000000000406666666666662840000000000000F03F000000000000084000000000000000400000000000002840000000000000F03F000000000000F03F00000000000000409A99999999992840",polygon.as_hex_ewkb);
333
+
334
+ end
335
+ def test_polygon_text
336
+ polygon = Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
337
+ assert_equal("SRID=256;POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1))",polygon.as_ewkt)
338
+
339
+ polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,true)
340
+ assert_equal("SRID=256;POLYGON((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))",polygon.as_ewkt);
341
+
342
+ polygon = Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256,false,true)
343
+ assert_equal("SRID=256;POLYGONM((0 0 2,4 0 2,4 4 2,0 4 2,0 0 2),(1 1 2,3 1 2,3 3 2,1 3 2,1 1 2))",polygon.as_ewkt);
344
+
345
+ polygon = Polygon.from_coordinates([[[0,0,2,-45.1],[4,0,2,5],[4,4,2,4.67],[0,4,2,1.34],[0,0,2,-45.1]],[[1,1,2,12.3],[3,1,2,123],[3,3,2,12.2],[1,3,2,12],[1,1,2,12.3]]],256,true,true)
346
+ assert_equal("SRID=256;POLYGON((0 0 2 -45.1,4 0 2 5,4 4 2 4.67,0 4 2 1.34,0 0 2 -45.1),(1 1 2 12.3,3 1 2 123,3 3 2 12.2,1 3 2 12,1 1 2 12.3))",polygon.as_ewkt);
347
+ end
348
+
349
+ def test_geometry_collection_creation
350
+ geometry_collection = GeometryCollection::new(256)
351
+ geometry_collection << Point.from_x_y(4.67,45.4,256)
352
+
353
+ assert_equal(1,geometry_collection.length)
354
+ assert_equal(Point.from_x_y(4.67,45.4,256),geometry_collection[0])
355
+
356
+ geometry_collection[0]=LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
357
+ geometry_collection << Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)
358
+ assert_equal(2,geometry_collection.length)
359
+ assert_equal(LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),geometry_collection[0])
360
+
361
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
362
+ assert_equal(GeometryCollection,geometry_collection.class)
363
+ assert_equal(256,geometry_collection.srid)
364
+ assert_equal(2,geometry_collection.length)
365
+ assert_equal(LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),geometry_collection[1])
366
+
367
+ bbox = geometry_collection.bounding_box
368
+ assert_equal(2,bbox.length)
369
+ assert_equal(Point.from_x_y(4.67,12.45),bbox[0])
370
+ assert_equal(Point.from_x_y(67.55,54),bbox[1])
371
+ end
372
+ def test_geometry_collection_equal
373
+ geometry_collection1 = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
374
+ geometry_collection2 = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256),Polygon.from_coordinates([[[0,0,2],[4,0,2],[4,4,2],[0,4,2],[0,0,2]],[[1,1,2],[3,1,2],[3,3,2],[1,3,2],[1,1,2]]],256)],256,true)
375
+ line_string=LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)
376
+
377
+ assert(GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256) == geometry_collection1)
378
+ assert(geometry_collection1 != geometry_collection2)
379
+ assert(geometry_collection1 != line_string)
380
+ end
381
+ def test_geometry_collection_binary
382
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
383
+ assert_equal("010700002000010000020000000101000000AE47E17A14AE12403333333333B34640010200000002000000CDCCCCCCCCCC16406666666666E628403333333333E350400000000000004B40",geometry_collection.as_hex_ewkb)
384
+
385
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y_z_m(4.67,45.4,45.67,2.3,256),LineString.from_coordinates([[5.7,12.45,4.56,98.3],[67.55,54,12.2,3.4]],256,true, true)],256,true, true)
386
+ assert_equal("01070000E0000100000200000001010000C0AE47E17A14AE12403333333333B34640F6285C8FC2D54640666666666666024001020000C002000000CDCCCCCCCCCC16406666666666E628403D0AD7A3703D124033333333339358403333333333E350400000000000004B4066666666666628403333333333330B40",geometry_collection.as_hex_ewkb)
387
+
388
+ end
389
+ def test_geometry_collection_text
390
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y(4.67,45.4,256),LineString.from_coordinates([[5.7,12.45],[67.55,54]],256)],256)
391
+ assert_equal("SRID=256;GEOMETRYCOLLECTION(POINT(4.67 45.4),LINESTRING(5.7 12.45,67.55 54))",geometry_collection.as_ewkt)
392
+
393
+ geometry_collection = GeometryCollection.from_geometries([Point.from_x_y_m(4.67,45.4,45.6,256),LineString.from_coordinates([[5.7,12.45,5.6],[67.55,54,6.7]],256,false,true)],256,false,true)
394
+ assert_equal("SRID=256;GEOMETRYCOLLECTIONM(POINTM(4.67 45.4 45.6),LINESTRINGM(5.7 12.45 5.6,67.55 54 6.7))",geometry_collection.as_ewkt)
395
+
396
+ end
397
+ def test_multi_point_creation
398
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
399
+ assert(multi_point.instance_of?(MultiPoint))
400
+ assert_equal(3,multi_point.length)
401
+ assert_equal(Point.from_x_y(12.4,-123.3,444),multi_point[0])
402
+ assert_equal(Point.from_x_y(123.55555555,123,444),multi_point[2])
403
+ end
404
+ def test_multi_point_binary
405
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
406
+ assert_equal("0104000020BC010000030000000101000000CDCCCCCCCCCC28403333333333D35EC0010100000066666666664650C09A99999999D95E4001010000001F97DD388EE35E400000000000C05E40",multi_point.as_hex_ewkb)
407
+
408
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,1.2],[123.55555555,123,2.3]],444,true)
409
+ assert_equal("01040000A0BC010000030000000101000080CDCCCCCCCCCC28403333333333D35EC00000000000001240010100008066666666664650C09A99999999D95E40333333333333F33F01010000801F97DD388EE35E400000000000C05E406666666666660240",multi_point.as_hex_ewkb)
410
+
411
+
412
+ end
413
+ def test_multi_point_text
414
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3],[-65.1,123.4],[123.55555555,123]],444)
415
+ assert_equal("SRID=444;MULTIPOINT((12.4 -123.3),(-65.1 123.4),(123.55555555 123))",multi_point.as_ewkt)
416
+
417
+ multi_point = MultiPoint.from_coordinates([[12.4,-123.3,4.5],[-65.1,123.4,6.7],[123.55555555,123,7.8]],444,true)
418
+ assert_equal("SRID=444;MULTIPOINT((12.4 -123.3 4.5),(-65.1 123.4 6.7),(123.55555555 123 7.8))",multi_point.as_ewkt)
419
+
420
+
421
+ end
422
+
423
+ def test_multi_line_string_creation
424
+ multi_line_string1 = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
425
+ assert(multi_line_string1.instance_of?(MultiLineString))
426
+ assert_equal(2,multi_line_string1.length)
427
+ assert_equal(LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),multi_line_string1[0])
428
+
429
+ multi_line_string2= MultiLineString.from_coordinates([[[1.5,45.2],[-54.12312,-0.012]],[[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]]],256);
430
+ assert(multi_line_string2.instance_of?(MultiLineString))
431
+ assert_equal(2,multi_line_string2.length)
432
+ assert_equal(LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),multi_line_string2[0])
433
+ assert(multi_line_string2 == multi_line_string2)
434
+ end
435
+
436
+ def test_multi_line_string_binary
437
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
438
+ assert_equal("01050000200001000002000000010200000002000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF010200000003000000000000000000F83F9A99999999994640E4BD6A65C20F4BC0FA7E6ABC749388BF39B4C876BE8F46403333333333D35E40",multi_line_string.as_hex_ewkb)
439
+
440
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true)
441
+ assert_equal("0105000020000100000200000001020000C002000000000000000000F83F9A99999999994640CDCCCCCCCCCCF43F333333333333F33FE4BD6A65C20F4BC0FA7E6ABC749388BF333333333333F33F000000000000124001020000C003000000000000000000F83F9A99999999994640666666666666144000000000000012C0E4BD6A65C20F4BC0FA7E6ABC749388BF3333333333331BC03333333333330B4039B4C876BE8F46403333333333D35E40000000000000124033333333333315C0",multi_line_string.as_hex_ewkb)
442
+ end
443
+
444
+ def test_multi_line_string_text
445
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012]],256),LineString.from_coordinates([[1.5,45.2],[-54.12312,-0.012],[45.123,123.3]],256)],256)
446
+ assert_equal("SRID=256;MULTILINESTRING((1.5 45.2,-54.12312 -0.012),(1.5 45.2,-54.12312 -0.012,45.123 123.3))",multi_line_string.as_ewkt)
447
+
448
+ multi_line_string = MultiLineString.from_line_strings([LineString.from_coordinates([[1.5,45.2,1.3,1.2],[-54.12312,-0.012,1.2,4.5]],256,true,true),LineString.from_coordinates([[1.5,45.2,5.1,-4.5],[-54.12312,-0.012,-6.8,3.4],[45.123,123.3,4.5,-5.3]],256,true,true)],256,true,true)
449
+ assert_equal("SRID=256;MULTILINESTRING((1.5 45.2 1.3 1.2,-54.12312 -0.012 1.2 4.5),(1.5 45.2 5.1 -4.5,-54.12312 -0.012 -6.8 3.4,45.123 123.3 4.5 -5.3))",multi_line_string.as_ewkt)
450
+
451
+ end
452
+
453
+ def test_multi_polygon_creation
454
+ multi_polygon1 = MultiPolygon.from_polygons([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]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256)
455
+ assert(multi_polygon1.instance_of?(MultiPolygon))
456
+ assert_equal(2,multi_polygon1.length)
457
+ assert_equal(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]]],256),multi_polygon1[0])
458
+
459
+ multi_polygon2 = MultiPolygon.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]]],[[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]]],256)
460
+ assert(multi_polygon2.instance_of?(MultiPolygon))
461
+ assert_equal(2,multi_polygon2.length)
462
+ assert_equal(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]]],256),multi_polygon2[0])
463
+ assert(multi_polygon1 == multi_polygon2)
464
+ end
465
+
466
+ def test_multi_polygon_binary
467
+ multi_polygon = MultiPolygon.from_polygons([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]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256)
468
+ assert_equal("0106000020000100000200000001030000000200000004000000CDCCCCCCCCCC28406666666666A646C03333333333B34640CDCCCCCCCCCC44406DE7FBA9F1D211403D2CD49AE61DF13FCDCCCCCCCCCC28406666666666A646C004000000333333333333034033333333333315409A999999999915408A8EE4F21FD2F63FEC51B81E85EB2C40F6285C8FC2F5F03F3333333333330340333333333333154001030000000200000005000000000000000000000000000000000000000000000000001040000000000000000000000000000010400000000000001040000000000000000000000000000010400000000000000000000000000000000005000000000000000000F03F000000000000F03F0000000000000840000000000000F03F00000000000008400000000000000840000000000000F03F0000000000000840000000000000F03F000000000000F03F",multi_polygon.as_hex_ewkb)
469
+
470
+ multi_polygon = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,1.2],[45.4,41.6,1.2],[4.456,1.0698,1.2],[12.4,-45.3,1.2]],[[2.4,5.3,1.2],[5.4,1.4263,1.2],[14.46,1.06,1.2],[2.4,5.3,1.2]]],256,false,true),Polygon.from_coordinates([[[0,0,1.2],[4,0,1.2],[4,4,2.3],[0,4,1.2],[0,0,1.2]],[[1,1,2.2],[3,1,3.3],[3,3,1.1],[1,3,2.4],[1,1,2.2]]],256,false,true)],256,false,true)
471
+ assert_equal("0106000020000100000200000001030000400200000004000000CDCCCCCCCCCC28406666666666A646C0333333333333F33F3333333333B34640CDCCCCCCCCCC4440333333333333F33F6DE7FBA9F1D211403D2CD49AE61DF13F333333333333F33FCDCCCCCCCCCC28406666666666A646C0333333333333F33F0400000033333333333303403333333333331540333333333333F33F9A999999999915408A8EE4F21FD2F63F333333333333F33FEC51B81E85EB2C40F6285C8FC2F5F03F333333333333F33F33333333333303403333333333331540333333333333F33F0103000040020000000500000000000000000000000000000000000000333333333333F33F00000000000010400000000000000000333333333333F33F00000000000010400000000000001040666666666666024000000000000000000000000000001040333333333333F33F00000000000000000000000000000000333333333333F33F05000000000000000000F03F000000000000F03F9A999999999901400000000000000840000000000000F03F6666666666660A40000000000000084000000000000008409A9999999999F13F000000000000F03F00000000000008403333333333330340000000000000F03F000000000000F03F9A99999999990140",multi_polygon.as_hex_ewkb)
472
+ end
473
+
474
+ def test_multi_polygon_text
475
+ multi_polygon = MultiPolygon.from_polygons([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]]],256),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]],256)],256)
476
+ assert_equal("SRID=256;MULTIPOLYGON(((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)),((0 0,4 0,4 4,0 4,0 0),(1 1,3 1,3 3,1 3,1 1)))",multi_polygon.as_ewkt)
477
+
478
+ multi_polygon = MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3,2],[45.4,41.6,3],[4.456,1.0698,4],[12.4,-45.3,2]],[[2.4,5.3,1],[5.4,1.4263,3.44],[14.46,1.06,4.5],[2.4,5.3,1]]],DEFAULT_SRID,true),Polygon.from_coordinates([[[0,0,5.6],[4,0,5.4],[4,4,1],[0,4,23],[0,0,5.6]],[[1,1,2.3],[3,1,4],[3,3,5],[1,3,6],[1,1,2.3]]],DEFAULT_SRID,true)],DEFAULT_SRID,true)
479
+ assert_equal("SRID=-1;MULTIPOLYGON(((12.4 -45.3 2,45.4 41.6 3,4.456 1.0698 4,12.4 -45.3 2),(2.4 5.3 1,5.4 1.4263 3.44,14.46 1.06 4.5,2.4 5.3 1)),((0 0 5.6,4 0 5.4,4 4 1,0 4 23,0 0 5.6),(1 1 2.3,3 1 4,3 3 5,1 3 6,1 1 2.3)))",multi_polygon.as_ewkt)
480
+
481
+ end
482
+
483
+ def test_envelope
484
+ linear_ring = LinearRing.from_coordinates([[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],256)
485
+ polygon = Polygon.from_linear_rings([linear_ring],256)
486
+ e = polygon.envelope
487
+
488
+ assert_equal(e.lower_corner.class, Point)
489
+ assert_equal(e.upper_corner.class, Point)
490
+
491
+ assert_equal(e.lower_corner.x,4.456)
492
+ assert_equal(e.lower_corner.y,-45.3)
493
+ assert_equal(e.upper_corner.x,45.4)
494
+ assert_equal(e.upper_corner.y,41.6)
495
+
496
+ line_string = LineString.from_coordinates([[13.6,-49.3],[45.4,44.6],[14.2,1.09],[13.6,-49.3]],256)
497
+ e2 = line_string.envelope
498
+
499
+ e3 = e.extend(e2)
500
+
501
+ assert_equal(e3.lower_corner.x,4.456)
502
+ assert_equal(e3.lower_corner.y,-49.3)
503
+ assert_equal(e3.upper_corner.x,45.4)
504
+ assert_equal(e3.upper_corner.y,44.6)
505
+ end
506
+ end