schleyfox-rgeo 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/History.rdoc +199 -0
  2. data/README.rdoc +172 -0
  3. data/Spatial_Programming_With_RGeo.rdoc +440 -0
  4. data/Version +1 -0
  5. data/ext/geos_c_impl/extconf.rb +84 -0
  6. data/ext/geos_c_impl/factory.c +468 -0
  7. data/ext/geos_c_impl/factory.h +224 -0
  8. data/ext/geos_c_impl/geometry.c +705 -0
  9. data/ext/geos_c_impl/geometry.h +55 -0
  10. data/ext/geos_c_impl/geometry_collection.c +482 -0
  11. data/ext/geos_c_impl/geometry_collection.h +69 -0
  12. data/ext/geos_c_impl/line_string.c +509 -0
  13. data/ext/geos_c_impl/line_string.h +64 -0
  14. data/ext/geos_c_impl/main.c +70 -0
  15. data/ext/geos_c_impl/point.c +193 -0
  16. data/ext/geos_c_impl/point.h +62 -0
  17. data/ext/geos_c_impl/polygon.c +265 -0
  18. data/ext/geos_c_impl/polygon.h +66 -0
  19. data/ext/geos_c_impl/preface.h +50 -0
  20. data/ext/proj4_c_impl/extconf.rb +88 -0
  21. data/ext/proj4_c_impl/main.c +271 -0
  22. data/lib/rgeo.rb +124 -0
  23. data/lib/rgeo/cartesian.rb +60 -0
  24. data/lib/rgeo/cartesian/analysis.rb +118 -0
  25. data/lib/rgeo/cartesian/bounding_box.rb +337 -0
  26. data/lib/rgeo/cartesian/calculations.rb +161 -0
  27. data/lib/rgeo/cartesian/factory.rb +209 -0
  28. data/lib/rgeo/cartesian/feature_classes.rb +173 -0
  29. data/lib/rgeo/cartesian/feature_methods.rb +106 -0
  30. data/lib/rgeo/cartesian/interface.rb +150 -0
  31. data/lib/rgeo/coord_sys.rb +79 -0
  32. data/lib/rgeo/coord_sys/cs/entities.rb +1524 -0
  33. data/lib/rgeo/coord_sys/cs/factories.rb +208 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +308 -0
  35. data/lib/rgeo/coord_sys/proj4.rb +312 -0
  36. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +194 -0
  37. data/lib/rgeo/coord_sys/srs_database/interface.rb +165 -0
  38. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +188 -0
  39. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +108 -0
  40. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +108 -0
  41. data/lib/rgeo/error.rb +63 -0
  42. data/lib/rgeo/feature.rb +88 -0
  43. data/lib/rgeo/feature/curve.rb +156 -0
  44. data/lib/rgeo/feature/factory.rb +332 -0
  45. data/lib/rgeo/feature/factory_generator.rb +138 -0
  46. data/lib/rgeo/feature/geometry.rb +614 -0
  47. data/lib/rgeo/feature/geometry_collection.rb +129 -0
  48. data/lib/rgeo/feature/line.rb +66 -0
  49. data/lib/rgeo/feature/line_string.rb +102 -0
  50. data/lib/rgeo/feature/linear_ring.rb +66 -0
  51. data/lib/rgeo/feature/multi_curve.rb +113 -0
  52. data/lib/rgeo/feature/multi_line_string.rb +66 -0
  53. data/lib/rgeo/feature/multi_point.rb +73 -0
  54. data/lib/rgeo/feature/multi_polygon.rb +97 -0
  55. data/lib/rgeo/feature/multi_surface.rb +116 -0
  56. data/lib/rgeo/feature/point.rb +120 -0
  57. data/lib/rgeo/feature/polygon.rb +141 -0
  58. data/lib/rgeo/feature/surface.rb +122 -0
  59. data/lib/rgeo/feature/types.rb +305 -0
  60. data/lib/rgeo/geographic.rb +75 -0
  61. data/lib/rgeo/geographic/factory.rb +287 -0
  62. data/lib/rgeo/geographic/interface.rb +410 -0
  63. data/lib/rgeo/geographic/proj4_projector.rb +98 -0
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +213 -0
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +228 -0
  66. data/lib/rgeo/geographic/projected_window.rb +467 -0
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +157 -0
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +212 -0
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +97 -0
  70. data/lib/rgeo/geographic/spherical_math.rb +206 -0
  71. data/lib/rgeo/geos.rb +72 -0
  72. data/lib/rgeo/geos/factory.rb +301 -0
  73. data/lib/rgeo/geos/impl_additions.rb +76 -0
  74. data/lib/rgeo/geos/interface.rb +139 -0
  75. data/lib/rgeo/geos/zm_factory.rb +275 -0
  76. data/lib/rgeo/geos/zm_impl.rb +432 -0
  77. data/lib/rgeo/impl_helper.rb +53 -0
  78. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +235 -0
  79. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +85 -0
  80. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +197 -0
  81. data/lib/rgeo/impl_helper/basic_point_methods.rb +138 -0
  82. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +121 -0
  83. data/lib/rgeo/impl_helper/math.rb +50 -0
  84. data/lib/rgeo/version.rb +52 -0
  85. data/lib/rgeo/wkrep.rb +72 -0
  86. data/lib/rgeo/wkrep/wkb_generator.rb +267 -0
  87. data/lib/rgeo/wkrep/wkb_parser.rb +315 -0
  88. data/lib/rgeo/wkrep/wkt_generator.rb +275 -0
  89. data/lib/rgeo/wkrep/wkt_parser.rb +496 -0
  90. data/test/common/geometry_collection_tests.rb +238 -0
  91. data/test/common/line_string_tests.rb +324 -0
  92. data/test/common/multi_line_string_tests.rb +209 -0
  93. data/test/common/multi_point_tests.rb +201 -0
  94. data/test/common/multi_polygon_tests.rb +208 -0
  95. data/test/common/point_tests.rb +331 -0
  96. data/test/common/polygon_tests.rb +232 -0
  97. data/test/coord_sys/tc_active_record_table.rb +102 -0
  98. data/test/coord_sys/tc_ogc_cs.rb +356 -0
  99. data/test/coord_sys/tc_proj4.rb +138 -0
  100. data/test/coord_sys/tc_proj4_srs_data.rb +76 -0
  101. data/test/coord_sys/tc_sr_org.rb +70 -0
  102. data/test/coord_sys/tc_url_reader.rb +82 -0
  103. data/test/geos/tc_factory.rb +91 -0
  104. data/test/geos/tc_geometry_collection.rb +62 -0
  105. data/test/geos/tc_line_string.rb +62 -0
  106. data/test/geos/tc_misc.rb +72 -0
  107. data/test/geos/tc_multi_line_string.rb +62 -0
  108. data/test/geos/tc_multi_point.rb +62 -0
  109. data/test/geos/tc_multi_polygon.rb +63 -0
  110. data/test/geos/tc_point.rb +86 -0
  111. data/test/geos/tc_polygon.rb +86 -0
  112. data/test/geos/tc_zmfactory.rb +85 -0
  113. data/test/projected_geographic/tc_geometry_collection.rb +62 -0
  114. data/test/projected_geographic/tc_line_string.rb +62 -0
  115. data/test/projected_geographic/tc_multi_line_string.rb +62 -0
  116. data/test/projected_geographic/tc_multi_point.rb +62 -0
  117. data/test/projected_geographic/tc_multi_polygon.rb +63 -0
  118. data/test/projected_geographic/tc_point.rb +93 -0
  119. data/test/projected_geographic/tc_polygon.rb +62 -0
  120. data/test/simple_cartesian/tc_calculations.rb +145 -0
  121. data/test/simple_cartesian/tc_geometry_collection.rb +69 -0
  122. data/test/simple_cartesian/tc_line_string.rb +70 -0
  123. data/test/simple_cartesian/tc_multi_line_string.rb +67 -0
  124. data/test/simple_cartesian/tc_multi_point.rb +67 -0
  125. data/test/simple_cartesian/tc_multi_polygon.rb +70 -0
  126. data/test/simple_cartesian/tc_point.rb +91 -0
  127. data/test/simple_cartesian/tc_polygon.rb +67 -0
  128. data/test/simple_mercator/tc_geometry_collection.rb +62 -0
  129. data/test/simple_mercator/tc_line_string.rb +62 -0
  130. data/test/simple_mercator/tc_multi_line_string.rb +62 -0
  131. data/test/simple_mercator/tc_multi_point.rb +62 -0
  132. data/test/simple_mercator/tc_multi_polygon.rb +63 -0
  133. data/test/simple_mercator/tc_point.rb +93 -0
  134. data/test/simple_mercator/tc_polygon.rb +62 -0
  135. data/test/simple_mercator/tc_window.rb +219 -0
  136. data/test/spherical_geographic/tc_calculations.rb +203 -0
  137. data/test/spherical_geographic/tc_geometry_collection.rb +70 -0
  138. data/test/spherical_geographic/tc_line_string.rb +70 -0
  139. data/test/spherical_geographic/tc_multi_line_string.rb +67 -0
  140. data/test/spherical_geographic/tc_multi_point.rb +67 -0
  141. data/test/spherical_geographic/tc_multi_polygon.rb +70 -0
  142. data/test/spherical_geographic/tc_point.rb +100 -0
  143. data/test/spherical_geographic/tc_polygon.rb +67 -0
  144. data/test/tc_cartesian_analysis.rb +107 -0
  145. data/test/tc_oneoff.rb +63 -0
  146. data/test/wkrep/tc_wkb_generator.rb +249 -0
  147. data/test/wkrep/tc_wkb_parser.rb +353 -0
  148. data/test/wkrep/tc_wkt_generator.rb +362 -0
  149. data/test/wkrep/tc_wkt_parser.rb +480 -0
  150. metadata +267 -0
