rgeo 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/History.rdoc +6 -0
  2. data/Version +1 -1
  3. data/lib/rgeo.rb +80 -30
  4. data/lib/rgeo/all.rb +48 -0
  5. data/lib/rgeo/cartesian.rb +37 -12
  6. data/lib/rgeo/cartesian/calculations.rb +5 -0
  7. data/lib/rgeo/cartesian/{simple_factory.rb → factory.rb} +14 -17
  8. data/lib/rgeo/cartesian/{simple_feature_classes.rb → feature_classes.rb} +55 -55
  9. data/lib/rgeo/cartesian/{simple_feature_methods.rb → feature_methods.rb} +7 -3
  10. data/lib/rgeo/cartesian/interface.rb +7 -3
  11. data/lib/rgeo/errors.rb +4 -0
  12. data/lib/rgeo/features.rb +25 -20
  13. data/lib/rgeo/geo_json.rb +10 -8
  14. data/lib/rgeo/geography.rb +10 -16
  15. data/lib/rgeo/geography/all.rb +40 -0
  16. data/lib/rgeo/geography/factory.rb +2 -2
  17. data/lib/rgeo/geography/{factories.rb → interface.rb} +4 -2
  18. data/lib/rgeo/geography/simple_mercator.rb +69 -0
  19. data/lib/rgeo/geography/simple_mercator/feature_classes.rb +62 -62
  20. data/lib/rgeo/geography/simple_mercator/projector.rb +1 -1
  21. data/lib/rgeo/geography/simple_spherical.rb +68 -0
  22. data/lib/rgeo/geography/simple_spherical/calculations.rb +2 -2
  23. data/lib/rgeo/geography/simple_spherical/feature_classes.rb +44 -44
  24. data/lib/rgeo/geos.rb +12 -9
  25. data/lib/rgeo/impl_helpers.rb +14 -9
  26. data/lib/rgeo/impl_helpers/basic_geometry_collection_methods.rb +10 -0
  27. data/lib/rgeo/impl_helpers/basic_point_methods.rb +3 -0
  28. data/lib/rgeo/{geography/helper.rb → impl_helpers/math.rb} +3 -3
  29. data/lib/rgeo/wkrep.rb +32 -12
  30. data/lib/rgeo/wkrep/wkb_generator.rb +95 -9
  31. data/lib/rgeo/wkrep/wkb_parser.rb +117 -9
  32. data/lib/rgeo/wkrep/wkt_generator.rb +106 -18
  33. data/lib/rgeo/wkrep/wkt_parser.rb +203 -59
  34. data/tests/simple_cartesian/tc_calculations.rb +8 -8
  35. data/tests/wkrep/tc_wkt_generator.rb +362 -0
  36. data/tests/wkrep/tc_wkt_parser.rb +490 -0
  37. metadata +16 -8
@@ -40,7 +40,7 @@ require 'rgeo'
40
40
 
41
41
  module RGeo
42
42
  module Tests # :nodoc:
43
- module SimpleCartesian # :nodoc:
43
+ module Cartesian # :nodoc:
44
44
 
45
45
  class TestCalculations < ::Test::Unit::TestCase # :nodoc:
46
46
 
@@ -54,13 +54,13 @@ module RGeo
54
54
  @point5 = @factory.point(-1, 2)
55
55
  @point6 = @factory.point(-1, 1)
56
56
  @point7 = @factory.point(5, 4)
57
- @horiz_seg = Cartesian::Segment.new(@point1, @point3)
58
- @vert_seg = Cartesian::Segment.new(@point4, @point1)
59
- @short_rising_seg = Cartesian::Segment.new(@point1, @point2)
60
- @long_rising_seg = Cartesian::Segment.new(@point5, @point2)
61
- @parallel_rising_seg = Cartesian::Segment.new(@point6, @point7)
62
- @steep_rising_seg = Cartesian::Segment.new(@point6, @point4)
63
- @degenerate_seg = Cartesian::Segment.new(@point5, @point5)
57
+ @horiz_seg = ::RGeo::Cartesian::Segment.new(@point1, @point3)
58
+ @vert_seg = ::RGeo::Cartesian::Segment.new(@point4, @point1)
59
+ @short_rising_seg = ::RGeo::Cartesian::Segment.new(@point1, @point2)
60
+ @long_rising_seg = ::RGeo::Cartesian::Segment.new(@point5, @point2)
61
+ @parallel_rising_seg = ::RGeo::Cartesian::Segment.new(@point6, @point7)
62
+ @steep_rising_seg = ::RGeo::Cartesian::Segment.new(@point6, @point4)
63
+ @degenerate_seg = ::RGeo::Cartesian::Segment.new(@point5, @point5)
64
64
  end
65
65
 
66
66
 
