schleyfox-rgeo 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +199 -0
- data/README.rdoc +172 -0
- data/Spatial_Programming_With_RGeo.rdoc +440 -0
- data/Version +1 -0
- data/ext/geos_c_impl/extconf.rb +84 -0
- data/ext/geos_c_impl/factory.c +468 -0
- data/ext/geos_c_impl/factory.h +224 -0
- data/ext/geos_c_impl/geometry.c +705 -0
- data/ext/geos_c_impl/geometry.h +55 -0
- data/ext/geos_c_impl/geometry_collection.c +482 -0
- data/ext/geos_c_impl/geometry_collection.h +69 -0
- data/ext/geos_c_impl/line_string.c +509 -0
- data/ext/geos_c_impl/line_string.h +64 -0
- data/ext/geos_c_impl/main.c +70 -0
- data/ext/geos_c_impl/point.c +193 -0
- data/ext/geos_c_impl/point.h +62 -0
- data/ext/geos_c_impl/polygon.c +265 -0
- data/ext/geos_c_impl/polygon.h +66 -0
- data/ext/geos_c_impl/preface.h +50 -0
- data/ext/proj4_c_impl/extconf.rb +88 -0
- data/ext/proj4_c_impl/main.c +271 -0
- data/lib/rgeo.rb +124 -0
- data/lib/rgeo/cartesian.rb +60 -0
- data/lib/rgeo/cartesian/analysis.rb +118 -0
- data/lib/rgeo/cartesian/bounding_box.rb +337 -0
- data/lib/rgeo/cartesian/calculations.rb +161 -0
- data/lib/rgeo/cartesian/factory.rb +209 -0
- data/lib/rgeo/cartesian/feature_classes.rb +173 -0
- data/lib/rgeo/cartesian/feature_methods.rb +106 -0
- data/lib/rgeo/cartesian/interface.rb +150 -0
- data/lib/rgeo/coord_sys.rb +79 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +1524 -0
- data/lib/rgeo/coord_sys/cs/factories.rb +208 -0
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +308 -0
- data/lib/rgeo/coord_sys/proj4.rb +312 -0
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +194 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +165 -0
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +188 -0
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +108 -0
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +108 -0
- data/lib/rgeo/error.rb +63 -0
- data/lib/rgeo/feature.rb +88 -0
- data/lib/rgeo/feature/curve.rb +156 -0
- data/lib/rgeo/feature/factory.rb +332 -0
- data/lib/rgeo/feature/factory_generator.rb +138 -0
- data/lib/rgeo/feature/geometry.rb +614 -0
- data/lib/rgeo/feature/geometry_collection.rb +129 -0
- data/lib/rgeo/feature/line.rb +66 -0
- data/lib/rgeo/feature/line_string.rb +102 -0
- data/lib/rgeo/feature/linear_ring.rb +66 -0
- data/lib/rgeo/feature/multi_curve.rb +113 -0
- data/lib/rgeo/feature/multi_line_string.rb +66 -0
- data/lib/rgeo/feature/multi_point.rb +73 -0
- data/lib/rgeo/feature/multi_polygon.rb +97 -0
- data/lib/rgeo/feature/multi_surface.rb +116 -0
- data/lib/rgeo/feature/point.rb +120 -0
- data/lib/rgeo/feature/polygon.rb +141 -0
- data/lib/rgeo/feature/surface.rb +122 -0
- data/lib/rgeo/feature/types.rb +305 -0
- data/lib/rgeo/geographic.rb +75 -0
- data/lib/rgeo/geographic/factory.rb +287 -0
- data/lib/rgeo/geographic/interface.rb +410 -0
- data/lib/rgeo/geographic/proj4_projector.rb +98 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +213 -0
- data/lib/rgeo/geographic/projected_feature_methods.rb +228 -0
- data/lib/rgeo/geographic/projected_window.rb +467 -0
- data/lib/rgeo/geographic/simple_mercator_projector.rb +157 -0
- data/lib/rgeo/geographic/spherical_feature_classes.rb +212 -0
- data/lib/rgeo/geographic/spherical_feature_methods.rb +97 -0
- data/lib/rgeo/geographic/spherical_math.rb +206 -0
- data/lib/rgeo/geos.rb +72 -0
- data/lib/rgeo/geos/factory.rb +301 -0
- data/lib/rgeo/geos/impl_additions.rb +76 -0
- data/lib/rgeo/geos/interface.rb +139 -0
- data/lib/rgeo/geos/zm_factory.rb +275 -0
- data/lib/rgeo/geos/zm_impl.rb +432 -0
- data/lib/rgeo/impl_helper.rb +53 -0
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +235 -0
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +85 -0
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +197 -0
- data/lib/rgeo/impl_helper/basic_point_methods.rb +138 -0
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +121 -0
- data/lib/rgeo/impl_helper/math.rb +50 -0
- data/lib/rgeo/version.rb +52 -0
- data/lib/rgeo/wkrep.rb +72 -0
- data/lib/rgeo/wkrep/wkb_generator.rb +267 -0
- data/lib/rgeo/wkrep/wkb_parser.rb +315 -0
- data/lib/rgeo/wkrep/wkt_generator.rb +275 -0
- data/lib/rgeo/wkrep/wkt_parser.rb +496 -0
- data/test/common/geometry_collection_tests.rb +238 -0
- data/test/common/line_string_tests.rb +324 -0
- data/test/common/multi_line_string_tests.rb +209 -0
- data/test/common/multi_point_tests.rb +201 -0
- data/test/common/multi_polygon_tests.rb +208 -0
- data/test/common/point_tests.rb +331 -0
- data/test/common/polygon_tests.rb +232 -0
- data/test/coord_sys/tc_active_record_table.rb +102 -0
- data/test/coord_sys/tc_ogc_cs.rb +356 -0
- data/test/coord_sys/tc_proj4.rb +138 -0
- data/test/coord_sys/tc_proj4_srs_data.rb +76 -0
- data/test/coord_sys/tc_sr_org.rb +70 -0
- data/test/coord_sys/tc_url_reader.rb +82 -0
- data/test/geos/tc_factory.rb +91 -0
- data/test/geos/tc_geometry_collection.rb +62 -0
- data/test/geos/tc_line_string.rb +62 -0
- data/test/geos/tc_misc.rb +72 -0
- data/test/geos/tc_multi_line_string.rb +62 -0
- data/test/geos/tc_multi_point.rb +62 -0
- data/test/geos/tc_multi_polygon.rb +63 -0
- data/test/geos/tc_point.rb +86 -0
- data/test/geos/tc_polygon.rb +86 -0
- data/test/geos/tc_zmfactory.rb +85 -0
- data/test/projected_geographic/tc_geometry_collection.rb +62 -0
- data/test/projected_geographic/tc_line_string.rb +62 -0
- data/test/projected_geographic/tc_multi_line_string.rb +62 -0
- data/test/projected_geographic/tc_multi_point.rb +62 -0
- data/test/projected_geographic/tc_multi_polygon.rb +63 -0
- data/test/projected_geographic/tc_point.rb +93 -0
- data/test/projected_geographic/tc_polygon.rb +62 -0
- data/test/simple_cartesian/tc_calculations.rb +145 -0
- data/test/simple_cartesian/tc_geometry_collection.rb +69 -0
- data/test/simple_cartesian/tc_line_string.rb +70 -0
- data/test/simple_cartesian/tc_multi_line_string.rb +67 -0
- data/test/simple_cartesian/tc_multi_point.rb +67 -0
- data/test/simple_cartesian/tc_multi_polygon.rb +70 -0
- data/test/simple_cartesian/tc_point.rb +91 -0
- data/test/simple_cartesian/tc_polygon.rb +67 -0
- data/test/simple_mercator/tc_geometry_collection.rb +62 -0
- data/test/simple_mercator/tc_line_string.rb +62 -0
- data/test/simple_mercator/tc_multi_line_string.rb +62 -0
- data/test/simple_mercator/tc_multi_point.rb +62 -0
- data/test/simple_mercator/tc_multi_polygon.rb +63 -0
- data/test/simple_mercator/tc_point.rb +93 -0
- data/test/simple_mercator/tc_polygon.rb +62 -0
- data/test/simple_mercator/tc_window.rb +219 -0
- data/test/spherical_geographic/tc_calculations.rb +203 -0
- data/test/spherical_geographic/tc_geometry_collection.rb +70 -0
- data/test/spherical_geographic/tc_line_string.rb +70 -0
- data/test/spherical_geographic/tc_multi_line_string.rb +67 -0
- data/test/spherical_geographic/tc_multi_point.rb +67 -0
- data/test/spherical_geographic/tc_multi_polygon.rb +70 -0
- data/test/spherical_geographic/tc_point.rb +100 -0
- data/test/spherical_geographic/tc_polygon.rb +67 -0
- data/test/tc_cartesian_analysis.rb +107 -0
- data/test/tc_oneoff.rb +63 -0
- data/test/wkrep/tc_wkb_generator.rb +249 -0
- data/test/wkrep/tc_wkb_parser.rb +353 -0
- data/test/wkrep/tc_wkt_generator.rb +362 -0
- data/test/wkrep/tc_wkt_parser.rb +480 -0
- metadata +267 -0
@@ -0,0 +1,331 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common tests for point 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 PointTests # :nodoc:
|
45
|
+
|
46
|
+
|
47
|
+
def assert_close_enough(p1_, p2_)
|
48
|
+
assert((p1_.x - p2_.x).abs < 0.00000001 && (p1_.y - p2_.y).abs < 0.00000001)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def assert_contains_approx(p_, mp_)
|
53
|
+
assert(mp_.any?{ |q_| (p_.x - q_.x).abs < 0.00000001 && (p_.y - q_.y).abs < 0.00000001 })
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_creation
|
58
|
+
point_ = @factory.point(21, -22)
|
59
|
+
assert_equal(21, point_.x)
|
60
|
+
assert_equal(-22, point_.y)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def test_wkt_creation
|
65
|
+
point1_ = @factory.parse_wkt('POINT(21 -22)')
|
66
|
+
assert_equal(21, point1_.x)
|
67
|
+
assert_equal(-22, point1_.y)
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def test_clone
|
72
|
+
point1_ = @factory.point(11, 12)
|
73
|
+
point2_ = point1_.clone
|
74
|
+
assert_equal(point1_, point2_)
|
75
|
+
point3_ = @factory.point(13, 12)
|
76
|
+
point4_ = point3_.dup
|
77
|
+
assert_equal(point3_, point4_)
|
78
|
+
assert_not_equal(point2_, point4_)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def test_type_check
|
83
|
+
point_ = @factory.point(21, 22)
|
84
|
+
assert(::RGeo::Feature::Geometry.check_type(point_))
|
85
|
+
assert(::RGeo::Feature::Point.check_type(point_))
|
86
|
+
assert(!::RGeo::Feature::GeometryCollection.check_type(point_))
|
87
|
+
assert(!::RGeo::Feature::Curve.check_type(point_))
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def test_geometry_type
|
92
|
+
point_ = @factory.point(11, 12)
|
93
|
+
assert_equal(::RGeo::Feature::Point, point_.geometry_type)
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def test_dimension
|
98
|
+
point_ = @factory.point(11, 12)
|
99
|
+
assert_equal(0, point_.dimension)
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def test_envelope
|
104
|
+
point_ = @factory.point(11, 12)
|
105
|
+
assert_close_enough(point_, point_.envelope)
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def test_as_text_wkt_round_trip
|
110
|
+
point1_ = @factory.point(11, 12)
|
111
|
+
text_ = point1_.as_text
|
112
|
+
point2_ = @factory.parse_wkt(text_)
|
113
|
+
assert_equal(point2_, point1_)
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def test_as_binary_wkb_round_trip
|
118
|
+
point1_ = @factory.point(211, 12)
|
119
|
+
binary_ = point1_.as_binary
|
120
|
+
point2_ = @factory.parse_wkb(binary_)
|
121
|
+
assert_equal(point2_, point1_)
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def test_is_empty
|
126
|
+
point1_ = @factory.point(0, 0)
|
127
|
+
assert(!point1_.is_empty?)
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def test_is_simple
|
132
|
+
point1_ = @factory.point(0, 0)
|
133
|
+
assert(point1_.is_simple?)
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def test_boundary
|
138
|
+
point_ = @factory.point(11, 12)
|
139
|
+
boundary_ = point_.boundary
|
140
|
+
assert(boundary_.is_empty?)
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
def test_equals
|
145
|
+
point1_ = @factory.point(11, 12)
|
146
|
+
point2_ = @factory.point(11, 12)
|
147
|
+
point3_ = @factory.point(13, 12)
|
148
|
+
assert(point1_.equals?(point2_))
|
149
|
+
assert(point1_ == point2_)
|
150
|
+
assert(point1_.eql?(point2_))
|
151
|
+
assert(!point1_.equals?(point3_))
|
152
|
+
assert(point1_ != point3_)
|
153
|
+
assert(!point1_.eql?(point3_))
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def test_disjoint
|
158
|
+
point1_ = @factory.point(11, 12)
|
159
|
+
point2_ = @factory.point(11, 12)
|
160
|
+
point3_ = @factory.point(12, 12)
|
161
|
+
assert(!point1_.disjoint?(point2_))
|
162
|
+
assert(point1_.disjoint?(point3_))
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def test_intersects
|
167
|
+
point1_ = @factory.point(11, 12)
|
168
|
+
point2_ = @factory.point(11, 12)
|
169
|
+
point3_ = @factory.point(12, 12)
|
170
|
+
assert(point1_.intersects?(point2_))
|
171
|
+
assert(!point1_.intersects?(point3_))
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
def test_touches
|
176
|
+
point1_ = @factory.point(11, 12)
|
177
|
+
point2_ = @factory.point(11, 12)
|
178
|
+
point3_ = @factory.point(12, 12)
|
179
|
+
assert(!point1_.touches?(point2_))
|
180
|
+
assert(!point1_.touches?(point3_))
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
def test_crosses
|
185
|
+
point1_ = @factory.point(11, 12)
|
186
|
+
point2_ = @factory.point(11, 12)
|
187
|
+
point3_ = @factory.point(12, 12)
|
188
|
+
assert(!point1_.crosses?(point2_))
|
189
|
+
assert(!point1_.crosses?(point3_))
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
def test_within
|
194
|
+
point1_ = @factory.point(11, 12)
|
195
|
+
point2_ = @factory.point(11, 12)
|
196
|
+
point3_ = @factory.point(12, 12)
|
197
|
+
assert(point1_.within?(point2_))
|
198
|
+
assert(!point1_.within?(point3_))
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
def test_contains
|
203
|
+
point1_ = @factory.point(11, 12)
|
204
|
+
point2_ = @factory.point(11, 12)
|
205
|
+
point3_ = @factory.point(12, 12)
|
206
|
+
assert(point1_.contains?(point2_))
|
207
|
+
assert(!point1_.contains?(point3_))
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
def test_overlaps
|
212
|
+
point1_ = @factory.point(11, 12)
|
213
|
+
point2_ = @factory.point(11, 12)
|
214
|
+
point3_ = @factory.point(12, 12)
|
215
|
+
assert(!point1_.overlaps?(point2_))
|
216
|
+
assert(!point1_.overlaps?(point3_))
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
def test_convex_hull
|
221
|
+
point_ = @factory.point(11, 12)
|
222
|
+
assert_close_enough(point_, point_.convex_hull)
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
def test_intersection
|
227
|
+
point1_ = @factory.point(11, 12)
|
228
|
+
point2_ = @factory.point(11, 12)
|
229
|
+
point3_ = @factory.point(12, 12)
|
230
|
+
assert_close_enough(point1_, point1_.intersection(point2_))
|
231
|
+
int13_ = point1_.intersection(point3_)
|
232
|
+
assert(int13_.is_empty?)
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
def test_union
|
237
|
+
point1_ = @factory.point(11, 12)
|
238
|
+
point2_ = @factory.point(11, 12)
|
239
|
+
point3_ = @factory.point(12, 12)
|
240
|
+
union12_ = point1_.union(point2_)
|
241
|
+
union13_ = point1_.union(point3_)
|
242
|
+
assert_close_enough(point1_, union12_)
|
243
|
+
assert_equal(::RGeo::Feature::MultiPoint, union13_.geometry_type)
|
244
|
+
assert_contains_approx(point1_, union13_)
|
245
|
+
assert_contains_approx(point3_, union13_)
|
246
|
+
end
|
247
|
+
|
248
|
+
|
249
|
+
def test_difference
|
250
|
+
point1_ = @factory.point(11, 12)
|
251
|
+
point2_ = @factory.point(11, 12)
|
252
|
+
point3_ = @factory.point(12, 12)
|
253
|
+
diff12_ = point1_.difference(point2_)
|
254
|
+
diff13_ = point1_.difference(point3_)
|
255
|
+
assert_equal(::RGeo::Feature::GeometryCollection, diff12_.geometry_type)
|
256
|
+
assert(diff12_.is_empty?)
|
257
|
+
assert_close_enough(point1_, diff13_)
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
def test_sym_difference
|
262
|
+
point1_ = @factory.point(11, 12)
|
263
|
+
point2_ = @factory.point(11, 12)
|
264
|
+
point3_ = @factory.point(12, 12)
|
265
|
+
diff12_ = point1_.sym_difference(point2_)
|
266
|
+
diff13_ = point1_.sym_difference(point3_)
|
267
|
+
assert_equal(::RGeo::Feature::GeometryCollection, diff12_.geometry_type)
|
268
|
+
assert(diff12_.is_empty?)
|
269
|
+
assert_equal(::RGeo::Feature::MultiPoint, diff13_.geometry_type)
|
270
|
+
assert_contains_approx(point1_, diff13_)
|
271
|
+
assert_contains_approx(point3_, diff13_)
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
def test_3dz_creation
|
276
|
+
point_ = @zfactory.point(11, 12, 13)
|
277
|
+
assert_equal(11, point_.x)
|
278
|
+
assert_equal(12, point_.y)
|
279
|
+
assert_equal(13, point_.z)
|
280
|
+
point2_ = @zfactory.point(21, 22)
|
281
|
+
assert_equal(21, point2_.x)
|
282
|
+
assert_equal(22, point2_.y)
|
283
|
+
assert_equal(0, point2_.z)
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
def test_3dm_creation
|
288
|
+
point_ = @mfactory.point(11, 12, 13)
|
289
|
+
assert_equal(11, point_.x)
|
290
|
+
assert_equal(12, point_.y)
|
291
|
+
assert_equal(13, point_.m)
|
292
|
+
point2_ = @mfactory.point(21, 22)
|
293
|
+
assert_equal(21, point2_.x)
|
294
|
+
assert_equal(22, point2_.y)
|
295
|
+
assert_equal(0, point2_.m)
|
296
|
+
end
|
297
|
+
|
298
|
+
|
299
|
+
def test_4d_creation
|
300
|
+
point_ = @zmfactory.point(11, 12, 13, 14)
|
301
|
+
assert_equal(11, point_.x)
|
302
|
+
assert_equal(12, point_.y)
|
303
|
+
assert_equal(13, point_.z)
|
304
|
+
assert_equal(14, point_.m)
|
305
|
+
point2_ = @zmfactory.point(21, 22)
|
306
|
+
assert_equal(21, point2_.x)
|
307
|
+
assert_equal(22, point2_.y)
|
308
|
+
assert_equal(0, point2_.z)
|
309
|
+
assert_equal(0, point2_.m)
|
310
|
+
end
|
311
|
+
|
312
|
+
|
313
|
+
def test_wkt_creation_3d
|
314
|
+
point2_ = @zfactory.parse_wkt('POINT(11 12 13)')
|
315
|
+
assert_equal(11, point2_.x)
|
316
|
+
assert_equal(12, point2_.y)
|
317
|
+
assert_equal(13, point2_.z)
|
318
|
+
point1_ = @zfactory.parse_wkt('POINT(21 22)')
|
319
|
+
assert_equal(21, point1_.x)
|
320
|
+
assert_equal(22, point1_.y)
|
321
|
+
# Z is undefined in this case.
|
322
|
+
# We'd like to define it to be 0, but the GEOS
|
323
|
+
# parser doesn't behave that way.
|
324
|
+
end
|
325
|
+
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common tests for polygon 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 PolygonTests # :nodoc:
|
45
|
+
|
46
|
+
|
47
|
+
def test_creation_simple
|
48
|
+
point1_ = @factory.point(0, 0)
|
49
|
+
point2_ = @factory.point(0, 1)
|
50
|
+
point3_ = @factory.point(1, 0)
|
51
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
52
|
+
polygon_ = @factory.polygon(exterior_)
|
53
|
+
assert_not_nil(polygon_)
|
54
|
+
assert(::RGeo::Feature::Polygon === polygon_)
|
55
|
+
assert_equal(::RGeo::Feature::Polygon, polygon_.geometry_type)
|
56
|
+
assert(exterior_.eql?(polygon_.exterior_ring))
|
57
|
+
assert_equal(0, polygon_.num_interior_rings)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def test_creation_one_hole
|
62
|
+
point1_ = @factory.point(0, 0)
|
63
|
+
point2_ = @factory.point(0, 10)
|
64
|
+
point3_ = @factory.point(10, 10)
|
65
|
+
point4_ = @factory.point(10, 0)
|
66
|
+
point5_ = @factory.point(4, 4)
|
67
|
+
point6_ = @factory.point(5, 6)
|
68
|
+
point7_ = @factory.point(6, 4)
|
69
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
|
70
|
+
interior_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
|
71
|
+
polygon_ = @factory.polygon(exterior_, [interior_])
|
72
|
+
assert_not_nil(polygon_)
|
73
|
+
assert(::RGeo::Feature::Polygon === polygon_)
|
74
|
+
assert_equal(::RGeo::Feature::Polygon, polygon_.geometry_type)
|
75
|
+
assert(exterior_.eql?(polygon_.exterior_ring))
|
76
|
+
assert_equal(1, polygon_.num_interior_rings)
|
77
|
+
assert(interior_.eql?(polygon_.interior_ring_n(0)))
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def test_fully_equal
|
82
|
+
point1_ = @factory.point(0, 0)
|
83
|
+
point2_ = @factory.point(0, 1)
|
84
|
+
point3_ = @factory.point(1, 0)
|
85
|
+
exterior1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
86
|
+
poly1_ = @factory.polygon(exterior1_)
|
87
|
+
point4_ = @factory.point(0, 0)
|
88
|
+
point5_ = @factory.point(0, 1)
|
89
|
+
point6_ = @factory.point(1, 0)
|
90
|
+
exterior2_ = @factory.linear_ring([point4_, point5_, point6_, point4_])
|
91
|
+
poly2_ = @factory.polygon(exterior2_)
|
92
|
+
assert(poly1_.eql?(poly2_))
|
93
|
+
assert(poly1_.equals?(poly2_))
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def test_geometrically_equal_but_ordered_different
|
98
|
+
point1_ = @factory.point(0, 0)
|
99
|
+
point2_ = @factory.point(0, 1)
|
100
|
+
point3_ = @factory.point(1, 0)
|
101
|
+
exterior1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
102
|
+
poly1_ = @factory.polygon(exterior1_)
|
103
|
+
exterior2_ = @factory.linear_ring([point2_, point3_, point1_, point2_])
|
104
|
+
poly2_ = @factory.polygon(exterior2_)
|
105
|
+
assert(!poly1_.eql?(poly2_))
|
106
|
+
assert(poly1_.equals?(poly2_))
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def test_geometrically_equal_but_different_directions
|
111
|
+
point1_ = @factory.point(0, 0)
|
112
|
+
point2_ = @factory.point(0, 1)
|
113
|
+
point3_ = @factory.point(1, 0)
|
114
|
+
exterior1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
115
|
+
poly1_ = @factory.polygon(exterior1_)
|
116
|
+
exterior2_ = @factory.linear_ring([point1_, point3_, point2_, point1_])
|
117
|
+
poly2_ = @factory.polygon(exterior2_)
|
118
|
+
assert(!poly1_.eql?(poly2_))
|
119
|
+
assert(poly1_.equals?(poly2_))
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def test_wkt_creation_simple
|
124
|
+
parsed_poly_ = @factory.parse_wkt('POLYGON((0 0, 0 1, 1 0, 0 0))')
|
125
|
+
point1_ = @factory.point(0, 0)
|
126
|
+
point2_ = @factory.point(0, 1)
|
127
|
+
point3_ = @factory.point(1, 0)
|
128
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
129
|
+
built_poly_ = @factory.polygon(exterior_)
|
130
|
+
assert(built_poly_.eql?(parsed_poly_))
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
def test_wkt_creation_one_hole
|
135
|
+
parsed_poly_ = @factory.parse_wkt('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0), (4 4, 5 6, 6 4, 4 4))')
|
136
|
+
point1_ = @factory.point(0, 0)
|
137
|
+
point2_ = @factory.point(0, 10)
|
138
|
+
point3_ = @factory.point(10, 10)
|
139
|
+
point4_ = @factory.point(10, 0)
|
140
|
+
point5_ = @factory.point(4, 4)
|
141
|
+
point6_ = @factory.point(5, 6)
|
142
|
+
point7_ = @factory.point(6, 4)
|
143
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
|
144
|
+
interior_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
|
145
|
+
built_poly_ = @factory.polygon(exterior_, [interior_])
|
146
|
+
assert(built_poly_.eql?(parsed_poly_))
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def test_clone
|
151
|
+
point1_ = @factory.point(0, 0)
|
152
|
+
point2_ = @factory.point(0, 1)
|
153
|
+
point3_ = @factory.point(1, 0)
|
154
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
155
|
+
poly1_ = @factory.polygon(exterior_)
|
156
|
+
poly2_ = poly1_.clone
|
157
|
+
assert(poly1_.eql?(poly2_))
|
158
|
+
assert(exterior_.eql?(poly2_.exterior_ring))
|
159
|
+
assert_equal(0, poly2_.num_interior_rings)
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
def test_type_check
|
164
|
+
point1_ = @factory.point(0, 0)
|
165
|
+
point2_ = @factory.point(0, 1)
|
166
|
+
point3_ = @factory.point(1, 0)
|
167
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
168
|
+
poly_ = @factory.polygon(exterior_)
|
169
|
+
assert(::RGeo::Feature::Geometry.check_type(poly_))
|
170
|
+
assert(!::RGeo::Feature::Point.check_type(poly_))
|
171
|
+
assert(!::RGeo::Feature::GeometryCollection.check_type(poly_))
|
172
|
+
assert(::RGeo::Feature::Surface.check_type(poly_))
|
173
|
+
assert(::RGeo::Feature::Polygon.check_type(poly_))
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
def test_as_text_wkt_round_trip
|
178
|
+
point1_ = @factory.point(0, 0)
|
179
|
+
point2_ = @factory.point(0, 1)
|
180
|
+
point3_ = @factory.point(1, 0)
|
181
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
182
|
+
poly1_ = @factory.polygon(exterior_)
|
183
|
+
text_ = poly1_.as_text
|
184
|
+
poly2_ = @factory.parse_wkt(text_)
|
185
|
+
assert(poly1_.eql?(poly2_))
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
def test_as_binary_wkb_round_trip
|
190
|
+
point1_ = @factory.point(0, 0)
|
191
|
+
point2_ = @factory.point(0, 1)
|
192
|
+
point3_ = @factory.point(1, 0)
|
193
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
194
|
+
poly1_ = @factory.polygon(exterior_)
|
195
|
+
binary_ = poly1_.as_binary
|
196
|
+
poly2_ = @factory.parse_wkb(binary_)
|
197
|
+
assert(poly1_.eql?(poly2_))
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
def test_dimension
|
202
|
+
point1_ = @factory.point(0, 0)
|
203
|
+
point2_ = @factory.point(0, 10)
|
204
|
+
point3_ = @factory.point(10, 10)
|
205
|
+
point4_ = @factory.point(10, 0)
|
206
|
+
point5_ = @factory.point(4, 4)
|
207
|
+
point6_ = @factory.point(5, 6)
|
208
|
+
point7_ = @factory.point(6, 4)
|
209
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
|
210
|
+
interior_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
|
211
|
+
poly_ = @factory.polygon(exterior_, [interior_])
|
212
|
+
assert_equal(2, poly_.dimension)
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
def test_is_empty
|
217
|
+
point1_ = @factory.point(0, 0)
|
218
|
+
point2_ = @factory.point(0, 1)
|
219
|
+
point3_ = @factory.point(1, 0)
|
220
|
+
exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
221
|
+
poly1_ = @factory.polygon(exterior_)
|
222
|
+
assert(!poly1_.is_empty?)
|
223
|
+
poly2_ = @factory.polygon(@factory.linear_ring([]))
|
224
|
+
assert(poly2_.is_empty?)
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|