@@ -0,0 +1,238 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for geometry collection implementations
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 'rgeo'
38
+
39
+
40
+ module RGeo
41
+ module Tests # :nodoc:
42
+ module Common # :nodoc:
43
+
44
+ module GeometryCollectionTests # :nodoc:
45
+
46
+
47
+ def setup
48
+ @factory = create_factory
49
+ @point1 = @factory.point(0, 0)
50
+ @point2 = @factory.point(1, 0)
51
+ @point3 = @factory.point(-4, 2)
52
+ @point4 = @factory.point(-5, 3)
53
+ @line1 = @factory.line_string([@point3, @point4])
54
+ @line2 = @factory.line_string([@point3, @point4, @point1])
55
+ @line3 = @factory.line(@point3, @point4)
56
+ end
57
+
58
+
59
+ def test_creation_simple
60
+ geom_ = @factory.collection([@point1, @line1])
61
+ assert_not_nil(geom_)
62
+ assert(::RGeo::Feature::GeometryCollection === geom_)
63
+ assert_equal(::RGeo::Feature::GeometryCollection, geom_.geometry_type)
64
+ assert_equal(2, geom_.num_geometries)
65
+ assert(@point1.eql?(geom_[0]))
66
+ assert(@line1.eql?(geom_[1]))
67
+ end
68
+
69
+
70
+ def test_creation_empty
71
+ geom_ = @factory.collection([])
72
+ assert_not_nil(geom_)
73
+ assert(::RGeo::Feature::GeometryCollection === geom_)
74
+ assert_equal(::RGeo::Feature::GeometryCollection, geom_.geometry_type)
75
+ assert_equal(0, geom_.num_geometries)
76
+ assert_equal([], geom_.to_a)
77
+ end
78
+
79
+
80
+ def test_creation_save_klass
81
+ geom_ = @factory.collection([@point1, @line3])
82
+ assert_not_nil(geom_)
83
+ assert(::RGeo::Feature::GeometryCollection === geom_)
84
+ assert_equal(::RGeo::Feature::GeometryCollection, geom_.geometry_type)
85
+ assert_equal(2, geom_.num_geometries)
86
+ assert(geom_[1].eql?(@line3))
87
+ end
88
+
89
+
90
+ def test_creation_compound
91
+ geom1_ = @factory.collection([@point1, @line1])
92
+ geom2_ = @factory.collection([@point2, geom1_])
93
+ assert_not_nil(geom2_)
94
+ assert(::RGeo::Feature::GeometryCollection === geom2_)
95
+ assert_equal(::RGeo::Feature::GeometryCollection, geom2_.geometry_type)
96
+ assert_equal(2, geom2_.num_geometries)
97
+ assert(geom2_[1].eql?(geom1_))
98
+ end
99
+
100
+
101
+ def test_creation_compound_save_klass
102
+ geom1_ = @factory.collection([@point1, @line3])
103
+ geom2_ = @factory.collection([@point2, geom1_])
104
+ ::GC.start
105
+ assert_not_nil(geom2_)
106
+ assert(::RGeo::Feature::GeometryCollection === geom2_)
107
+ assert_equal(::RGeo::Feature::GeometryCollection, geom2_.geometry_type)
108
+ assert_equal(2, geom2_.num_geometries)
109
+ assert_equal(::RGeo::Feature::Line, geom2_[1][1].geometry_type)
110
+ end
111
+
112
+
113
+ def test_fully_equal
114
+ geom1_ = @factory.collection([@point1, @line1])
115
+ geom2_ = @factory.collection([@point1, @line1])
116
+ assert(geom1_.eql?(geom2_))
117
+ assert(geom1_.equals?(geom2_))
118
+ end
119
+
120
+
121
+ def test_geometrically_equal
122
+ geom1_ = @factory.collection([@point2, @line2])
123
+ geom2_ = @factory.collection([@point2, @line1, @line2])
124
+ assert(!geom1_.eql?(geom2_))
125
+ assert(geom1_.equals?(geom2_))
126
+ end
127
+
128
+
129
+ def test_empty_equal
130
+ geom1_ = @factory.collection([])
131
+ geom2_ = @factory.collection([])
132
+ assert(geom1_.eql?(geom2_))
133
+ assert(geom1_.equals?(geom2_))
134
+ end
135
+
136
+
137
+ def test_not_equal
138
+ geom1_ = @factory.collection([@point1, @line1])
139
+ geom2_ = @factory.collection([@point2, @line1])
140
+ assert(!geom1_.eql?(geom2_))
141
+ assert(!geom1_.equals?(geom2_))
142
+ end
143
+
144
+
145
+ def test_wkt_creation_simple
146
+ parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(-4 2, -5 3))')
147
+ built_geom_ = @factory.collection([@point1, @line1])
148
+ assert(built_geom_.eql?(parsed_geom_))
149
+ end
150
+
151
+
152
+ def test_wkt_creation_empty
153
+ parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION EMPTY')
154
+ assert_equal(0, parsed_geom_.num_geometries)
155
+ assert_equal([], parsed_geom_.to_a)
156
+ end
157
+
158
+
159
+ def test_clone
160
+ geom1_ = @factory.collection([@point1, @line1])
161
+ geom2_ = geom1_.clone
162
+ assert(geom1_.eql?(geom2_))
163
+ assert_equal(::RGeo::Feature::GeometryCollection, geom2_.geometry_type)
164
+ assert_equal(2, geom2_.num_geometries)
165
+ assert(@point1.eql?(geom2_[0]))
166
+ assert(@line1.eql?(geom2_[1]))
167
+ end
168
+
169
+
170
+ def test_type_check
171
+ geom1_ = @factory.collection([@point1, @line1])
172
+ assert(::RGeo::Feature::Geometry.check_type(geom1_))
173
+ assert(!::RGeo::Feature::Point.check_type(geom1_))
174
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom1_))
175
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom1_))
176
+ geom2_ = @factory.collection([@point1, @point2])
177
+ assert(::RGeo::Feature::Geometry.check_type(geom2_))
178
+ assert(!::RGeo::Feature::Point.check_type(geom2_))
179
+ assert(::RGeo::Feature::GeometryCollection.check_type(geom2_))
180
+ assert(!::RGeo::Feature::MultiPoint.check_type(geom2_))
181
+ end
182
+
183
+
184
+ def test_as_text_wkt_round_trip
185
+ geom1_ = @factory.collection([@point1, @line1])
186
+ text_ = geom1_.as_text
187
+ geom2_ = @factory.parse_wkt(text_)
188
+ assert(geom1_.eql?(geom2_))
189
+ end
190
+
191
+
192
+ def test_as_binary_wkb_round_trip
193
+ geom1_ = @factory.collection([@point1, @line1])
194
+ binary_ = geom1_.as_binary
195
+ geom2_ = @factory.parse_wkb(binary_)
196
+ assert(geom1_.eql?(geom2_))
197
+ end
198
+
199
+
200
+ def test_dimension
201
+ geom1_ = @factory.collection([@point1, @line1])
202
+ assert_equal(1, geom1_.dimension)
203
+ geom2_ = @factory.collection([@point1, @point2])
204
+ assert_equal(0, geom2_.dimension)
205
+ geom3_ = @factory.collection([])
206
+ assert_equal(-1, geom3_.dimension)
207
+ end
208
+
209
+
210
+ def test_is_empty
211
+ geom1_ = @factory.collection([@point1, @line1])
212
+ assert(!geom1_.is_empty?)
213
+ geom2_ = @factory.collection([])
214
+ assert(geom2_.is_empty?)
215
+ end
216
+
217
+
218
+ def test_empty_collection_envelope
219
+ empty_ = @factory.collection([])
220
+ envelope_ = empty_.envelope
221
+ assert_equal(Feature::GeometryCollection, envelope_.geometry_type)
222
+ assert_equal(0, envelope_.num_geometries)
223
+ end
224
+
225
+
226
+ def test_empty_collection_boundary
227
+ empty_ = @factory.collection([])
228
+ boundary_ = empty_.boundary
229
+ assert_equal(Feature::GeometryCollection, boundary_.geometry_type)
230
+ assert_equal(0, boundary_.num_geometries)
231
+ end
232
+
233
+
234
+ end
235
+
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,324 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for line string implementations
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 'rgeo'
38
+
39
+
40
+ module RGeo
41
+ module Tests # :nodoc:
42
+ module Common # :nodoc:
43
+
44
+ module LineStringTests # :nodoc:
45
+
46
+
47
+ def test_creation_points2
48
+ point1_ = @factory.point(0, 0)
49
+ point2_ = @factory.point(0, 1)
50
+ line1_ = @factory.line_string([point1_, point2_])
51
+ assert_not_nil(line1_)
52
+ assert_equal(::RGeo::Feature::LineString, line1_.geometry_type)
53
+ assert_equal(2, line1_.num_points)
54
+ assert_equal(point1_, line1_.point_n(0))
55
+ assert_equal(point2_, line1_.point_n(1))
56
+ assert_equal(point1_, line1_.start_point)
57
+ assert_equal(point2_, line1_.end_point)
58
+ end
59
+
60
+
61
+ def test_creation_points3
62
+ point1_ = @factory.point(0, 0)
63
+ point2_ = @factory.point(0, 1)
64
+ point3_ = @factory.point(1, 0)
65
+ line2_ = @factory.line_string([point1_, point2_, point3_])
66
+ assert_not_nil(line2_)
67
+ assert_equal(::RGeo::Feature::LineString, line2_.geometry_type)
68
+ assert_equal(3, line2_.num_points)
69
+ assert_equal(point1_, line2_.point_n(0))
70
+ assert_equal(point2_, line2_.point_n(1))
71
+ assert_equal(point3_, line2_.point_n(2))
72
+ assert_nil(line2_.point_n(3))
73
+ assert_equal(point1_, line2_.start_point)
74
+ assert_equal(point3_, line2_.end_point)
75
+ end
76
+
77
+
78
+ def test_creation_points2_degenerate
79
+ point1_ = @factory.point(0, 0)
80
+ line3_ = @factory.line_string([point1_, point1_])
81
+ assert_not_nil(line3_)
82
+ assert_equal(::RGeo::Feature::LineString, line3_.geometry_type)
83
+ assert_equal(2, line3_.num_points)
84
+ assert_equal(point1_, line3_.point_n(0))
85
+ assert_equal(point1_, line3_.point_n(1))
86
+ assert_equal(point1_, line3_.start_point)
87
+ assert_equal(point1_, line3_.end_point)
88
+ end
89
+
90
+
91
+ def test_creation_points_empty
92
+ line4_ = @factory.line_string([])
93
+ assert_not_nil(line4_)
94
+ assert_equal(::RGeo::Feature::LineString, line4_.geometry_type)
95
+ assert_equal(0, line4_.num_points)
96
+ assert_nil(line4_.start_point)
97
+ assert_nil(line4_.end_point)
98
+ end
99
+
100
+
101
+ def test_creation_line_string
102
+ point1_ = @factory.point(0, 0)
103
+ point2_ = @factory.point(0, 1)
104
+ point3_ = @factory.point(1, 1)
105
+ line1_ = @factory.line_string([point1_, point2_, point3_])
106
+ assert_not_nil(line1_)
107
+ assert(::RGeo::Feature::LineString === line1_)
108
+ assert(!(::RGeo::Feature::LinearRing === line1_))
109
+ assert(!(::RGeo::Feature::Line === line1_))
110
+ assert_equal(::RGeo::Feature::LineString, line1_.geometry_type)
111
+ end
112
+
113
+
114
+ def test_creation_linear_ring
115
+ point1_ = @factory.point(0, 0)
116
+ point2_ = @factory.point(0, 1)
117
+ point3_ = @factory.point(1, 0)
118
+ line1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
119
+ assert_not_nil(line1_)
120
+ assert(line1_.is_ring?)
121
+ assert(::RGeo::Feature::LinearRing === line1_)
122
+ assert_equal(::RGeo::Feature::LinearRing, line1_.geometry_type)
123
+ line2_ = @factory.linear_ring([point1_, point2_, point3_])
124
+ assert_not_nil(line2_)
125
+ assert(line2_.is_ring?)
126
+ assert(::RGeo::Feature::LinearRing === line2_)
127
+ assert_equal(4, line2_.num_points)
128
+ assert_equal(::RGeo::Feature::LinearRing, line2_.geometry_type)
129
+ end
130
+
131
+
132
+ def test_creation_line
133
+ point1_ = @factory.point(0, 0)
134
+ point2_ = @factory.point(0, 1)
135
+ line1_ = @factory.line(point1_, point2_)
136
+ assert_not_nil(line1_)
137
+ assert(::RGeo::Feature::Line === line1_)
138
+ assert_equal(::RGeo::Feature::Line, line1_.geometry_type)
139
+ end
140
+
141
+
142
+ def test_creation_errors
143
+ point1_ = @factory.point(0, 0)
144
+ collection_ = point1_.boundary
145
+ line1_ = @factory.line_string([point1_])
146
+ assert_nil(line1_)
147
+ line2_ = @factory.line_string([point1_, collection_])
148
+ assert_nil(line2_)
149
+ end
150
+
151
+
152
+ def test_fully_equal
153
+ point1_ = @factory.point(0, 0)
154
+ point2_ = @factory.point(0, 1)
155
+ point3_ = @factory.point(1, 0)
156
+ line1_ = @factory.line_string([point1_, point2_, point3_])
157
+ point4_ = @factory.point(0, 0)
158
+ point5_ = @factory.point(0, 1)
159
+ point6_ = @factory.point(1, 0)
160
+ line2_ = @factory.line_string([point4_, point5_, point6_])
161
+ assert(line1_.eql?(line2_))
162
+ assert(line1_.equals?(line2_))
163
+ end
164
+
165
+
166
+ def test_geometrically_equal_but_different_type
167
+ point1_ = @factory.point(0, 0)
168
+ point2_ = @factory.point(0, 1)
169
+ line1_ = @factory.line_string([point1_, point2_])
170
+ point4_ = @factory.point(0, 0)
171
+ point5_ = @factory.point(0, 1)
172
+ line2_ = @factory.line(point4_, point5_)
173
+ assert(!line1_.eql?(line2_))
174
+ assert(line1_.equals?(line2_))
175
+ end
176
+
177
+
178
+ def test_geometrically_equal_but_different_type2
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_, point1_])
183
+ point4_ = @factory.point(0, 0)
184
+ point5_ = @factory.point(0, 1)
185
+ point6_ = @factory.point(1, 0)
186
+ line2_ = @factory.linear_ring([point4_, point5_, point6_, point4_])
187
+ assert(!line1_.eql?(line2_))
188
+ assert(line1_.equals?(line2_))
189
+ end
190
+
191
+
192
+ def test_geometrically_equal_but_different_overlap
193
+ point1_ = @factory.point(0, 0)
194
+ point2_ = @factory.point(0, 1)
195
+ point3_ = @factory.point(1, 0)
196
+ line1_ = @factory.line_string([point1_, point2_, point3_])
197
+ point4_ = @factory.point(0, 0)
198
+ point5_ = @factory.point(0, 1)
199
+ point6_ = @factory.point(1, 0)
200
+ line2_ = @factory.line_string([point4_, point5_, point6_, point5_])
201
+ assert(!line1_.eql?(line2_))
202
+ assert(line1_.equals?(line2_))
203
+ end
204
+
205
+
206
+ def test_empty_equal
207
+ line1_ = @factory.line_string([])
208
+ line2_ = @factory.line_string([])
209
+ assert(line1_.eql?(line2_))
210
+ assert(line1_.equals?(line2_))
211
+ end
212
+
213
+
214
+ def test_not_equal
215
+ point1_ = @factory.point(0, 0)
216
+ point2_ = @factory.point(0, 1)
217
+ line1_ = @factory.line_string([point1_, point2_])
218
+ point4_ = @factory.point(0, 0)
219
+ point5_ = @factory.point(0, 1)
220
+ point6_ = @factory.point(1, 0)
221
+ line2_ = @factory.line_string([point4_, point5_, point6_])
222
+ assert(!line1_.eql?(line2_))
223
+ assert(!line1_.equals?(line2_))
224
+ end
225
+
226
+
227
+ def test_wkt_creation
228
+ line1_ = @factory.parse_wkt('LINESTRING(21 22, 11 12)')
229
+ assert_equal(@factory.point(21, 22), line1_.point_n(0))
230
+ assert_equal(@factory.point(11, 12), line1_.point_n(1))
231
+ assert_equal(2, line1_.num_points)
232
+ line2_ = @factory.parse_wkt('LINESTRING(-1 -1, 21 22, 11 12, -1 -1)')
233
+ assert_equal(@factory.point(-1, -1), line2_.point_n(0))
234
+ assert_equal(@factory.point(21, 22), line2_.point_n(1))
235
+ assert_equal(@factory.point(11, 12), line2_.point_n(2))
236
+ assert_equal(@factory.point(-1, -1), line2_.point_n(3))
237
+ assert_equal(4, line2_.num_points)
238
+ end
239
+
240
+
241
+ def test_clone
242
+ point1_ = @factory.point(0, 0)
243
+ point2_ = @factory.point(0, 1)
244
+ line1_ = @factory.line_string([point1_, point2_])
245
+ line2_ = line1_.clone
246
+ assert(line1_.eql?(line2_))
247
+ assert_equal(2, line2_.num_points)
248
+ assert(point1_.eql?(line2_.point_n(0)))
249
+ assert(point2_.eql?(line2_.point_n(1)))
250
+ end
251
+
252
+
253
+ def test_type_check
254
+ point1_ = @factory.point(0, 0)
255
+ point2_ = @factory.point(0, 1)
256
+ line_ = @factory.line_string([point1_, point2_])
257
+ assert(::RGeo::Feature::Geometry.check_type(line_))
258
+ assert(!::RGeo::Feature::Point.check_type(line_))
259
+ assert(!::RGeo::Feature::GeometryCollection.check_type(line_))
260
+ assert(::RGeo::Feature::Curve.check_type(line_))
261
+ assert(::RGeo::Feature::LineString.check_type(line_))
262
+ assert(!::RGeo::Feature::LinearRing.check_type(line_))
263
+ end
264
+
265
+
266
+ def test_as_text_wkt_round_trip
267
+ point1_ = @factory.point(0, 0)
268
+ point2_ = @factory.point(0, 1)
269
+ line1_ = @factory.line_string([point1_, point2_])
270
+ text_ = line1_.as_text
271
+ line2_ = @factory.parse_wkt(text_)
272
+ assert(line2_.eql?(line1_))
273
+ end
274
+
275
+
276
+ def test_as_binary_wkb_round_trip
277
+ point1_ = @factory.point(-42, 0)
278
+ point2_ = @factory.point(0, 193)
279
+ line1_ = @factory.line_string([point1_, point2_])
280
+ binary_ = line1_.as_binary
281
+ line2_ = @factory.parse_wkb(binary_)
282
+ assert(line2_.eql?(line1_))
283
+ end
284
+
285
+
286
+ def test_empty_as_text_wkt_round_trip
287
+ line1_ = @factory.line_string([])
288
+ text_ = line1_.as_text
289
+ line2_ = @factory.parse_wkt(text_)
290
+ assert(line2_.is_empty?)
291
+ end
292
+
293
+
294
+ def test_empty_as_binary_wkb_round_trip
295
+ line1_ = @factory.line_string([])
296
+ binary_ = line1_.as_binary
297
+ line2_ = @factory.parse_wkb(binary_)
298
+ assert(line2_.is_empty?)
299
+ end
300
+
301
+
302
+ def test_dimension
303
+ point1_ = @factory.point(-42, 0)
304
+ point2_ = @factory.point(0, 193)
305
+ line1_ = @factory.line_string([point1_, point2_])
306
+ assert_equal(1, line1_.dimension)
307
+ end
308
+
309
+
310
+ def test_is_empty
311
+ point1_ = @factory.point(-42, 0)
312
+ point2_ = @factory.point(0, 193)
313
+ line1_ = @factory.line_string([point1_, point2_])
314
+ assert(!line1_.is_empty?)
315
+ line2_ = @factory.line_string([])
316
+ assert(line2_.is_empty?)
317
+ end
318
+
319
+
320
+ end
321
+
322
+ end
323
+ end
324
+ end