rgeo 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +22 -0
- data/README.rdoc +124 -0
- data/Version +1 -0
- data/ext/geos_c_impl/extconf.rb +72 -0
- data/ext/geos_c_impl/factory.c +468 -0
- data/ext/geos_c_impl/factory.h +217 -0
- data/ext/geos_c_impl/geometry.c +644 -0
- data/ext/geos_c_impl/geometry.h +65 -0
- data/ext/geos_c_impl/geometry_collection.c +580 -0
- data/ext/geos_c_impl/geometry_collection.h +79 -0
- data/ext/geos_c_impl/globals.h +58 -0
- data/ext/geos_c_impl/line_string.c +468 -0
- data/ext/geos_c_impl/line_string.h +74 -0
- data/ext/geos_c_impl/main.c +65 -0
- data/ext/geos_c_impl/point.c +201 -0
- data/ext/geos_c_impl/point.h +77 -0
- data/ext/geos_c_impl/polygon.c +259 -0
- data/ext/geos_c_impl/polygon.h +76 -0
- data/ext/geos_c_impl/preface.h +42 -0
- data/lib/rgeo.rb +68 -0
- data/lib/rgeo/errors.rb +59 -0
- data/lib/rgeo/features.rb +89 -0
- data/lib/rgeo/features/curve.rb +155 -0
- data/lib/rgeo/features/factory.rb +191 -0
- data/lib/rgeo/features/geometry.rb +560 -0
- data/lib/rgeo/features/geometry_collection.rb +118 -0
- data/lib/rgeo/features/line.rb +65 -0
- data/lib/rgeo/features/line_string.rb +101 -0
- data/lib/rgeo/features/linear_ring.rb +65 -0
- data/lib/rgeo/features/multi_curve.rb +112 -0
- data/lib/rgeo/features/multi_line_string.rb +65 -0
- data/lib/rgeo/features/multi_point.rb +72 -0
- data/lib/rgeo/features/multi_polygon.rb +96 -0
- data/lib/rgeo/features/multi_surface.rb +115 -0
- data/lib/rgeo/features/point.rb +97 -0
- data/lib/rgeo/features/polygon.rb +141 -0
- data/lib/rgeo/features/surface.rb +121 -0
- data/lib/rgeo/geo_json.rb +58 -0
- data/lib/rgeo/geo_json/coder.rb +305 -0
- data/lib/rgeo/geo_json/entities.rb +284 -0
- data/lib/rgeo/geo_json/interface.rb +95 -0
- data/lib/rgeo/geography.rb +75 -0
- data/lib/rgeo/geography/common/geometry_collection_methods.rb +206 -0
- data/lib/rgeo/geography/common/geometry_methods.rb +92 -0
- data/lib/rgeo/geography/common/helper.rb +102 -0
- data/lib/rgeo/geography/common/line_string_methods.rb +187 -0
- data/lib/rgeo/geography/common/point_methods.rb +149 -0
- data/lib/rgeo/geography/common/polygon_methods.rb +122 -0
- data/lib/rgeo/geography/factories.rb +136 -0
- data/lib/rgeo/geography/factory.rb +246 -0
- data/lib/rgeo/geography/projected_window.rb +467 -0
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +320 -0
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +291 -0
- data/lib/rgeo/geography/simple_mercator/projector.rb +116 -0
- data/lib/rgeo/geography/simple_spherical/calculations.rb +70 -0
- data/lib/rgeo/geography/simple_spherical/geometry_collection_impl.rb +66 -0
- data/lib/rgeo/geography/simple_spherical/geometry_methods.rb +59 -0
- data/lib/rgeo/geography/simple_spherical/line_string_impl.rb +104 -0
- data/lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/multi_point_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/point_impl.rb +85 -0
- data/lib/rgeo/geography/simple_spherical/polygon_impl.rb +66 -0
- data/lib/rgeo/geos.rb +72 -0
- data/lib/rgeo/geos/factory.rb +260 -0
- data/lib/rgeo/geos/impl_additions.rb +57 -0
- data/lib/rgeo/geos/interface.rb +74 -0
- data/lib/rgeo/version.rb +52 -0
- data/tests/geos/tc_factory.rb +91 -0
- data/tests/geos/tc_geometry_collection.rb +226 -0
- data/tests/geos/tc_line_string.rb +310 -0
- data/tests/geos/tc_misc.rb +72 -0
- data/tests/geos/tc_multi_line_string.rb +211 -0
- data/tests/geos/tc_multi_point.rb +202 -0
- data/tests/geos/tc_multi_polygon.rb +210 -0
- data/tests/geos/tc_point.rb +305 -0
- data/tests/geos/tc_polygon.rb +240 -0
- data/tests/simple_mercator/tc_point.rb +303 -0
- data/tests/simple_mercator/tc_window.rb +219 -0
- data/tests/tc_geojson.rb +230 -0
- data/tests/tc_oneoff.rb +61 -0
- metadata +162 -0
@@ -0,0 +1,202 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Tests for the GEOS multi point 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 TestMultiPoint < ::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(-5, 3)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def test_creation_simple
|
59
|
+
geom_ = @factory.multi_point([@point1, @point2])
|
60
|
+
assert_not_nil(geom_)
|
61
|
+
assert_kind_of(::RGeo::Geos::MultiPointImpl, geom_)
|
62
|
+
assert(::RGeo::Features::MultiPoint === geom_)
|
63
|
+
assert_equal(::RGeo::Features::MultiPoint, geom_.geometry_type)
|
64
|
+
assert_equal(2, geom_.num_geometries)
|
65
|
+
assert_equal([@point1, @point2], geom_.to_a)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def test_creation_empty
|
70
|
+
geom_ = @factory.multi_point([])
|
71
|
+
assert_not_nil(geom_)
|
72
|
+
assert_kind_of(::RGeo::Geos::MultiPointImpl, geom_)
|
73
|
+
assert(::RGeo::Features::MultiPoint === geom_)
|
74
|
+
assert_equal(::RGeo::Features::MultiPoint, geom_.geometry_type)
|
75
|
+
assert_equal(0, geom_.num_geometries)
|
76
|
+
assert_equal([], geom_.to_a)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def test_creation_compound
|
81
|
+
mp1_ = @factory.multi_point([@point1, @point2])
|
82
|
+
mp2_ = @factory.collection([@point3])
|
83
|
+
mp3_ = @factory.collection([mp1_])
|
84
|
+
geom_ = @factory.multi_point([mp3_, mp2_, @point4])
|
85
|
+
assert_not_nil(geom_)
|
86
|
+
assert_kind_of(::RGeo::Geos::MultiPointImpl, geom_)
|
87
|
+
assert(::RGeo::Features::MultiPoint === geom_)
|
88
|
+
assert_equal(::RGeo::Features::MultiPoint, geom_.geometry_type)
|
89
|
+
assert_equal(4, geom_.num_geometries)
|
90
|
+
assert_equal([@point1, @point2, @point3, @point4], geom_.to_a)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def test_creation_wrong_type
|
95
|
+
line_ = @factory.line_string([@point1, @point2])
|
96
|
+
geom_ = @factory.multi_point([@point3, line_])
|
97
|
+
assert_nil(geom_)
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def test_fully_equal
|
102
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
103
|
+
geom2_ = @factory.multi_point([@point1, @point2])
|
104
|
+
assert(geom1_.eql?(geom2_))
|
105
|
+
assert(geom1_.equals?(geom2_))
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def test_geometrically_equal
|
110
|
+
geom1_ = @factory.multi_point([@point1, @point4])
|
111
|
+
geom2_ = @factory.multi_point([@point1, @point4, @point5])
|
112
|
+
assert(!geom1_.eql?(geom2_))
|
113
|
+
assert(geom1_.equals?(geom2_))
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def test_not_equal
|
118
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
119
|
+
geom2_ = @factory.multi_point([@point1])
|
120
|
+
assert(!geom1_.eql?(geom2_))
|
121
|
+
assert(!geom1_.equals?(geom2_))
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def test_wkt_creation_simple
|
126
|
+
parsed_geom_ = @factory.parse_wkt('MULTIPOINT((0 0), (-4 2), (-5 3))')
|
127
|
+
built_geom_ = @factory.multi_point([@point1, @point3, @point4])
|
128
|
+
assert_equal(built_geom_, parsed_geom_)
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def test_wkt_creation_empty
|
133
|
+
parsed_geom_ = @factory.parse_wkt('MULTIPOINT EMPTY')
|
134
|
+
assert(::RGeo::Features::MultiPoint === parsed_geom_)
|
135
|
+
assert_equal(0, parsed_geom_.num_geometries)
|
136
|
+
assert_equal([], parsed_geom_.to_a)
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def test_clone
|
141
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
142
|
+
geom2_ = geom1_.clone
|
143
|
+
assert_equal(geom1_, geom2_)
|
144
|
+
assert_equal(::RGeo::Features::MultiPoint, geom2_.geometry_type)
|
145
|
+
assert_equal(2, geom2_.num_geometries)
|
146
|
+
assert_equal([@point1, @point2], geom2_.to_a)
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def test_type_check
|
151
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
152
|
+
assert(::RGeo::Features::Geometry.check_type(geom1_))
|
153
|
+
assert(!::RGeo::Features::Point.check_type(geom1_))
|
154
|
+
assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
|
155
|
+
assert(::RGeo::Features::MultiPoint.check_type(geom1_))
|
156
|
+
assert(!::RGeo::Features::MultiLineString.check_type(geom1_))
|
157
|
+
geom2_ = @factory.multi_point([])
|
158
|
+
assert(::RGeo::Features::Geometry.check_type(geom2_))
|
159
|
+
assert(!::RGeo::Features::Point.check_type(geom2_))
|
160
|
+
assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
|
161
|
+
assert(::RGeo::Features::MultiPoint.check_type(geom2_))
|
162
|
+
assert(!::RGeo::Features::MultiLineString.check_type(geom2_))
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def test_as_text_wkt_round_trip
|
167
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
168
|
+
text_ = geom1_.as_text
|
169
|
+
geom2_ = @factory.parse_wkt(text_)
|
170
|
+
assert_equal(geom1_, geom2_)
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def test_as_binary_wkb_round_trip
|
175
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
176
|
+
binary_ = geom1_.as_binary
|
177
|
+
geom2_ = @factory.parse_wkb(binary_)
|
178
|
+
assert_equal(geom1_, geom2_)
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def test_dimension
|
183
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
184
|
+
assert_equal(0, geom1_.dimension)
|
185
|
+
geom2_ = @factory.multi_point([])
|
186
|
+
assert_equal(-1, geom2_.dimension)
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def test_is_empty
|
191
|
+
geom1_ = @factory.multi_point([@point1, @point2])
|
192
|
+
assert(!geom1_.is_empty?)
|
193
|
+
geom2_ = @factory.multi_point([])
|
194
|
+
assert(geom2_.is_empty?)
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Tests for the GEOS multi polygon 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 TestMultiPolygon < ::Test::Unit::TestCase # :nodoc:
|
46
|
+
|
47
|
+
|
48
|
+
def setup
|
49
|
+
@factory = ::RGeo::Geos.factory
|
50
|
+
@lenient_factory = ::RGeo::Geos.factory(:lenient_multi_polygon_assertions => true)
|
51
|
+
point1_ = @factory.point(0, 0)
|
52
|
+
point2_ = @factory.point(0, 10)
|
53
|
+
point3_ = @factory.point(10, 10)
|
54
|
+
point4_ = @factory.point(10, 0)
|
55
|
+
point5_ = @factory.point(4, 4)
|
56
|
+
point6_ = @factory.point(5, 6)
|
57
|
+
point7_ = @factory.point(6, 4)
|
58
|
+
point8_ = @factory.point(0, -10)
|
59
|
+
point9_ = @factory.point(-10, 0)
|
60
|
+
exterior1_ = @factory.linear_ring([point1_, point8_, point9_, point1_])
|
61
|
+
exterior2_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
|
62
|
+
exterior3_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
63
|
+
exterior4_ = @factory.linear_ring([point1_, point3_, point4_, point1_])
|
64
|
+
interior1_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
|
65
|
+
@poly1 = @factory.polygon(exterior1_)
|
66
|
+
@poly2 = @factory.polygon(exterior2_, [interior1_])
|
67
|
+
@poly3 = @factory.polygon(exterior3_)
|
68
|
+
@poly4 = @factory.polygon(exterior4_)
|
69
|
+
@line1 = interior1_
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_creation_simple
|
74
|
+
geom_ = @factory.multi_polygon([@poly1, @poly2])
|
75
|
+
assert_not_nil(geom_)
|
76
|
+
assert_kind_of(::RGeo::Geos::MultiPolygonImpl, geom_)
|
77
|
+
assert(::RGeo::Features::MultiPolygon === geom_)
|
78
|
+
assert_equal(::RGeo::Features::MultiPolygon, geom_.geometry_type)
|
79
|
+
assert_equal(2, geom_.num_geometries)
|
80
|
+
assert_equal([@poly1, @poly2], geom_.to_a)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def test_creation_empty
|
85
|
+
geom_ = @factory.multi_polygon([])
|
86
|
+
assert_not_nil(geom_)
|
87
|
+
assert_kind_of(::RGeo::Geos::MultiPolygonImpl, geom_)
|
88
|
+
assert(::RGeo::Features::MultiPolygon === geom_)
|
89
|
+
assert_equal(::RGeo::Features::MultiPolygon, geom_.geometry_type)
|
90
|
+
assert_equal(0, geom_.num_geometries)
|
91
|
+
assert_equal([], geom_.to_a)
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def test_creation_wrong_type
|
96
|
+
geom_ = @factory.multi_polygon([@poly1, @line1])
|
97
|
+
assert_nil(geom_)
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def test_creation_overlapping
|
102
|
+
geom_ = @factory.multi_polygon([@poly1, @poly1])
|
103
|
+
assert_nil(geom_)
|
104
|
+
geom2_ = @lenient_factory.multi_polygon([@poly1, @poly1])
|
105
|
+
assert_not_nil(geom2_)
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def test_creation_connected
|
110
|
+
geom_ = @factory.multi_polygon([@poly3, @poly4])
|
111
|
+
assert_nil(geom_)
|
112
|
+
geom2_ = @lenient_factory.multi_polygon([@poly3, @poly4])
|
113
|
+
assert_not_nil(geom2_)
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def test_equal
|
118
|
+
geom1_ = @factory.multi_polygon([@poly1, @poly2])
|
119
|
+
geom2_ = @factory.multi_polygon([@poly1, @poly2])
|
120
|
+
assert(geom1_.eql?(geom2_))
|
121
|
+
assert(geom1_.equals?(geom2_))
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def test_not_equal
|
126
|
+
geom1_ = @factory.multi_polygon([@poly1])
|
127
|
+
geom2_ = @factory.multi_polygon([@poly2])
|
128
|
+
assert(!geom1_.eql?(geom2_))
|
129
|
+
assert(!geom1_.equals?(geom2_))
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def test_wkt_creation_simple
|
134
|
+
parsed_geom_ = @factory.parse_wkt('MULTIPOLYGON(((0 0, 0 -10, -10 0, 0 0)), ((0 0, 0 10, 10 10, 10 0, 0 0), (4 4, 5 6, 6 4, 4 4)))')
|
135
|
+
built_geom_ = @factory.multi_polygon([@poly1, @poly2])
|
136
|
+
assert_equal(built_geom_, parsed_geom_)
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def test_wkt_creation_empty
|
141
|
+
parsed_geom_ = @factory.parse_wkt('MULTIPOLYGON EMPTY')
|
142
|
+
assert_equal(::RGeo::Features::MultiPolygon, parsed_geom_.geometry_type)
|
143
|
+
assert_equal(0, parsed_geom_.num_geometries)
|
144
|
+
assert_equal([], parsed_geom_.to_a)
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
def test_clone
|
149
|
+
geom1_ = @factory.multi_polygon([@poly1, @poly2])
|
150
|
+
geom2_ = geom1_.clone
|
151
|
+
assert_equal(geom1_, geom2_)
|
152
|
+
assert_equal(::RGeo::Features::MultiPolygon, geom2_.geometry_type)
|
153
|
+
assert_equal(2, geom2_.num_geometries)
|
154
|
+
assert_equal([@poly1, @poly2], geom2_.to_a)
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
def test_type_check
|
159
|
+
geom1_ = @factory.multi_polygon([@poly1, @poly2])
|
160
|
+
assert(::RGeo::Features::Geometry.check_type(geom1_))
|
161
|
+
assert(!::RGeo::Features::Polygon.check_type(geom1_))
|
162
|
+
assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
|
163
|
+
assert(!::RGeo::Features::MultiPoint.check_type(geom1_))
|
164
|
+
assert(::RGeo::Features::MultiPolygon.check_type(geom1_))
|
165
|
+
geom2_ = @factory.multi_polygon([])
|
166
|
+
assert(::RGeo::Features::Geometry.check_type(geom2_))
|
167
|
+
assert(!::RGeo::Features::Polygon.check_type(geom2_))
|
168
|
+
assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
|
169
|
+
assert(!::RGeo::Features::MultiPoint.check_type(geom2_))
|
170
|
+
assert(::RGeo::Features::MultiPolygon.check_type(geom2_))
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def test_as_text_wkt_round_trip
|
175
|
+
geom1_ = @factory.multi_polygon([@poly1, @poly2])
|
176
|
+
text_ = geom1_.as_text
|
177
|
+
geom2_ = @factory.parse_wkt(text_)
|
178
|
+
assert_equal(geom1_, geom2_)
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def test_as_binary_wkb_round_trip
|
183
|
+
geom1_ = @factory.multi_polygon([@poly1, @poly2])
|
184
|
+
binary_ = geom1_.as_binary
|
185
|
+
geom2_ = @factory.parse_wkb(binary_)
|
186
|
+
assert_equal(geom1_, geom2_)
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def test_dimension
|
191
|
+
geom1_ = @factory.multi_polygon([@poly1, @poly2])
|
192
|
+
assert_equal(2, geom1_.dimension)
|
193
|
+
geom2_ = @factory.multi_polygon([])
|
194
|
+
assert_equal(-1, geom2_.dimension)
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
def test_is_empty
|
199
|
+
geom1_ = @factory.multi_polygon([@poly1, @poly2])
|
200
|
+
assert(!geom1_.is_empty?)
|
201
|
+
geom2_ = @factory.multi_polygon([])
|
202
|
+
assert(geom2_.is_empty?)
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,305 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Tests for the GEOS point 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 TestPoint < ::Test::Unit::TestCase # :nodoc:
|
46
|
+
|
47
|
+
|
48
|
+
def setup
|
49
|
+
@factory = ::RGeo::Geos.factory
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def test_2d_creation
|
54
|
+
point_ = @factory.point(21, 22)
|
55
|
+
assert_equal(21, point_.x)
|
56
|
+
assert_equal(22, point_.y)
|
57
|
+
assert_nil(point_.z)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def test_3d_creation
|
62
|
+
point_ = @factory.point3d(11, 12, 13)
|
63
|
+
assert_equal(11, point_.x)
|
64
|
+
assert_equal(12, point_.y)
|
65
|
+
assert_equal(13, point_.z)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def test_wkt_creation
|
70
|
+
point1_ = @factory.parse_wkt('POINT(21 22)')
|
71
|
+
assert_equal(21, point1_.x)
|
72
|
+
assert_equal(22, point1_.y)
|
73
|
+
assert_nil(point1_.z)
|
74
|
+
point2_ = @factory.parse_wkt('POINT(11 12 13)')
|
75
|
+
assert_equal(11, point2_.x)
|
76
|
+
assert_equal(12, point2_.y)
|
77
|
+
assert_equal(13, point2_.z)
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def test_clone
|
82
|
+
point1_ = @factory.point(11, 12)
|
83
|
+
point2_ = point1_.clone
|
84
|
+
assert_equal(point1_, point2_)
|
85
|
+
point3_ = @factory.point(13, 12)
|
86
|
+
point4_ = point3_.dup
|
87
|
+
assert_equal(point3_, point4_)
|
88
|
+
assert_not_equal(point2_, point4_)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def test_type_check
|
93
|
+
point_ = @factory.point(21, 22)
|
94
|
+
assert(::RGeo::Features::Geometry.check_type(point_))
|
95
|
+
assert(::RGeo::Features::Point.check_type(point_))
|
96
|
+
assert(!::RGeo::Features::GeometryCollection.check_type(point_))
|
97
|
+
assert(!::RGeo::Features::Curve.check_type(point_))
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def test_geometry_type
|
102
|
+
point_ = @factory.point(11, 12)
|
103
|
+
assert_equal(::RGeo::Features::Point, point_.geometry_type)
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def test_srid
|
108
|
+
point_ = @factory.point(11, 12)
|
109
|
+
assert_equal(0, point_.srid)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def test_dimension
|
114
|
+
point_ = @factory.point(11, 12)
|
115
|
+
assert_equal(0, point_.dimension)
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def test_envelope
|
120
|
+
point_ = @factory.point(11, 12)
|
121
|
+
assert_equal(point_, point_.envelope)
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def test_as_text_wkt_round_trip
|
126
|
+
point1_ = @factory.point(11, 12)
|
127
|
+
text_ = point1_.as_text
|
128
|
+
point2_ = @factory.parse_wkt(text_)
|
129
|
+
assert(point2_.eql?(point1_))
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def test_as_binary_wkb_round_trip
|
134
|
+
point1_ = @factory.point(211, 12)
|
135
|
+
binary_ = point1_.as_binary
|
136
|
+
point2_ = @factory.parse_wkb(binary_)
|
137
|
+
assert(point2_.eql?(point1_))
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def test_is_empty
|
142
|
+
point1_ = @factory.point(0, 0)
|
143
|
+
assert(!point1_.is_empty?)
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def test_is_simple
|
148
|
+
point1_ = @factory.point(0, 0)
|
149
|
+
assert(point1_.is_simple?)
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
def test_boundary
|
154
|
+
point_ = @factory.point(11, 12)
|
155
|
+
boundary_ = point_.boundary
|
156
|
+
assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, boundary_)
|
157
|
+
assert(boundary_.is_empty?)
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def test_equals
|
162
|
+
point1_ = @factory.point(11, 12)
|
163
|
+
point2_ = @factory.point(11, 12)
|
164
|
+
point3_ = @factory.point(13, 12)
|
165
|
+
assert(point1_.equals?(point2_))
|
166
|
+
assert(point1_.eql?(point2_))
|
167
|
+
assert(!point1_.equals?(point3_))
|
168
|
+
assert(!point1_.eql?(point3_))
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
def test_disjoint
|
173
|
+
point1_ = @factory.point(11, 12)
|
174
|
+
point2_ = @factory.point(11, 12)
|
175
|
+
point3_ = @factory.point(12, 12)
|
176
|
+
assert(!point1_.disjoint?(point2_))
|
177
|
+
assert(point1_.disjoint?(point3_))
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def test_intersects
|
182
|
+
point1_ = @factory.point(11, 12)
|
183
|
+
point2_ = @factory.point(11, 12)
|
184
|
+
point3_ = @factory.point(12, 12)
|
185
|
+
assert(point1_.intersects?(point2_))
|
186
|
+
assert(!point1_.intersects?(point3_))
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def test_touches
|
191
|
+
point1_ = @factory.point(11, 12)
|
192
|
+
point2_ = @factory.point(11, 12)
|
193
|
+
point3_ = @factory.point(12, 12)
|
194
|
+
assert(!point1_.touches?(point2_))
|
195
|
+
assert(!point1_.touches?(point3_))
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
def test_crosses
|
200
|
+
point1_ = @factory.point(11, 12)
|
201
|
+
point2_ = @factory.point(11, 12)
|
202
|
+
point3_ = @factory.point(12, 12)
|
203
|
+
assert(!point1_.crosses?(point2_))
|
204
|
+
assert(!point1_.crosses?(point3_))
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def test_within
|
209
|
+
point1_ = @factory.point(11, 12)
|
210
|
+
point2_ = @factory.point(11, 12)
|
211
|
+
point3_ = @factory.point(12, 12)
|
212
|
+
assert(point1_.within?(point2_))
|
213
|
+
assert(!point1_.within?(point3_))
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
def test_contains
|
218
|
+
point1_ = @factory.point(11, 12)
|
219
|
+
point2_ = @factory.point(11, 12)
|
220
|
+
point3_ = @factory.point(12, 12)
|
221
|
+
assert(point1_.contains?(point2_))
|
222
|
+
assert(!point1_.contains?(point3_))
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
def test_overlaps
|
227
|
+
point1_ = @factory.point(11, 12)
|
228
|
+
point2_ = @factory.point(11, 12)
|
229
|
+
point3_ = @factory.point(12, 12)
|
230
|
+
assert(!point1_.overlaps?(point2_))
|
231
|
+
assert(!point1_.overlaps?(point3_))
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
def test_distance
|
236
|
+
point1_ = @factory.point(11, 12)
|
237
|
+
point2_ = @factory.point(11, 12)
|
238
|
+
point3_ = @factory.point(13, 12)
|
239
|
+
assert_equal(0, point1_.distance(point2_))
|
240
|
+
assert_equal(2, point1_.distance(point3_))
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
def test_convex_hull
|
245
|
+
point_ = @factory.point(11, 12)
|
246
|
+
hull_ = point_.convex_hull
|
247
|
+
assert_equal(point_, hull_)
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
def test_intersection
|
252
|
+
point1_ = @factory.point(11, 12)
|
253
|
+
point2_ = @factory.point(11, 12)
|
254
|
+
point3_ = @factory.point(12, 12)
|
255
|
+
assert_equal(point1_, point1_.intersection(point2_))
|
256
|
+
int13_ = point1_.intersection(point3_)
|
257
|
+
assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, int13_)
|
258
|
+
assert(int13_.is_empty?)
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
def test_union
|
263
|
+
point1_ = @factory.point(11, 12)
|
264
|
+
point2_ = @factory.point(11, 12)
|
265
|
+
point3_ = @factory.point(12, 12)
|
266
|
+
union12_ = point1_.union(point2_)
|
267
|
+
union13_ = point1_.union(point3_)
|
268
|
+
assert_equal(point1_, union12_)
|
269
|
+
assert_kind_of(::RGeo::Geos::MultiPointImpl, union13_)
|
270
|
+
assert(union13_.contains?(point1_))
|
271
|
+
assert(union13_.contains?(point3_))
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
def test_difference
|
276
|
+
point1_ = @factory.point(11, 12)
|
277
|
+
point2_ = @factory.point(11, 12)
|
278
|
+
point3_ = @factory.point(12, 12)
|
279
|
+
diff12_ = point1_.difference(point2_)
|
280
|
+
diff13_ = point1_.difference(point3_)
|
281
|
+
assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, diff12_)
|
282
|
+
assert(diff12_.is_empty?)
|
283
|
+
assert_equal(point1_, diff13_)
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
def test_sym_difference
|
288
|
+
point1_ = @factory.point(11, 12)
|
289
|
+
point2_ = @factory.point(11, 12)
|
290
|
+
point3_ = @factory.point(12, 12)
|
291
|
+
diff12_ = point1_.sym_difference(point2_)
|
292
|
+
diff13_ = point1_.sym_difference(point3_)
|
293
|
+
assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, diff12_)
|
294
|
+
assert(diff12_.is_empty?)
|
295
|
+
assert_kind_of(::RGeo::Geos::MultiPointImpl, diff13_)
|
296
|
+
assert(diff13_.contains?(point1_))
|
297
|
+
assert(diff13_.contains?(point3_))
|
298
|
+
end
|
299
|
+
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|