rgeo 0.1.10 → 0.1.11
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 +13 -0
- data/README.rdoc +6 -0
- data/Version +1 -1
- data/ext/geos_c_impl/factory.c +2 -2
- data/lib/rgeo/features/factory.rb +2 -2
- data/lib/rgeo/features/geometry.rb +26 -4
- data/lib/rgeo/features/geometry_collection.rb +12 -2
- data/lib/rgeo/geography/common/geometry_collection_methods.rb +12 -1
- data/lib/rgeo/geography/common/helper.rb +4 -4
- data/lib/rgeo/geography/common/line_string_methods.rb +1 -1
- data/lib/rgeo/geography/common/point_methods.rb +1 -1
- data/lib/rgeo/geography/common/polygon_methods.rb +1 -1
- data/lib/rgeo/geography/factories.rb +19 -6
- data/lib/rgeo/geography/factory.rb +31 -10
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +26 -26
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +14 -14
- data/lib/rgeo/geography/simple_mercator/projector.rb +1 -1
- data/lib/rgeo/geography/simple_spherical/calculations.rb +61 -0
- data/lib/rgeo/geography/simple_spherical/point_impl.rb +5 -0
- data/lib/rgeo/geos/factory.rb +12 -11
- data/tests/common/geometry_collection_tests.rb +220 -0
- data/tests/common/line_string_tests.rb +300 -0
- data/tests/common/multi_line_string_tests.rb +206 -0
- data/tests/common/multi_point_tests.rb +198 -0
- data/tests/common/multi_polygon_tests.rb +206 -0
- data/tests/common/point_tests.rb +281 -0
- data/tests/common/polygon_tests.rb +232 -0
- data/tests/geos/tc_geometry_collection.rb +5 -169
- data/tests/geos/tc_line_string.rb +4 -252
- data/tests/geos/tc_multi_line_string.rb +5 -154
- data/tests/geos/tc_multi_point.rb +5 -145
- data/tests/geos/tc_multi_polygon.rb +4 -151
- data/tests/geos/tc_point.rb +11 -213
- data/tests/geos/tc_polygon.rb +4 -182
- data/tests/simple_mercator/tc_geometry_collection.rb +62 -0
- data/tests/simple_mercator/tc_line_string.rb +62 -0
- data/tests/simple_mercator/tc_multi_line_string.rb +62 -0
- data/tests/simple_mercator/tc_multi_point.rb +62 -0
- data/tests/simple_mercator/tc_multi_polygon.rb +63 -0
- data/tests/simple_mercator/tc_point.rb +7 -220
- data/tests/simple_mercator/tc_polygon.rb +62 -0
- data/tests/simple_spherical/tc_point.rb +165 -0
- metadata +48 -9
data/lib/rgeo/geos/factory.rb
CHANGED
@@ -66,7 +66,8 @@ module RGeo
|
|
66
66
|
# example, the buffer around a point to be approximated by a
|
67
67
|
# 4-sided polygon. A resolution of 2 would cause that buffer
|
68
68
|
# to be approximated by an 8-sided polygon. The exact behavior
|
69
|
-
# for different kinds of buffers is not
|
69
|
+
# for different kinds of buffers is internal to GEOS, and is not
|
70
|
+
# well-specified as far as I can tell.
|
70
71
|
# <tt>:srid</tt>::
|
71
72
|
# Set the SRID returned by geometries created by this factory.
|
72
73
|
# Default is 0.
|
@@ -202,9 +203,9 @@ module RGeo
|
|
202
203
|
end
|
203
204
|
|
204
205
|
|
205
|
-
# See ::RGeo::Features::Factory#
|
206
|
+
# See ::RGeo::Features::Factory#coerce
|
206
207
|
|
207
|
-
def
|
208
|
+
def coerce(original_, force_new_=false)
|
208
209
|
return nil unless Geos.supported?
|
209
210
|
case original_
|
210
211
|
when GeometryImpl
|
@@ -224,21 +225,21 @@ module RGeo
|
|
224
225
|
PointImpl.create(self, original_.x, original_.y)
|
225
226
|
end
|
226
227
|
when Features::Line
|
227
|
-
LineImpl.create(self, original_.start_point, original_.end_point)
|
228
|
+
LineImpl.create(self, coerce(original_.start_point), coerce(original_.end_point))
|
228
229
|
when Features::LinearRing
|
229
|
-
LinearRingImpl.create(self, original_.points)
|
230
|
+
LinearRingImpl.create(self, original_.points.map{ |g_| coerce(g_) })
|
230
231
|
when Features::LineString
|
231
|
-
LineStringImpl.create(self, original_.points)
|
232
|
+
LineStringImpl.create(self, original_.points.map{ |g_| coerce(g_) })
|
232
233
|
when Features::Polygon
|
233
|
-
PolygonImpl.create(self, original_.exterior_ring, original_.interior_rings)
|
234
|
+
PolygonImpl.create(self, coerce(original_.exterior_ring), original_.interior_rings.map{ |g_| coerce(g_) })
|
234
235
|
when Features::MultiPoint
|
235
|
-
MultiPointImpl.create(self, original_.to_a)
|
236
|
+
MultiPointImpl.create(self, original_.to_a.map{ |g_| coerce(g_) })
|
236
237
|
when Features::MultiLineString
|
237
|
-
MultiLineStringImpl.create(self, original_.to_a)
|
238
|
+
MultiLineStringImpl.create(self, original_.to_a.map{ |g_| coerce(g_) })
|
238
239
|
when Features::MultiPolygon
|
239
|
-
MultiPolygonImpl.create(self, original_.to_a)
|
240
|
+
MultiPolygonImpl.create(self, original_.to_a.map{ |g_| coerce(g_) })
|
240
241
|
when Features::GeometryCollection
|
241
|
-
GeometryCollectionImpl.create(self, original_.to_a)
|
242
|
+
GeometryCollectionImpl.create(self, original_.to_a.map{ |g_| coerce(g_) })
|
242
243
|
else
|
243
244
|
nil
|
244
245
|
end
|
@@ -0,0 +1,220 @@
|
|
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::Features::GeometryCollection === geom_)
|
63
|
+
assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
|
64
|
+
assert_equal(2, geom_.num_geometries)
|
65
|
+
assert_equal([@point1, @line1], geom_.to_a)
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def test_creation_empty
|
70
|
+
geom_ = @factory.collection([])
|
71
|
+
assert_not_nil(geom_)
|
72
|
+
assert(::RGeo::Features::GeometryCollection === geom_)
|
73
|
+
assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
|
74
|
+
assert_equal(0, geom_.num_geometries)
|
75
|
+
assert_equal([], geom_.to_a)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def test_creation_save_klass
|
80
|
+
geom_ = @factory.collection([@point1, @line3])
|
81
|
+
assert_not_nil(geom_)
|
82
|
+
assert(::RGeo::Features::GeometryCollection === geom_)
|
83
|
+
assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
|
84
|
+
assert_equal(2, geom_.num_geometries)
|
85
|
+
assert(geom_[1].eql?(@line3))
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def test_creation_compound
|
90
|
+
geom1_ = @factory.collection([@point1, @line1])
|
91
|
+
geom2_ = @factory.collection([@point2, geom1_])
|
92
|
+
assert_not_nil(geom2_)
|
93
|
+
assert(::RGeo::Features::GeometryCollection === geom2_)
|
94
|
+
assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
|
95
|
+
assert_equal(2, geom2_.num_geometries)
|
96
|
+
assert(geom2_[1].eql?(geom1_))
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def test_creation_compound_save_klass
|
101
|
+
geom1_ = @factory.collection([@point1, @line3])
|
102
|
+
geom2_ = @factory.collection([@point2, geom1_])
|
103
|
+
::GC.start
|
104
|
+
assert_not_nil(geom2_)
|
105
|
+
assert(::RGeo::Features::GeometryCollection === geom2_)
|
106
|
+
assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
|
107
|
+
assert_equal(2, geom2_.num_geometries)
|
108
|
+
assert(::RGeo::Features::Line === geom2_[1][1])
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def test_fully_equal
|
113
|
+
geom1_ = @factory.collection([@point1, @line1])
|
114
|
+
geom2_ = @factory.collection([@point1, @line1])
|
115
|
+
assert(geom1_.eql?(geom2_))
|
116
|
+
assert(geom1_.equals?(geom2_))
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def test_geometrically_equal
|
121
|
+
geom1_ = @factory.collection([@point2, @line2])
|
122
|
+
geom2_ = @factory.collection([@point2, @line1, @line2])
|
123
|
+
assert(!geom1_.eql?(geom2_))
|
124
|
+
assert(geom1_.equals?(geom2_))
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def test_empty_equal
|
129
|
+
geom1_ = @factory.collection([])
|
130
|
+
geom2_ = @factory.collection([])
|
131
|
+
assert(geom1_.eql?(geom2_))
|
132
|
+
assert(geom1_.equals?(geom2_))
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
def test_not_equal
|
137
|
+
geom1_ = @factory.collection([@point1, @line1])
|
138
|
+
geom2_ = @factory.collection([@point2, @line1])
|
139
|
+
assert(!geom1_.eql?(geom2_))
|
140
|
+
assert(!geom1_.equals?(geom2_))
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
def test_wkt_creation_simple
|
145
|
+
parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(-4 2, -5 3))')
|
146
|
+
built_geom_ = @factory.collection([@point1, @line1])
|
147
|
+
assert_equal(built_geom_, parsed_geom_)
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def test_wkt_creation_empty
|
152
|
+
parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION EMPTY')
|
153
|
+
assert_equal(0, parsed_geom_.num_geometries)
|
154
|
+
assert_equal([], parsed_geom_.to_a)
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
def test_clone
|
159
|
+
geom1_ = @factory.collection([@point1, @line1])
|
160
|
+
geom2_ = geom1_.clone
|
161
|
+
assert_equal(geom1_, geom2_)
|
162
|
+
assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
|
163
|
+
assert_equal(2, geom2_.num_geometries)
|
164
|
+
assert_equal([@point1, @line1], geom2_.to_a)
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
def test_type_check
|
169
|
+
geom1_ = @factory.collection([@point1, @line1])
|
170
|
+
assert(::RGeo::Features::Geometry.check_type(geom1_))
|
171
|
+
assert(!::RGeo::Features::Point.check_type(geom1_))
|
172
|
+
assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
|
173
|
+
assert(!::RGeo::Features::MultiPoint.check_type(geom1_))
|
174
|
+
geom2_ = @factory.collection([@point1, @point2])
|
175
|
+
assert(::RGeo::Features::Geometry.check_type(geom2_))
|
176
|
+
assert(!::RGeo::Features::Point.check_type(geom2_))
|
177
|
+
assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
|
178
|
+
assert(!::RGeo::Features::MultiPoint.check_type(geom2_))
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def test_as_text_wkt_round_trip
|
183
|
+
geom1_ = @factory.collection([@point1, @line1])
|
184
|
+
text_ = geom1_.as_text
|
185
|
+
geom2_ = @factory.parse_wkt(text_)
|
186
|
+
assert_equal(geom1_, geom2_)
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def test_as_binary_wkb_round_trip
|
191
|
+
geom1_ = @factory.collection([@point1, @line1])
|
192
|
+
binary_ = geom1_.as_binary
|
193
|
+
geom2_ = @factory.parse_wkb(binary_)
|
194
|
+
assert_equal(geom1_, geom2_)
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
def test_dimension
|
199
|
+
geom1_ = @factory.collection([@point1, @line1])
|
200
|
+
assert_equal(1, geom1_.dimension)
|
201
|
+
geom2_ = @factory.collection([@point1, @point2])
|
202
|
+
assert_equal(0, geom2_.dimension)
|
203
|
+
geom3_ = @factory.collection([])
|
204
|
+
assert_equal(-1, geom3_.dimension)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def test_is_empty
|
209
|
+
geom1_ = @factory.collection([@point1, @line1])
|
210
|
+
assert(!geom1_.is_empty?)
|
211
|
+
geom2_ = @factory.collection([])
|
212
|
+
assert(geom2_.is_empty?)
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,300 @@
|
|
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_success
|
48
|
+
point1_ = @factory.point(0, 0)
|
49
|
+
point2_ = @factory.point(0, 1)
|
50
|
+
point3_ = @factory.point(1, 0)
|
51
|
+
line1_ = @factory.line_string([point1_, point2_])
|
52
|
+
assert_not_nil(line1_)
|
53
|
+
assert_equal(::RGeo::Features::LineString, line1_.geometry_type)
|
54
|
+
assert_equal(2, line1_.num_points)
|
55
|
+
assert_equal(point1_, line1_.point_n(0))
|
56
|
+
assert_equal(point2_, line1_.point_n(1))
|
57
|
+
line2_ = @factory.line_string([point1_, point2_, point3_])
|
58
|
+
assert_not_nil(line2_)
|
59
|
+
assert_equal(::RGeo::Features::LineString, line2_.geometry_type)
|
60
|
+
assert_equal(3, line2_.num_points)
|
61
|
+
assert_equal(point1_, line2_.point_n(0))
|
62
|
+
assert_equal(point2_, line2_.point_n(1))
|
63
|
+
assert_equal(point3_, line2_.point_n(2))
|
64
|
+
line3_ = @factory.line_string([point1_, point1_])
|
65
|
+
assert_not_nil(line3_)
|
66
|
+
assert_equal(::RGeo::Features::LineString, line3_.geometry_type)
|
67
|
+
assert_equal(2, line3_.num_points)
|
68
|
+
assert_equal(point1_, line3_.point_n(0))
|
69
|
+
assert_equal(point1_, line3_.point_n(1))
|
70
|
+
line4_ = @factory.line_string([])
|
71
|
+
assert_not_nil(line4_)
|
72
|
+
assert_equal(::RGeo::Features::LineString, line4_.geometry_type)
|
73
|
+
assert_equal(0, line4_.num_points)
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def test_creation_line_string
|
78
|
+
point1_ = @factory.point(0, 0)
|
79
|
+
point2_ = @factory.point(0, 1)
|
80
|
+
point3_ = @factory.point(1, 1)
|
81
|
+
line1_ = @factory.line_string([point1_, point2_, point3_])
|
82
|
+
assert_not_nil(line1_)
|
83
|
+
assert(::RGeo::Features::LineString === line1_)
|
84
|
+
assert(!(::RGeo::Features::LinearRing === line1_))
|
85
|
+
assert(!(::RGeo::Features::Line === line1_))
|
86
|
+
assert_equal(::RGeo::Features::LineString, line1_.geometry_type)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def test_creation_linear_ring
|
91
|
+
point1_ = @factory.point(0, 0)
|
92
|
+
point2_ = @factory.point(0, 1)
|
93
|
+
point3_ = @factory.point(1, 0)
|
94
|
+
line1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
|
95
|
+
assert_not_nil(line1_)
|
96
|
+
assert(line1_.is_ring?)
|
97
|
+
assert(::RGeo::Features::LinearRing === line1_)
|
98
|
+
assert_equal(::RGeo::Features::LinearRing, line1_.geometry_type)
|
99
|
+
line2_ = @factory.linear_ring([point1_, point2_, point3_])
|
100
|
+
assert_not_nil(line2_)
|
101
|
+
assert(line2_.is_ring?)
|
102
|
+
assert(::RGeo::Features::LinearRing === line2_)
|
103
|
+
assert_equal(4, line2_.num_points)
|
104
|
+
assert_equal(::RGeo::Features::LinearRing, line2_.geometry_type)
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def test_creation_line
|
109
|
+
point1_ = @factory.point(0, 0)
|
110
|
+
point2_ = @factory.point(0, 1)
|
111
|
+
line1_ = @factory.line(point1_, point2_)
|
112
|
+
assert_not_nil(line1_)
|
113
|
+
assert(::RGeo::Features::Line === line1_)
|
114
|
+
assert_equal(::RGeo::Features::Line, line1_.geometry_type)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def test_creation_errors
|
119
|
+
point1_ = @factory.point(0, 0)
|
120
|
+
collection_ = point1_.boundary
|
121
|
+
line1_ = @factory.line_string([point1_])
|
122
|
+
assert_nil(line1_)
|
123
|
+
line2_ = @factory.line_string([point1_, collection_])
|
124
|
+
assert_nil(line2_)
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def test_fully_equal
|
129
|
+
point1_ = @factory.point(0, 0)
|
130
|
+
point2_ = @factory.point(0, 1)
|
131
|
+
point3_ = @factory.point(1, 0)
|
132
|
+
line1_ = @factory.line_string([point1_, point2_, point3_])
|
133
|
+
point4_ = @factory.point(0, 0)
|
134
|
+
point5_ = @factory.point(0, 1)
|
135
|
+
point6_ = @factory.point(1, 0)
|
136
|
+
line2_ = @factory.line_string([point4_, point5_, point6_])
|
137
|
+
assert(line1_.eql?(line2_))
|
138
|
+
assert(line1_.equals?(line2_))
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
def test_geometrically_equal_but_different_type
|
143
|
+
point1_ = @factory.point(0, 0)
|
144
|
+
point2_ = @factory.point(0, 1)
|
145
|
+
line1_ = @factory.line_string([point1_, point2_])
|
146
|
+
point4_ = @factory.point(0, 0)
|
147
|
+
point5_ = @factory.point(0, 1)
|
148
|
+
line2_ = @factory.line(point4_, point5_)
|
149
|
+
assert(!line1_.eql?(line2_))
|
150
|
+
assert(line1_.equals?(line2_))
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
def test_geometrically_equal_but_different_type2
|
155
|
+
point1_ = @factory.point(0, 0)
|
156
|
+
point2_ = @factory.point(0, 1)
|
157
|
+
point3_ = @factory.point(1, 0)
|
158
|
+
line1_ = @factory.line_string([point1_, point2_, point3_, point1_])
|
159
|
+
point4_ = @factory.point(0, 0)
|
160
|
+
point5_ = @factory.point(0, 1)
|
161
|
+
point6_ = @factory.point(1, 0)
|
162
|
+
line2_ = @factory.linear_ring([point4_, point5_, point6_, point4_])
|
163
|
+
assert(!line1_.eql?(line2_))
|
164
|
+
assert(line1_.equals?(line2_))
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
def test_geometrically_equal_but_different_overlap
|
169
|
+
point1_ = @factory.point(0, 0)
|
170
|
+
point2_ = @factory.point(0, 1)
|
171
|
+
point3_ = @factory.point(1, 0)
|
172
|
+
line1_ = @factory.line_string([point1_, point2_, point3_])
|
173
|
+
point4_ = @factory.point(0, 0)
|
174
|
+
point5_ = @factory.point(0, 1)
|
175
|
+
point6_ = @factory.point(1, 0)
|
176
|
+
line2_ = @factory.line_string([point4_, point5_, point6_, point5_])
|
177
|
+
assert(!line1_.eql?(line2_))
|
178
|
+
assert(line1_.equals?(line2_))
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def test_empty_equal
|
183
|
+
line1_ = @factory.line_string([])
|
184
|
+
line2_ = @factory.line_string([])
|
185
|
+
assert(line1_.eql?(line2_))
|
186
|
+
assert(line1_.equals?(line2_))
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def test_not_equal
|
191
|
+
point1_ = @factory.point(0, 0)
|
192
|
+
point2_ = @factory.point(0, 1)
|
193
|
+
line1_ = @factory.line_string([point1_, point2_])
|
194
|
+
point4_ = @factory.point(0, 0)
|
195
|
+
point5_ = @factory.point(0, 1)
|
196
|
+
point6_ = @factory.point(1, 0)
|
197
|
+
line2_ = @factory.line_string([point4_, point5_, point6_])
|
198
|
+
assert(!line1_.eql?(line2_))
|
199
|
+
assert(!line1_.equals?(line2_))
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
def test_wkt_creation
|
204
|
+
line1_ = @factory.parse_wkt('LINESTRING(21 22, 11 12)')
|
205
|
+
assert_equal(@factory.point(21, 22), line1_.point_n(0))
|
206
|
+
assert_equal(@factory.point(11, 12), line1_.point_n(1))
|
207
|
+
assert_equal(2, line1_.num_points)
|
208
|
+
line2_ = @factory.parse_wkt('LINESTRING(-1 -1, 21 22, 11 12, -1 -1)')
|
209
|
+
assert_equal(@factory.point(-1, -1), line2_.point_n(0))
|
210
|
+
assert_equal(@factory.point(21, 22), line2_.point_n(1))
|
211
|
+
assert_equal(@factory.point(11, 12), line2_.point_n(2))
|
212
|
+
assert_equal(@factory.point(-1, -1), line2_.point_n(3))
|
213
|
+
assert_equal(4, line2_.num_points)
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
def test_clone
|
218
|
+
point1_ = @factory.point(0, 0)
|
219
|
+
point2_ = @factory.point(0, 1)
|
220
|
+
line1_ = @factory.line_string([point1_, point2_])
|
221
|
+
line2_ = line1_.clone
|
222
|
+
assert_equal(line1_, line2_)
|
223
|
+
assert_equal(2, line2_.num_points)
|
224
|
+
assert_equal(point1_, line2_.point_n(0))
|
225
|
+
assert_equal(point2_, line2_.point_n(1))
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
def test_type_check
|
230
|
+
point1_ = @factory.point(0, 0)
|
231
|
+
point2_ = @factory.point(0, 1)
|
232
|
+
line_ = @factory.line_string([point1_, point2_])
|
233
|
+
assert(::RGeo::Features::Geometry.check_type(line_))
|
234
|
+
assert(!::RGeo::Features::Point.check_type(line_))
|
235
|
+
assert(!::RGeo::Features::GeometryCollection.check_type(line_))
|
236
|
+
assert(::RGeo::Features::Curve.check_type(line_))
|
237
|
+
assert(::RGeo::Features::LineString.check_type(line_))
|
238
|
+
assert(!::RGeo::Features::LinearRing.check_type(line_))
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
def test_as_text_wkt_round_trip
|
243
|
+
point1_ = @factory.point(0, 0)
|
244
|
+
point2_ = @factory.point(0, 1)
|
245
|
+
line1_ = @factory.line_string([point1_, point2_])
|
246
|
+
text_ = line1_.as_text
|
247
|
+
line2_ = @factory.parse_wkt(text_)
|
248
|
+
assert_equal(line2_, line1_)
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
def test_as_binary_wkb_round_trip
|
253
|
+
point1_ = @factory.point(-42, 0)
|
254
|
+
point2_ = @factory.point(0, 193)
|
255
|
+
line1_ = @factory.line_string([point1_, point2_])
|
256
|
+
binary_ = line1_.as_binary
|
257
|
+
line2_ = @factory.parse_wkb(binary_)
|
258
|
+
assert_equal(line2_, line1_)
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
def test_empty_as_text_wkt_round_trip
|
263
|
+
line1_ = @factory.line_string([])
|
264
|
+
text_ = line1_.as_text
|
265
|
+
line2_ = @factory.parse_wkt(text_)
|
266
|
+
assert(line2_.is_empty?)
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
def test_empty_as_binary_wkb_round_trip
|
271
|
+
line1_ = @factory.line_string([])
|
272
|
+
binary_ = line1_.as_binary
|
273
|
+
line2_ = @factory.parse_wkb(binary_)
|
274
|
+
assert(line2_.is_empty?)
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
def test_dimension
|
279
|
+
point1_ = @factory.point(-42, 0)
|
280
|
+
point2_ = @factory.point(0, 193)
|
281
|
+
line1_ = @factory.line_string([point1_, point2_])
|
282
|
+
assert_equal(1, line1_.dimension)
|
283
|
+
end
|
284
|
+
|
285
|
+
|
286
|
+
def test_is_empty
|
287
|
+
point1_ = @factory.point(-42, 0)
|
288
|
+
point2_ = @factory.point(0, 193)
|
289
|
+
line1_ = @factory.line_string([point1_, point2_])
|
290
|
+
assert(!line1_.is_empty?)
|
291
|
+
line2_ = @factory.line_string([])
|
292
|
+
assert(line2_.is_empty?)
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|