rgeo 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/History.rdoc +22 -0
  2. data/README.rdoc +124 -0
  3. data/Version +1 -0
  4. data/ext/geos_c_impl/extconf.rb +72 -0
  5. data/ext/geos_c_impl/factory.c +468 -0
  6. data/ext/geos_c_impl/factory.h +217 -0
  7. data/ext/geos_c_impl/geometry.c +644 -0
  8. data/ext/geos_c_impl/geometry.h +65 -0
  9. data/ext/geos_c_impl/geometry_collection.c +580 -0
  10. data/ext/geos_c_impl/geometry_collection.h +79 -0
  11. data/ext/geos_c_impl/globals.h +58 -0
  12. data/ext/geos_c_impl/line_string.c +468 -0
  13. data/ext/geos_c_impl/line_string.h +74 -0
  14. data/ext/geos_c_impl/main.c +65 -0
  15. data/ext/geos_c_impl/point.c +201 -0
  16. data/ext/geos_c_impl/point.h +77 -0
  17. data/ext/geos_c_impl/polygon.c +259 -0
  18. data/ext/geos_c_impl/polygon.h +76 -0
  19. data/ext/geos_c_impl/preface.h +42 -0
  20. data/lib/rgeo.rb +68 -0
  21. data/lib/rgeo/errors.rb +59 -0
  22. data/lib/rgeo/features.rb +89 -0
  23. data/lib/rgeo/features/curve.rb +155 -0
  24. data/lib/rgeo/features/factory.rb +191 -0
  25. data/lib/rgeo/features/geometry.rb +560 -0
  26. data/lib/rgeo/features/geometry_collection.rb +118 -0
  27. data/lib/rgeo/features/line.rb +65 -0
  28. data/lib/rgeo/features/line_string.rb +101 -0
  29. data/lib/rgeo/features/linear_ring.rb +65 -0
  30. data/lib/rgeo/features/multi_curve.rb +112 -0
  31. data/lib/rgeo/features/multi_line_string.rb +65 -0
  32. data/lib/rgeo/features/multi_point.rb +72 -0
  33. data/lib/rgeo/features/multi_polygon.rb +96 -0
  34. data/lib/rgeo/features/multi_surface.rb +115 -0
  35. data/lib/rgeo/features/point.rb +97 -0
  36. data/lib/rgeo/features/polygon.rb +141 -0
  37. data/lib/rgeo/features/surface.rb +121 -0
  38. data/lib/rgeo/geo_json.rb +58 -0
  39. data/lib/rgeo/geo_json/coder.rb +305 -0
  40. data/lib/rgeo/geo_json/entities.rb +284 -0
  41. data/lib/rgeo/geo_json/interface.rb +95 -0
  42. data/lib/rgeo/geography.rb +75 -0
  43. data/lib/rgeo/geography/common/geometry_collection_methods.rb +206 -0
  44. data/lib/rgeo/geography/common/geometry_methods.rb +92 -0
  45. data/lib/rgeo/geography/common/helper.rb +102 -0
  46. data/lib/rgeo/geography/common/line_string_methods.rb +187 -0
  47. data/lib/rgeo/geography/common/point_methods.rb +149 -0
  48. data/lib/rgeo/geography/common/polygon_methods.rb +122 -0
  49. data/lib/rgeo/geography/factories.rb +136 -0
  50. data/lib/rgeo/geography/factory.rb +246 -0
  51. data/lib/rgeo/geography/projected_window.rb +467 -0
  52. data/lib/rgeo/geography/simple_mercator/feature_classes.rb +320 -0
  53. data/lib/rgeo/geography/simple_mercator/feature_methods.rb +291 -0
  54. data/lib/rgeo/geography/simple_mercator/projector.rb +116 -0
  55. data/lib/rgeo/geography/simple_spherical/calculations.rb +70 -0
  56. data/lib/rgeo/geography/simple_spherical/geometry_collection_impl.rb +66 -0
  57. data/lib/rgeo/geography/simple_spherical/geometry_methods.rb +59 -0
  58. data/lib/rgeo/geography/simple_spherical/line_string_impl.rb +104 -0
  59. data/lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb +67 -0
  60. data/lib/rgeo/geography/simple_spherical/multi_point_impl.rb +67 -0
  61. data/lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb +67 -0
  62. data/lib/rgeo/geography/simple_spherical/point_impl.rb +85 -0
  63. data/lib/rgeo/geography/simple_spherical/polygon_impl.rb +66 -0
  64. data/lib/rgeo/geos.rb +72 -0
  65. data/lib/rgeo/geos/factory.rb +260 -0
  66. data/lib/rgeo/geos/impl_additions.rb +57 -0
  67. data/lib/rgeo/geos/interface.rb +74 -0
  68. data/lib/rgeo/version.rb +52 -0
  69. data/tests/geos/tc_factory.rb +91 -0
  70. data/tests/geos/tc_geometry_collection.rb +226 -0
  71. data/tests/geos/tc_line_string.rb +310 -0
  72. data/tests/geos/tc_misc.rb +72 -0
  73. data/tests/geos/tc_multi_line_string.rb +211 -0
  74. data/tests/geos/tc_multi_point.rb +202 -0
  75. data/tests/geos/tc_multi_polygon.rb +210 -0
  76. data/tests/geos/tc_point.rb +305 -0
  77. data/tests/geos/tc_polygon.rb +240 -0
  78. data/tests/simple_mercator/tc_point.rb +303 -0
  79. data/tests/simple_mercator/tc_window.rb +219 -0
  80. data/tests/tc_geojson.rb +230 -0
  81. data/tests/tc_oneoff.rb +61 -0
  82. metadata +162 -0