@@ -0,0 +1,362 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for WKT generator
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'rgeo'
39
+
40
+
41
+ module RGeo
42
+ module Tests # :nodoc:
43
+ module WKRep # :nodoc:
44
+
45
+ class TestWKTGenerator < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def setup
49
+ @factory = ::RGeo::Cartesian.simple_factory(:srid => 1000)
50
+ @factoryz = ::RGeo::Cartesian.simple_factory(:srid => 1000, :support_z_coordinate => true)
51
+ @factorym = ::RGeo::Cartesian.simple_factory(:srid => 1000, :support_m_coordinate => true)
52
+ @factoryzm = ::RGeo::Cartesian.simple_factory(:srid => 1000, :support_z_coordinate => true, :support_m_coordinate => true)
53
+ end
54
+
55
+
56
+ def test_point_2d
57
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
58
+ obj_ = @factory.point(1, 2)
59
+ assert_equal('Point(1.0 2.0)', generator_.generate(obj_))
60
+ end
61
+
62
+
63
+ def test_point_z
64
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
65
+ obj_ = @factoryz.point(1, 2, 3)
66
+ assert_equal('Point(1.0 2.0 3.0)', generator_.generate(obj_))
67
+ end
68
+
69
+
70
+ def test_point_z_wkt11strict
71
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :wkt11_strict)
72
+ obj_ = @factoryz.point(1, 2, 3)
73
+ assert_equal('Point(1.0 2.0)', generator_.generate(obj_))
74
+ end
75
+
76
+
77
+ def test_point_m
78
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
79
+ obj_ = @factorym.point(1, 2, 3)
80
+ assert_equal('Point(1.0 2.0 3.0)', generator_.generate(obj_))
81
+ end
82
+
83
+
84
+ def test_point_zm
85
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
86
+ obj_ = @factoryzm.point(1, 2, 3, 4)
87
+ assert_equal('Point(1.0 2.0 3.0 4.0)', generator_.generate(obj_))
88
+ end
89
+
90
+
91
+ def test_point_squarebrackets
92
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:square_brackets => true)
93
+ obj_ = @factory.point(1, 2)
94
+ assert_equal('Point[1.0 2.0]', generator_.generate(obj_))
95
+ end
96
+
97
+
98
+ def test_point_uppercase
99
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:convert_case => :upper)
100
+ obj_ = @factory.point(1, 2)
101
+ assert_equal('POINT(1.0 2.0)', generator_.generate(obj_))
102
+ end
103
+
104
+
105
+ def test_point_lowercase
106
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:convert_case => :lower)
107
+ obj_ = @factory.point(1, 2)
108
+ assert_equal('point(1.0 2.0)', generator_.generate(obj_))
109
+ end
110
+
111
+
112
+ def test_point_wkt12
113
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :wkt12)
114
+ obj_ = @factory.point(1, 2)
115
+ assert_equal('Point(1.0 2.0)', generator_.generate(obj_))
116
+ end
117
+
118
+
119
+ def test_point_wkt12_z
120
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :wkt12)
121
+ obj_ = @factoryz.point(1, 2, 3)
122
+ assert_equal('Point Z(1.0 2.0 3.0)', generator_.generate(obj_))
123
+ end
124
+
125
+
126
+ def test_point_wkt12_m
127
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :wkt12)
128
+ obj_ = @factorym.point(1, 2, 3)
129
+ assert_equal('Point M(1.0 2.0 3.0)', generator_.generate(obj_))
130
+ end
131
+
132
+
133
+ def test_point_wkt12_zm
134
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :wkt12)
135
+ obj_ = @factoryzm.point(1, 2, 3, 4)
136
+ assert_equal('Point ZM(1.0 2.0 3.0 4.0)', generator_.generate(obj_))
137
+ end
138
+
139
+
140
+ def test_point_ewkt
141
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :ewkt)
142
+ obj_ = @factory.point(1, 2)
143
+ assert_equal('Point(1.0 2.0)', generator_.generate(obj_))
144
+ end
145
+
146
+
147
+ def test_point_ewkt_z
148
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :ewkt)
149
+ obj_ = @factoryz.point(1, 2, 3)
150
+ assert_equal('Point(1.0 2.0 3.0)', generator_.generate(obj_))
151
+ end
152
+
153
+
154
+ def test_point_ewkt_m
155
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :ewkt)
156
+ obj_ = @factorym.point(1, 2, 3)
157
+ assert_equal('PointM(1.0 2.0 3.0)', generator_.generate(obj_))
158
+ end
159
+
160
+
161
+ def test_point_ewkt_zm
162
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :ewkt)
163
+ obj_ = @factoryzm.point(1, 2, 3, 4)
164
+ assert_equal('Point(1.0 2.0 3.0 4.0)', generator_.generate(obj_))
165
+ end
166
+
167
+
168
+ def test_point_ewkt_with_srid
169
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :ewkt, :emit_ewkt_srid => true)
170
+ obj_ = @factory.point(1, 2)
171
+ assert_equal('SRID=1000;Point(1.0 2.0)', generator_.generate(obj_))
172
+ end
173
+
174
+
175
+ def test_linestring_basic
176
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
177
+ p1_ = @factory.point(1, 2)
178
+ p2_ = @factory.point(2, 2)
179
+ p3_ = @factory.point(1, 1)
180
+ obj_ = @factory.line_string([p1_, p2_, p3_])
181
+ assert_equal('LineString(1.0 2.0,2.0 2.0,1.0 1.0)', generator_.generate(obj_))
182
+ end
183
+
184
+
185
+ def test_linestring_empty
186
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
187
+ obj_ = @factory.line_string([])
188
+ assert_equal('LineString EMPTY', generator_.generate(obj_))
189
+ end
190
+
191
+
192
+ def test_polygon_basic
193
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
194
+ p1_ = @factory.point(0, 0)
195
+ p2_ = @factory.point(10, 0)
196
+ p3_ = @factory.point(10, 10)
197
+ p4_ = @factory.point(0, 10)
198
+ ext_ = @factory.line_string([p1_, p2_, p3_, p4_, p1_])
199
+ obj_ = @factory.polygon(ext_)
200
+ assert_equal('Polygon((0.0 0.0,10.0 0.0,10.0 10.0,0.0 10.0,0.0 0.0))', generator_.generate(obj_))
201
+ end
202
+
203
+
204
+ def test_polygon_with_hole
205
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
206
+ p1_ = @factory.point(0, 0)
207
+ p2_ = @factory.point(10, 0)
208
+ p3_ = @factory.point(10, 10)
209
+ p4_ = @factory.point(0, 10)
210
+ p5_ = @factory.point(1, 1)
211
+ p6_ = @factory.point(2, 2)
212
+ p7_ = @factory.point(3, 1)
213
+ ext_ = @factory.line_string([p1_, p2_, p3_, p4_, p1_])
214
+ int_ = @factory.line_string([p5_, p6_, p7_, p5_])
215
+ obj_ = @factory.polygon(ext_, [int_])
216
+ assert_equal('Polygon((0.0 0.0,10.0 0.0,10.0 10.0,0.0 10.0,0.0 0.0),(1.0 1.0,2.0 2.0,3.0 1.0,1.0 1.0))', generator_.generate(obj_))
217
+ end
218
+
219
+
220
+ def test_polygon_empty
221
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
222
+ obj_ = @factory.polygon(@factory.line_string([]))
223
+ assert_equal('Polygon EMPTY', generator_.generate(obj_))
224
+ end
225
+
226
+
227
+ def test_multipoint_basic
228
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
229
+ p1_ = @factory.point(1, 2)
230
+ p2_ = @factory.point(2, 2)
231
+ p3_ = @factory.point(1, 1)
232
+ obj_ = @factory.multi_point([p1_, p2_, p3_])
233
+ assert_equal('MultiPoint((1.0 2.0),(2.0 2.0),(1.0 1.0))', generator_.generate(obj_))
234
+ end
235
+
236
+
237
+ def test_multipoint_empty
238
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
239
+ obj_ = @factory.multi_point([])
240
+ assert_equal('MultiPoint EMPTY', generator_.generate(obj_))
241
+ end
242
+
243
+
244
+ def test_multilinestring_basic
245
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
246
+ p1_ = @factory.point(0, 0)
247
+ p2_ = @factory.point(10, 0)
248
+ p3_ = @factory.point(10, 10)
249
+ p4_ = @factory.point(0, 10)
250
+ p5_ = @factory.point(1, 1)
251
+ p6_ = @factory.point(2, 2)
252
+ p7_ = @factory.point(3, 1)
253
+ ls1_ = @factory.line_string([p1_, p2_, p3_, p4_, p1_])
254
+ ls2_ = @factory.line_string([p5_, p6_, p7_])
255
+ ls3_ = @factory.line_string([])
256
+ obj_ = @factory.multi_line_string([ls1_, ls2_, ls3_])
257
+ assert_equal('MultiLineString((0.0 0.0,10.0 0.0,10.0 10.0,0.0 10.0,0.0 0.0),(1.0 1.0,2.0 2.0,3.0 1.0),EMPTY)', generator_.generate(obj_))
258
+ end
259
+
260
+
261
+ def test_multilinestring_empty
262
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
263
+ obj_ = @factory.multi_line_string([])
264
+ assert_equal('MultiLineString EMPTY', generator_.generate(obj_))
265
+ end
266
+
267
+
268
+ def test_multipolygon_basic
269
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
270
+ p1_ = @factory.point(0, 0)
271
+ p2_ = @factory.point(10, 0)
272
+ p3_ = @factory.point(10, 10)
273
+ p4_ = @factory.point(0, 10)
274
+ p5_ = @factory.point(1, 1)
275
+ p6_ = @factory.point(2, 2)
276
+ p7_ = @factory.point(3, 1)
277
+ p8_ = @factory.point(20, 20)
278
+ p9_ = @factory.point(30, 20)
279
+ p10_ = @factory.point(30, 30)
280
+ p11_ = @factory.point(20, 30)
281
+ ext1_ = @factory.line_string([p1_, p2_, p3_, p4_, p1_])
282
+ int1_ = @factory.line_string([p5_, p6_, p7_, p5_])
283
+ ext3_ = @factory.line_string([p8_, p9_, p10_, p11_, p8_])
284
+ poly1_ = @factory.polygon(ext1_, [int1_])
285
+ poly2_ = @factory.polygon(@factory.line_string([]))
286
+ poly3_ = @factory.polygon(ext3_)
287
+ obj_ = @factory.multi_polygon([poly1_, poly2_, poly3_])
288
+ assert_equal('MultiPolygon(((0.0 0.0,10.0 0.0,10.0 10.0,0.0 10.0,0.0 0.0),(1.0 1.0,2.0 2.0,3.0 1.0,1.0 1.0)),EMPTY,((20.0 20.0,30.0 20.0,30.0 30.0,20.0 30.0,20.0 20.0)))', generator_.generate(obj_))
289
+ end
290
+
291
+
292
+ def test_multipolygon_empty
293
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
294
+ obj_ = @factory.multi_polygon([])
295
+ assert_equal('MultiPolygon EMPTY', generator_.generate(obj_))
296
+ end
297
+
298
+
299
+ def test_collection_basic
300
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
301
+ p1_ = @factory.point(0, 0)
302
+ p2_ = @factory.point(10, 0)
303
+ p3_ = @factory.point(10, 10)
304
+ p4_ = @factory.point(0, 10)
305
+ p5_ = @factory.point(1, 1)
306
+ p6_ = @factory.point(2, 2)
307
+ p7_ = @factory.point(3, 1)
308
+ p8_ = @factory.point(20, 20)
309
+ p9_ = @factory.point(30, 20)
310
+ p10_ = @factory.point(30, 30)
311
+ p11_ = @factory.point(20, 30)
312
+ ext1_ = @factory.line_string([p1_, p2_, p3_, p4_, p1_])
313
+ int1_ = @factory.line_string([p5_, p6_, p7_, p5_])
314
+ ext3_ = @factory.line_string([p8_, p9_, p10_, p11_, p8_])
315
+ poly1_ = @factory.polygon(ext1_, [int1_])
316
+ poly2_ = @factory.polygon(@factory.line_string([]))
317
+ poly3_ = @factory.polygon(ext3_)
318
+ obj1_ = @factory.multi_polygon([poly1_, poly2_, poly3_])
319
+ obj2_ = @factory.point(1, 2)
320
+ obj_ = @factory.collection([obj1_, obj2_])
321
+ assert_equal('GeometryCollection(MultiPolygon(((0.0 0.0,10.0 0.0,10.0 10.0,0.0 10.0,0.0 0.0),(1.0 1.0,2.0 2.0,3.0 1.0,1.0 1.0)),EMPTY,((20.0 20.0,30.0 20.0,30.0 30.0,20.0 30.0,20.0 20.0))),Point(1.0 2.0))', generator_.generate(obj_))
322
+ end
323
+
324
+
325
+ def test_collection_wkt12_z
326
+ generator_ = ::RGeo::WKRep::WKTGenerator.new(:tag_format => :wkt12)
327
+ p1_ = @factoryz.point(0, 0)
328
+ p2_ = @factoryz.point(10, 0)
329
+ p3_ = @factoryz.point(10, 10)
330
+ p4_ = @factoryz.point(0, 10)
331
+ p5_ = @factoryz.point(1, 1)
332
+ p6_ = @factoryz.point(2, 2)
333
+ p7_ = @factoryz.point(3, 1)
334
+ p8_ = @factoryz.point(20, 20)
335
+ p9_ = @factoryz.point(30, 20)
336
+ p10_ = @factoryz.point(30, 30)
337
+ p11_ = @factoryz.point(20, 30)
338
+ ext1_ = @factoryz.line_string([p1_, p2_, p3_, p4_, p1_])
339
+ int1_ = @factoryz.line_string([p5_, p6_, p7_, p5_])
340
+ ext3_ = @factoryz.line_string([p8_, p9_, p10_, p11_, p8_])
341
+ poly1_ = @factoryz.polygon(ext1_, [int1_])
342
+ poly2_ = @factoryz.polygon(@factory.line_string([]))
343
+ poly3_ = @factoryz.polygon(ext3_)
344
+ obj1_ = @factoryz.multi_polygon([poly1_, poly2_, poly3_])
345
+ obj2_ = @factoryz.point(1, 2, 3)
346
+ obj_ = @factoryz.collection([obj1_, obj2_])
347
+ assert_equal('GeometryCollection Z(MultiPolygon Z(((0.0 0.0 0.0,10.0 0.0 0.0,10.0 10.0 0.0,0.0 10.0 0.0,0.0 0.0 0.0),(1.0 1.0 0.0,2.0 2.0 0.0,3.0 1.0 0.0,1.0 1.0 0.0)),EMPTY,((20.0 20.0 0.0,30.0 20.0 0.0,30.0 30.0 0.0,20.0 30.0 0.0,20.0 20.0 0.0))),Point Z(1.0 2.0 3.0))', generator_.generate(obj_))
348
+ end
349
+
350
+
351
+ def test_collection_empty
352
+ generator_ = ::RGeo::WKRep::WKTGenerator.new
353
+ obj_ = @factory.collection([])
354
+ assert_equal('GeometryCollection EMPTY', generator_.generate(obj_))
355
+ end
356
+
357
+
358
+ end
359
+
360
+ end
361
+ end
362
+ end
@@ -0,0 +1,490 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for WKT parser
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'rgeo'
39
+
40
+
41
+ module RGeo
42
+ module Tests # :nodoc:
43
+ module WKRep # :nodoc:
44
+
45
+ class TestWKTParser < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def test_point_2d
49
+ parser_ = ::RGeo::WKRep::WKTParser.new
50
+ obj_ = parser_.parse('POINT(1 2)')
51
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
52
+ assert_equal(1, obj_.x)
53
+ assert_equal(2, obj_.y)
54
+ end
55
+
56
+
57
+ def test_values_fractional
58
+ parser_ = ::RGeo::WKRep::WKTParser.new
59
+ obj_ = parser_.parse('POINT(1.000 2.5)')
60
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
61
+ assert_equal(1.0, obj_.x)
62
+ assert_equal(2.5, obj_.y)
63
+ end
64
+
65
+
66
+ def test_values_fractional2
67
+ parser_ = ::RGeo::WKRep::WKTParser.new
68
+ obj_ = parser_.parse('POINT(1. .5)')
69
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
70
+ assert_equal(1.0, obj_.x)
71
+ assert_equal(0.5, obj_.y)
72
+ end
73
+
74
+
75
+ def test_values_negative
76
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
77
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
78
+ obj_ = parser_.parse('POINT(-1. -.5 -5.5)')
79
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
80
+ assert_equal(-1.0, obj_.x)
81
+ assert_equal(-0.5, obj_.y)
82
+ assert_equal(-5.5, obj_.z)
83
+ end
84
+
85
+
86
+ def test_point_square_brackets
87
+ parser_ = ::RGeo::WKRep::WKTParser.new
88
+ obj_ = parser_.parse('POINT[1 2]')
89
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
90
+ assert_equal(1, obj_.x)
91
+ assert_equal(2, obj_.y)
92
+ end
93
+
94
+
95
+ def test_point_empty
96
+ parser_ = ::RGeo::WKRep::WKTParser.new
97
+ obj_ = parser_.parse('POINT EMPTY')
98
+ assert_equal(::RGeo::Features::MultiPoint, obj_.geometry_type)
99
+ assert_equal(0, obj_.num_geometries)
100
+ end
101
+
102
+
103
+ def test_point_with_z
104
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
105
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
106
+ obj_ = parser_.parse('POINT(1 2 3)')
107
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
108
+ assert_equal(3, obj_.z)
109
+ assert_nil(obj_.m)
110
+ end
111
+
112
+
113
+ def test_point_with_m
114
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true)
115
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
116
+ obj_ = parser_.parse('POINT(1 2 3)')
117
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
118
+ assert_equal(3, obj_.m)
119
+ assert_nil(obj_.z)
120
+ end
121
+
122
+
123
+ def test_point_with_too_many_coords
124
+ factory_ = ::RGeo::Cartesian.preferred_factory
125
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
126
+ assert_raise(::RGeo::Errors::ParseError) do
127
+ obj_ = parser_.parse('POINT(1 2 3)')
128
+ end
129
+ end
130
+
131
+
132
+ def test_point_wkt12_z
133
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
134
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
135
+ obj_ = parser_.parse('POINT Z(1 2 3)')
136
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
137
+ assert_equal(3, obj_.z)
138
+ assert_nil(obj_.m)
139
+ end
140
+
141
+
142
+ def test_point_wkt12_z_unsupported_factory
143
+ factory_ = ::RGeo::Cartesian.preferred_factory
144
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
145
+ assert_raise(::RGeo::Errors::ParseError) do
146
+ obj_ = parser_.parse('POINT Z(1 2 3)')
147
+ end
148
+ end
149
+
150
+
151
+ def test_point_wkt12_m
152
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true)
153
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
154
+ obj_ = parser_.parse('POINT M(1 2 3)')
155
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
156
+ assert_equal(3, obj_.m)
157
+ assert_nil(obj_.z)
158
+ end
159
+
160
+
161
+ def test_point_wkt12_m_with_factory_zm
162
+ factory_ = ::RGeo::Cartesian.simple_factory(:support_z_coordinate => true, :support_m_coordinate => true)
163
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
164
+ obj_ = parser_.parse('POINT M(1 2 3)')
165
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
166
+ assert_equal(3, obj_.m)
167
+ assert_equal(0, obj_.z)
168
+ end
169
+
170
+
171
+ def test_point_wkt12_m_too_many_coords
172
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true)
173
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
174
+ assert_raise(::RGeo::Errors::ParseError) do
175
+ obj_ = parser_.parse('POINT M(1 2 3 4)')
176
+ end
177
+ end
178
+
179
+
180
+ def test_point_wkt12_zm
181
+ factory_ = ::RGeo::Cartesian.simple_factory(:support_z_coordinate => true, :support_m_coordinate => true)
182
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
183
+ obj_ = parser_.parse('POINT ZM(1 2 3 4)')
184
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
185
+ assert_equal(3, obj_.z)
186
+ assert_equal(4, obj_.m)
187
+ end
188
+
189
+
190
+ def test_point_wkt12_zm_not_enough_coords
191
+ factory_ = ::RGeo::Cartesian.simple_factory(:support_z_coordinate => true, :support_m_coordinate => true)
192
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
193
+ assert_raise(::RGeo::Errors::ParseError) do
194
+ obj_ = parser_.parse('POINT ZM(1 2 3)')
195
+ end
196
+ end
197
+
198
+
199
+ def test_point_ewkt_z
200
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
201
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_ewkt => true)
202
+ obj_ = parser_.parse('POINT(1 2 3)')
203
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
204
+ assert_equal(3, obj_.z)
205
+ assert_nil(obj_.m)
206
+ end
207
+
208
+
209
+ def test_point_ewkt_m
210
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true)
211
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_ewkt => true)
212
+ obj_ = parser_.parse('POINTM(1 2 3)')
213
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
214
+ assert_equal(3, obj_.m)
215
+ assert_nil(obj_.z)
216
+ end
217
+
218
+
219
+ def test_point_ewkt_with_srid
220
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true)
221
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_ewkt => true)
222
+ parser_.set_factory_from_srid do |srid_|
223
+ ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true, :srid => srid_)
224
+ end
225
+ obj_ = parser_.parse('SRID=1000;POINTM(1 2 3)')
226
+ assert_equal(::RGeo::Features::Point, obj_.geometry_type)
227
+ assert_equal(3, obj_.m)
228
+ assert_nil(obj_.z)
229
+ assert_equal(1000, obj_.srid)
230
+ end
231
+
232
+
233
+ def test_point_ewkt_m_too_many_coords
234
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true)
235
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_ewkt => true)
236
+ assert_raise(::RGeo::Errors::ParseError) do
237
+ obj_ = parser_.parse('POINTM(1 2 3 4)')
238
+ end
239
+ end
240
+
241
+
242
+ def test_point_strict_wkt11_with_z
243
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
244
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :strict_wkt11 => true)
245
+ assert_raise(::RGeo::Errors::ParseError) do
246
+ obj_ = parser_.parse('POINT(1 2 3)')
247
+ end
248
+ end
249
+
250
+
251
+ def test_point_non_ewkt_with_srid
252
+ factory_ = ::RGeo::Cartesian.preferred_factory
253
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
254
+ parser_.set_factory_from_srid do |srid_|
255
+ ::RGeo::Cartesian.preferred_factory(:srid => srid_)
256
+ end
257
+ assert_raise(::RGeo::Errors::ParseError) do
258
+ obj_ = parser_.parse('SRID=1000;POINT(1 2)')
259
+ end
260
+ end
261
+
262
+
263
+ def test_linestring_basic
264
+ factory_ = ::RGeo::Cartesian.preferred_factory
265
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
266
+ obj_ = parser_.parse('LINESTRING(1 2, 3 4, 5 6)')
267
+ assert_equal(::RGeo::Features::LineString, obj_.geometry_type)
268
+ assert_equal(3, obj_.num_points)
269
+ assert_equal(1, obj_.point_n(0).x)
270
+ assert_equal(6, obj_.point_n(2).y)
271
+ end
272
+
273
+
274
+ def test_linestring_with_z
275
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
276
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
277
+ obj_ = parser_.parse('LINESTRING(1 2 3, 4 5 6,7 8 9)')
278
+ assert_equal(::RGeo::Features::LineString, obj_.geometry_type)
279
+ assert_equal(3, obj_.num_points)
280
+ assert_equal(1, obj_.point_n(0).x)
281
+ assert_equal(9, obj_.point_n(2).z)
282
+ end
283
+
284
+
285
+ def test_linestring_with_inconsistent_coords
286
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
287
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
288
+ assert_raise(::RGeo::Errors::ParseError) do
289
+ obj_ = parser_.parse('LINESTRING(1 2 3, 4 5,7 8 9)')
290
+ end
291
+ end
292
+
293
+
294
+ def test_linestring_wkt12_m
295
+ factory_ = ::RGeo::Cartesian.simple_factory(:support_z_coordinate => true, :support_m_coordinate => true)
296
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
297
+ obj_ = parser_.parse('LINESTRING M(1 2 3,5 6 7)')
298
+ assert_equal(::RGeo::Features::LineString, obj_.geometry_type)
299
+ assert_equal(2, obj_.num_points)
300
+ assert_equal(0, obj_.point_n(0).z)
301
+ assert_equal(3, obj_.point_n(0).m)
302
+ assert_equal(0, obj_.point_n(1).z)
303
+ assert_equal(7, obj_.point_n(1).m)
304
+ end
305
+
306
+
307
+ def test_linestring_ewkt_with_srid
308
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true)
309
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_ewkt => true)
310
+ parser_.set_factory_from_srid do |srid_|
311
+ ::RGeo::Cartesian.preferred_factory(:support_m_coordinate => true, :srid => srid_)
312
+ end
313
+ obj_ = parser_.parse('SRID=1000;LINESTRINGM(1 2 3, 4 5 6)')
314
+ assert_equal(::RGeo::Features::LineString, obj_.geometry_type)
315
+ assert_equal(3, obj_.point_n(0).m)
316
+ assert_nil(obj_.point_n(0).z)
317
+ assert_equal(1000, obj_.srid)
318
+ end
319
+
320
+
321
+ def test_linestring_empty
322
+ factory_ = ::RGeo::Cartesian.preferred_factory
323
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
324
+ obj_ = parser_.parse('LINESTRING EMPTY')
325
+ assert_equal(::RGeo::Features::LineString, obj_.geometry_type)
326
+ assert_equal(0, obj_.num_points)
327
+ end
328
+
329
+
330
+ def test_polygon_basic
331
+ factory_ = ::RGeo::Cartesian.preferred_factory
332
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
333
+ obj_ = parser_.parse('POLYGON((1 2, 3 4, 5 6, 1 2))')
334
+ assert_equal(::RGeo::Features::Polygon, obj_.geometry_type)
335
+ assert_equal(4, obj_.exterior_ring.num_points)
336
+ assert_equal(1, obj_.exterior_ring.point_n(0).x)
337
+ assert_equal(6, obj_.exterior_ring.point_n(2).y)
338
+ end
339
+
340
+
341
+ def test_polygon_with_holes_and_z
342
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
343
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
344
+ obj_ = parser_.parse('POLYGON((0 0 -1, 10 0 -2, 10 10 -3, 0 10 -4, 0 0 -5),(1 1 -6, 2 3 -7, 3 1 -8, 1 1 -9))')
345
+ assert_equal(::RGeo::Features::Polygon, obj_.geometry_type)
346
+ assert_equal(5, obj_.exterior_ring.num_points)
347
+ assert_equal(0, obj_.exterior_ring.point_n(0).x)
348
+ assert_equal(10, obj_.exterior_ring.point_n(2).y)
349
+ assert_equal(1, obj_.num_interior_rings)
350
+ assert_equal(-6, obj_.interior_ring_n(0).point_n(0).z)
351
+ assert_equal(-7, obj_.interior_ring_n(0).point_n(1).z)
352
+ end
353
+
354
+
355
+ def test_polygon_empty
356
+ factory_ = ::RGeo::Cartesian.preferred_factory
357
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
358
+ obj_ = parser_.parse('POLYGON EMPTY')
359
+ assert_equal(::RGeo::Features::Polygon, obj_.geometry_type)
360
+ assert_equal(0, obj_.exterior_ring.num_points)
361
+ end
362
+
363
+
364
+ def test_multipoint_basic
365
+ factory_ = ::RGeo::Cartesian.preferred_factory
366
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
367
+ obj_ = parser_.parse('MULTIPOINT((1 2),(0 3))')
368
+ assert_equal(::RGeo::Features::MultiPoint, obj_.geometry_type)
369
+ assert_equal(2, obj_.num_geometries)
370
+ assert_equal(1, obj_[0].x)
371
+ assert_equal(3, obj_[1].y)
372
+ end
373
+
374
+
375
+ def test_multipoint_empty
376
+ factory_ = ::RGeo::Cartesian.preferred_factory
377
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
378
+ obj_ = parser_.parse('MULTIPOINT EMPTY')
379
+ assert_equal(::RGeo::Features::MultiPoint, obj_.geometry_type)
380
+ assert_equal(0, obj_.num_geometries)
381
+ end
382
+
383
+
384
+ def test_multilinestring_basic
385
+ factory_ = ::RGeo::Cartesian.preferred_factory
386
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
387
+ obj_ = parser_.parse('MULTILINESTRING((1 2, 3 4, 5 6),(0 -3, 0 -4, 1 -5))')
388
+ assert_equal(::RGeo::Features::MultiLineString, obj_.geometry_type)
389
+ assert_equal(2, obj_.num_geometries)
390
+ assert_equal(1, obj_[0].point_n(0).x)
391
+ assert_equal(-5, obj_[1].point_n(2).y)
392
+ end
393
+
394
+
395
+ def test_multilinestring_empty
396
+ factory_ = ::RGeo::Cartesian.preferred_factory
397
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
398
+ obj_ = parser_.parse('MULTILINESTRING EMPTY')
399
+ assert_equal(::RGeo::Features::MultiLineString, obj_.geometry_type)
400
+ assert_equal(0, obj_.num_geometries)
401
+ end
402
+
403
+
404
+ def test_multipolygon_basic
405
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
406
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
407
+ obj_ = parser_.parse('MULTIPOLYGON(((-1 -2 0, -3 -4 0, -5 -6 0, -1 -2 0)),((0 0 -1, 10 0 -2, 10 10 -3, 0 10 -4, 0 0 -5),(1 1 -6, 2 3 -7, 3 1 -8, 1 1 -9)))')
408
+ assert_equal(::RGeo::Features::MultiPolygon, obj_.geometry_type)
409
+ assert_equal(2, obj_.num_geometries)
410
+ assert_equal(4, obj_[0].exterior_ring.num_points)
411
+ assert_equal(-1, obj_[0].exterior_ring.point_n(0).x)
412
+ assert_equal(-6, obj_[0].exterior_ring.point_n(2).y)
413
+ assert_equal(5, obj_[1].exterior_ring.num_points)
414
+ assert_equal(0, obj_[1].exterior_ring.point_n(0).x)
415
+ assert_equal(10, obj_[1].exterior_ring.point_n(2).y)
416
+ assert_equal(1, obj_[1].num_interior_rings)
417
+ assert_equal(-6, obj_[1].interior_ring_n(0).point_n(0).z)
418
+ assert_equal(-7, obj_[1].interior_ring_n(0).point_n(1).z)
419
+ end
420
+
421
+
422
+ def test_multipolygon_empty
423
+ factory_ = ::RGeo::Cartesian.preferred_factory
424
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
425
+ obj_ = parser_.parse('MULTIPOLYGON EMPTY')
426
+ assert_equal(::RGeo::Features::MultiPolygon, obj_.geometry_type)
427
+ assert_equal(0, obj_.num_geometries)
428
+ end
429
+
430
+
431
+ def test_collection_basic
432
+ factory_ = ::RGeo::Cartesian.preferred_factory
433
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
434
+ obj_ = parser_.parse('GEOMETRYCOLLECTION(POINT(-1 -2),LINESTRING(1 2, 3 4, 5 6))')
435
+ assert_equal(::RGeo::Features::GeometryCollection, obj_.geometry_type)
436
+ assert_equal(2, obj_.num_geometries)
437
+ assert_equal(::RGeo::Features::Point, obj_[0].geometry_type)
438
+ assert_equal(-1, obj_[0].x)
439
+ assert_equal(::RGeo::Features::LineString, obj_[1].geometry_type)
440
+ assert_equal(1, obj_[1].point_n(0).x)
441
+ assert_equal(6, obj_[1].point_n(2).y)
442
+ end
443
+
444
+
445
+ def test_collection_z
446
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
447
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
448
+ obj_ = parser_.parse('GEOMETRYCOLLECTION(POINT(-1 -2 0),LINESTRING(1 2 0, 3 4 0, 5 6 0))')
449
+ assert_equal(::RGeo::Features::GeometryCollection, obj_.geometry_type)
450
+ assert_equal(2, obj_.num_geometries)
451
+ assert_equal(::RGeo::Features::Point, obj_[0].geometry_type)
452
+ assert_equal(-1, obj_[0].x)
453
+ assert_equal(::RGeo::Features::LineString, obj_[1].geometry_type)
454
+ assert_equal(1, obj_[1].point_n(0).x)
455
+ assert_equal(6, obj_[1].point_n(2).y)
456
+ end
457
+
458
+
459
+ def test_collection_dimension_mismatch
460
+ factory_ = ::RGeo::Cartesian.preferred_factory(:support_z_coordinate => true)
461
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
462
+ assert_raise(::RGeo::Errors::ParseError) do
463
+ obj_ = parser_.parse('GEOMETRYCOLLECTION(POINT(-1 -2),LINESTRING(1 2 0, 3 4 0, 5 6 0))')
464
+ end
465
+ end
466
+
467
+
468
+ def test_collection_wkt12_type_mismatch
469
+ factory_ = ::RGeo::Cartesian.simple_factory(:support_z_coordinate => true, :support_m_coordinate => true)
470
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_, :support_wkt12 => true)
471
+ assert_raise(::RGeo::Errors::ParseError) do
472
+ obj_ = parser_.parse('GEOMETRYCOLLECTION Z(POINT Z(-1 -2 0),LINESTRING M(1 2 0, 3 4 0, 5 6 0))')
473
+ end
474
+ end
475
+
476
+
477
+ def test_collection_empty
478
+ factory_ = ::RGeo::Cartesian.preferred_factory
479
+ parser_ = ::RGeo::WKRep::WKTParser.new(:default_factory => factory_)
480
+ obj_ = parser_.parse('GEOMETRYCOLLECTION EMPTY')
481
+ assert_equal(::RGeo::Features::GeometryCollection, obj_.geometry_type)
482
+ assert_equal(0, obj_.num_geometries)
483
+ end
484
+
485
+
486
+ end
487
+
488
+ end
489
+ end
490
+ end