@@ -0,0 +1,310 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the GEOS line string implementation
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 Geos
44
+
45
+ class TestLineString < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def setup
49
+ @factory = ::RGeo::Geos.factory
50
+ end
51
+
52
+
53
+ def test_creation_success
54
+ point1_ = @factory.point(0, 0)
55
+ point2_ = @factory.point(0, 1)
56
+ point3_ = @factory.point(1, 0)
57
+ line1_ = @factory.line_string([point1_, point2_])
58
+ assert_not_nil(line1_)
59
+ assert_kind_of(::RGeo::Geos::LineStringImpl, line1_)
60
+ assert_equal(2, line1_.num_points)
61
+ assert_equal(point1_, line1_.point_n(0))
62
+ assert_equal(point2_, line1_.point_n(1))
63
+ line2_ = @factory.line_string([point1_, point2_, point3_])
64
+ assert_not_nil(line2_)
65
+ assert_kind_of(::RGeo::Geos::LineStringImpl, line2_)
66
+ assert_equal(3, line2_.num_points)
67
+ assert_equal(point1_, line2_.point_n(0))
68
+ assert_equal(point2_, line2_.point_n(1))
69
+ assert_equal(point3_, line2_.point_n(2))
70
+ line3_ = @factory.line_string([point1_, point1_])
71
+ assert_not_nil(line3_)
72
+ assert_kind_of(::RGeo::Geos::LineStringImpl, line3_)
73
+ assert_equal(2, line3_.num_points)
74
+ assert_equal(point1_, line3_.point_n(0))
75
+ assert_equal(point1_, line3_.point_n(1))
76
+ line4_ = @factory.line_string([])
77
+ assert_not_nil(line4_)
78
+ assert_kind_of(::RGeo::Geos::LineStringImpl, line4_)
79
+ assert_equal(0, line4_.num_points)
80
+ end
81
+
82
+
83
+ def test_creation_line_string
84
+ point1_ = @factory.point(0, 0)
85
+ point2_ = @factory.point(0, 1)
86
+ point3_ = @factory.point(1, 1)
87
+ line1_ = @factory.line_string([point1_, point2_, point3_])
88
+ assert_not_nil(line1_)
89
+ assert_kind_of(::RGeo::Geos::LineStringImpl, line1_)
90
+ assert(::RGeo::Features::LineString === line1_)
91
+ assert(!(::RGeo::Features::LinearRing === line1_))
92
+ assert(!(::RGeo::Features::Line === line1_))
93
+ assert_equal(::RGeo::Features::LineString, line1_.geometry_type)
94
+ end
95
+
96
+
97
+ def test_creation_linear_ring
98
+ point1_ = @factory.point(0, 0)
99
+ point2_ = @factory.point(0, 1)
100
+ point3_ = @factory.point(1, 0)
101
+ line1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
102
+ assert_not_nil(line1_)
103
+ assert_kind_of(::RGeo::Geos::LinearRingImpl, line1_)
104
+ assert(line1_.is_ring?)
105
+ assert(::RGeo::Features::LinearRing === line1_)
106
+ assert_equal(::RGeo::Features::LinearRing, line1_.geometry_type)
107
+ line2_ = @factory.linear_ring([point1_, point2_, point3_])
108
+ assert_not_nil(line2_)
109
+ assert_kind_of(::RGeo::Geos::LinearRingImpl, line2_)
110
+ assert(line2_.is_ring?)
111
+ assert(::RGeo::Features::LinearRing === line2_)
112
+ assert_equal(4, line2_.num_points)
113
+ assert_equal(::RGeo::Features::LinearRing, line2_.geometry_type)
114
+ end
115
+
116
+
117
+ def test_creation_line
118
+ point1_ = @factory.point(0, 0)
119
+ point2_ = @factory.point(0, 1)
120
+ line1_ = @factory.line(point1_, point2_)
121
+ assert_not_nil(line1_)
122
+ assert_kind_of(::RGeo::Geos::LineImpl, line1_)
123
+ assert(::RGeo::Features::Line === line1_)
124
+ assert_equal(::RGeo::Features::Line, line1_.geometry_type)
125
+ end
126
+
127
+
128
+ def test_creation_errors
129
+ point1_ = @factory.point(0, 0)
130
+ collection_ = point1_.boundary
131
+ line1_ = @factory.line_string([point1_])
132
+ assert_nil(line1_)
133
+ line2_ = @factory.line_string([point1_, collection_])
134
+ assert_nil(line2_)
135
+ end
136
+
137
+
138
+ def test_fully_equal
139
+ point1_ = @factory.point(0, 0)
140
+ point2_ = @factory.point(0, 1)
141
+ point3_ = @factory.point(1, 0)
142
+ line1_ = @factory.line_string([point1_, point2_, point3_])
143
+ point4_ = @factory.point(0, 0)
144
+ point5_ = @factory.point(0, 1)
145
+ point6_ = @factory.point(1, 0)
146
+ line2_ = @factory.line_string([point4_, point5_, point6_])
147
+ assert(line1_.eql?(line2_))
148
+ assert(line1_.equals?(line2_))
149
+ end
150
+
151
+
152
+ def test_geometrically_equal_but_different_type
153
+ point1_ = @factory.point(0, 0)
154
+ point2_ = @factory.point(0, 1)
155
+ line1_ = @factory.line_string([point1_, point2_])
156
+ point4_ = @factory.point(0, 0)
157
+ point5_ = @factory.point(0, 1)
158
+ line2_ = @factory.line(point4_, point5_)
159
+ assert(!line1_.eql?(line2_))
160
+ assert(line1_.equals?(line2_))
161
+ end
162
+
163
+
164
+ def test_geometrically_equal_but_different_type2
165
+ point1_ = @factory.point(0, 0)
166
+ point2_ = @factory.point(0, 1)
167
+ point3_ = @factory.point(1, 0)
168
+ line1_ = @factory.line_string([point1_, point2_, point3_, point1_])
169
+ point4_ = @factory.point(0, 0)
170
+ point5_ = @factory.point(0, 1)
171
+ point6_ = @factory.point(1, 0)
172
+ line2_ = @factory.linear_ring([point4_, point5_, point6_, point4_])
173
+ assert(!line1_.eql?(line2_))
174
+ assert(line1_.equals?(line2_))
175
+ end
176
+
177
+
178
+ def test_geometrically_equal_but_different_overlap
179
+ point1_ = @factory.point(0, 0)
180
+ point2_ = @factory.point(0, 1)
181
+ point3_ = @factory.point(1, 0)
182
+ line1_ = @factory.line_string([point1_, point2_, point3_])
183
+ point4_ = @factory.point(0, 0)
184
+ point5_ = @factory.point(0, 1)
185
+ point6_ = @factory.point(1, 0)
186
+ line2_ = @factory.line_string([point4_, point5_, point6_, point5_])
187
+ assert(!line1_.eql?(line2_))
188
+ assert(line1_.equals?(line2_))
189
+ end
190
+
191
+
192
+ def test_empty_equal
193
+ line1_ = @factory.line_string([])
194
+ line2_ = @factory.line_string([])
195
+ assert(line1_.eql?(line2_))
196
+ assert(line1_.equals?(line2_))
197
+ end
198
+
199
+
200
+ def test_not_equal
201
+ point1_ = @factory.point(0, 0)
202
+ point2_ = @factory.point(0, 1)
203
+ line1_ = @factory.line_string([point1_, point2_])
204
+ point4_ = @factory.point(0, 0)
205
+ point5_ = @factory.point(0, 1)
206
+ point6_ = @factory.point(1, 0)
207
+ line2_ = @factory.line_string([point4_, point5_, point6_])
208
+ assert(!line1_.eql?(line2_))
209
+ assert(!line1_.equals?(line2_))
210
+ end
211
+
212
+
213
+ def test_wkt_creation
214
+ line1_ = @factory.parse_wkt('LINESTRING(21 22, 11 12)')
215
+ assert_equal(@factory.point(21, 22), line1_.point_n(0))
216
+ assert_equal(@factory.point(11, 12), line1_.point_n(1))
217
+ assert_equal(2, line1_.num_points)
218
+ line2_ = @factory.parse_wkt('LINESTRING(-1 -1, 21 22, 11 12, -1 -1)')
219
+ assert_equal(@factory.point(-1, -1), line2_.point_n(0))
220
+ assert_equal(@factory.point(21, 22), line2_.point_n(1))
221
+ assert_equal(@factory.point(11, 12), line2_.point_n(2))
222
+ assert_equal(@factory.point(-1, -1), line2_.point_n(3))
223
+ assert_equal(4, line2_.num_points)
224
+ end
225
+
226
+
227
+ def test_clone
228
+ point1_ = @factory.point(0, 0)
229
+ point2_ = @factory.point(0, 1)
230
+ line1_ = @factory.line_string([point1_, point2_])
231
+ line2_ = line1_.clone
232
+ assert_equal(line1_, line2_)
233
+ assert_equal(2, line2_.num_points)
234
+ assert_equal(point1_, line2_.point_n(0))
235
+ assert_equal(point2_, line2_.point_n(1))
236
+ end
237
+
238
+
239
+ def test_type_check
240
+ point1_ = @factory.point(0, 0)
241
+ point2_ = @factory.point(0, 1)
242
+ line_ = @factory.line_string([point1_, point2_])
243
+ assert(::RGeo::Features::Geometry.check_type(line_))
244
+ assert(!::RGeo::Features::Point.check_type(line_))
245
+ assert(!::RGeo::Features::GeometryCollection.check_type(line_))
246
+ assert(::RGeo::Features::Curve.check_type(line_))
247
+ assert(::RGeo::Features::LineString.check_type(line_))
248
+ assert(!::RGeo::Features::LinearRing.check_type(line_))
249
+ end
250
+
251
+
252
+ def test_as_text_wkt_round_trip
253
+ point1_ = @factory.point(0, 0)
254
+ point2_ = @factory.point(0, 1)
255
+ line1_ = @factory.line_string([point1_, point2_])
256
+ text_ = line1_.as_text
257
+ line2_ = @factory.parse_wkt(text_)
258
+ assert_equal(line2_, line1_)
259
+ end
260
+
261
+
262
+ def test_as_binary_wkb_round_trip
263
+ point1_ = @factory.point(-42, 0)
264
+ point2_ = @factory.point(0, 193)
265
+ line1_ = @factory.line_string([point1_, point2_])
266
+ binary_ = line1_.as_binary
267
+ line2_ = @factory.parse_wkb(binary_)
268
+ assert_equal(line2_, line1_)
269
+ end
270
+
271
+
272
+ def test_empty_as_text_wkt_round_trip
273
+ line1_ = @factory.line_string([])
274
+ text_ = line1_.as_text
275
+ line2_ = @factory.parse_wkt(text_)
276
+ assert(line2_.is_empty?)
277
+ end
278
+
279
+
280
+ def test_empty_as_binary_wkb_round_trip
281
+ line1_ = @factory.line_string([])
282
+ binary_ = line1_.as_binary
283
+ line2_ = @factory.parse_wkb(binary_)
284
+ assert(line2_.is_empty?)
285
+ end
286
+
287
+
288
+ def test_dimension
289
+ point1_ = @factory.point(-42, 0)
290
+ point2_ = @factory.point(0, 193)
291
+ line1_ = @factory.line_string([point1_, point2_])
292
+ assert_equal(1, line1_.dimension)
293
+ end
294
+
295
+
296
+ def test_is_empty
297
+ point1_ = @factory.point(-42, 0)
298
+ point2_ = @factory.point(0, 193)
299
+ line1_ = @factory.line_string([point1_, point2_])
300
+ assert(!line1_.is_empty?)
301
+ line2_ = @factory.line_string([])
302
+ assert(line2_.is_empty?)
303
+ end
304
+
305
+
306
+ end
307
+
308
+ end
309
+ end
310
+ end
@@ -0,0 +1,72 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for miscellaneous GEOS stuff
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 Geos
44
+
45
+ class TestMisc < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def setup
49
+ @factory = ::RGeo::Geos.factory(:srid => 4326)
50
+ end
51
+
52
+
53
+ def test_uninitialized
54
+ geom_ = ::RGeo::Geos::GeometryImpl.new
55
+ assert_equal(false, geom_.initialized?)
56
+ assert_nil(geom_.geometry_type)
57
+ end
58
+
59
+
60
+ def test_empty_geometries_equal
61
+ geom1_ = @factory.collection([])
62
+ geom2_ = @factory.line_string([])
63
+ assert(!geom1_.eql?(geom2_))
64
+ assert(geom1_.equals?(geom2_))
65
+ end
66
+
67
+
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,211 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Tests for the GEOS multi line string implementation
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 Geos
44
+
45
+ class TestMultiLineString < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ def setup
49
+ @factory = ::RGeo::Geos.factory
50
+ point1_ = @factory.point(0, 0)
51
+ point2_ = @factory.point(1, 0)
52
+ point3_ = @factory.point(-4, 2)
53
+ point4_ = @factory.point(-5, 3)
54
+ point5_ = @factory.point(-3, 5)
55
+ @linestring1 = @factory.line_string([point1_, point2_])
56
+ @linestring2 = @factory.line_string([point3_, point4_, point5_])
57
+ @linearring1 = @factory.linear_ring([point5_, point3_, point4_, point5_])
58
+ @line1 = @factory.line(point1_, point2_)
59
+ end
60
+
61
+
62
+ def test_creation_simple
63
+ geom_ = @factory.multi_line_string([@linestring1, @linestring2])
64
+ assert_not_nil(geom_)
65
+ assert_kind_of(::RGeo::Geos::MultiLineStringImpl, geom_)
66
+ assert(::RGeo::Features::MultiLineString === geom_)
67
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
68
+ assert_equal(2, geom_.num_geometries)
69
+ assert_equal([@linestring1, @linestring2], geom_.to_a)
70
+ end
71
+
72
+
73
+ def test_creation_empty
74
+ geom_ = @factory.multi_line_string([])
75
+ assert_not_nil(geom_)
76
+ assert_kind_of(::RGeo::Geos::MultiLineStringImpl, geom_)
77
+ assert(::RGeo::Features::MultiLineString === geom_)
78
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
79
+ assert_equal(0, geom_.num_geometries)
80
+ assert_equal([], geom_.to_a)
81
+ end
82
+
83
+
84
+ def test_creation_save_types
85
+ geom_ = @factory.multi_line_string([@linestring1, @linearring1, @line1])
86
+ assert_not_nil(geom_)
87
+ assert_kind_of(::RGeo::Geos::MultiLineStringImpl, geom_)
88
+ assert(::RGeo::Features::MultiLineString === geom_)
89
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
90
+ assert_equal(3, geom_.num_geometries)
91
+ assert(geom_[1].eql?(@linearring1))
92
+ assert(geom_[2].eql?(@line1))
93
+ end
94
+
95
+
96
+ def test_creation_compound
97
+ mls1_ = @factory.multi_line_string([@linestring1, @linestring2])
98
+ mls2_ = @factory.collection([@line1])
99
+ mls3_ = @factory.collection([mls1_])
100
+ geom_ = @factory.multi_line_string([mls3_, mls2_, @linearring1])
101
+ assert_not_nil(geom_)
102
+ assert_kind_of(::RGeo::Geos::MultiLineStringImpl, geom_)
103
+ assert(::RGeo::Features::MultiLineString === geom_)
104
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
105
+ assert_equal(4, geom_.num_geometries)
106
+ assert(geom_.to_a.eql?([@linestring1, @linestring2, @line1, @linearring1]))
107
+ end
108
+
109
+
110
+ def test_fully_equal
111
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
112
+ geom2_ = @factory.multi_line_string([@linestring1, @linestring2])
113
+ assert(geom1_.eql?(geom2_))
114
+ assert(geom1_.equals?(geom2_))
115
+ end
116
+
117
+
118
+ def test_geometrically_equal
119
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2, @linearring1])
120
+ geom2_ = @factory.multi_line_string([@line1, @linearring1])
121
+ assert(!geom1_.eql?(geom2_))
122
+ assert(geom1_.equals?(geom2_))
123
+ end
124
+
125
+
126
+ def test_not_equal
127
+ geom1_ = @factory.multi_line_string([@linestring2])
128
+ geom2_ = @factory.multi_line_string([@linearring1])
129
+ assert(!geom1_.eql?(geom2_))
130
+ assert(!geom1_.equals?(geom2_))
131
+ end
132
+
133
+
134
+ def test_wkt_creation_simple
135
+ parsed_geom_ = @factory.parse_wkt('MULTILINESTRING((0 0, 1 0), (-4 2, -5 3, -3 5))')
136
+ built_geom_ = @factory.multi_line_string([@linestring1, @linestring2])
137
+ assert_equal(built_geom_, parsed_geom_)
138
+ end
139
+
140
+
141
+ def test_wkt_creation_empty
142
+ parsed_geom_ = @factory.parse_wkt('MULTILINESTRING EMPTY')
143
+ assert_equal(::RGeo::Features::MultiLineString, parsed_geom_.geometry_type)
144
+ assert_equal(0, parsed_geom_.num_geometries)
145
+ assert_equal([], parsed_geom_.to_a)
146
+ end
147
+
148
+
149
+ def test_clone
150
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
151
+ geom2_ = geom1_.clone
152
+ assert_equal(geom1_, geom2_)
153
+ assert_equal(::RGeo::Features::MultiLineString, geom2_.geometry_type)
154
+ assert_equal(2, geom2_.num_geometries)
155
+ assert_equal([@linestring1, @linestring2], geom2_.to_a)
156
+ end
157
+
158
+
159
+ def test_type_check
160
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
161
+ assert(::RGeo::Features::Geometry.check_type(geom1_))
162
+ assert(!::RGeo::Features::LineString.check_type(geom1_))
163
+ assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
164
+ assert(!::RGeo::Features::MultiPoint.check_type(geom1_))
165
+ assert(::RGeo::Features::MultiLineString.check_type(geom1_))
166
+ geom2_ = @factory.multi_line_string([])
167
+ assert(::RGeo::Features::Geometry.check_type(geom2_))
168
+ assert(!::RGeo::Features::LineString.check_type(geom2_))
169
+ assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
170
+ assert(!::RGeo::Features::MultiPoint.check_type(geom2_))
171
+ assert(::RGeo::Features::MultiLineString.check_type(geom2_))
172
+ end
173
+
174
+
175
+ def test_as_text_wkt_round_trip
176
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
177
+ text_ = geom1_.as_text
178
+ geom2_ = @factory.parse_wkt(text_)
179
+ assert_equal(geom1_, geom2_)
180
+ end
181
+
182
+
183
+ def test_as_binary_wkb_round_trip
184
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
185
+ binary_ = geom1_.as_binary
186
+ geom2_ = @factory.parse_wkb(binary_)
187
+ assert_equal(geom1_, geom2_)
188
+ end
189
+
190
+
191
+ def test_dimension
192
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
193
+ assert_equal(1, geom1_.dimension)
194
+ geom2_ = @factory.multi_line_string([])
195
+ assert_equal(-1, geom2_.dimension)
196
+ end
197
+
198
+
199
+ def test_is_empty
200
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
201
+ assert(!geom1_.is_empty?)
202
+ geom2_ = @factory.multi_line_string([])
203
+ assert(geom2_.is_empty?)
204
+ end
205
+
206
+
207
+ end
208
+
209
+ end
210
+ end
211
+ end