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,480 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Tests for WKT parser
|
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 WKRep # :nodoc:
|
44
|
+
|
45
|
+
class TestWKTParser < ::Test::Unit::TestCase # :nodoc:
|
46
|
+
|
47
|
+
|
48
|
+
def test_point_2d
|
49
|
+
parser_ = ::RGeo::WKRep::WKTParser.new
|
50
|
+
obj_ = parser_.parse('POINT(1 2)')
|
51
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
52
|
+
assert_equal(1, obj_.x)
|
53
|
+
assert_equal(2, obj_.y)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def test_values_fractional
|
58
|
+
parser_ = ::RGeo::WKRep::WKTParser.new
|
59
|
+
obj_ = parser_.parse('POINT(1.000 2.5)')
|
60
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
61
|
+
assert_equal(1.0, obj_.x)
|
62
|
+
assert_equal(2.5, obj_.y)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def test_values_fractional2
|
67
|
+
parser_ = ::RGeo::WKRep::WKTParser.new
|
68
|
+
obj_ = parser_.parse('POINT(1. .5)')
|
69
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
70
|
+
assert_equal(1.0, obj_.x)
|
71
|
+
assert_equal(0.5, obj_.y)
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def test_values_negative
|
76
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
77
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
78
|
+
obj_ = parser_.parse('POINT(-1. -.5 -5.5)')
|
79
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
80
|
+
assert_equal(-1.0, obj_.x)
|
81
|
+
assert_equal(-0.5, obj_.y)
|
82
|
+
assert_equal(-5.5, obj_.z)
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def test_point_square_brackets
|
87
|
+
parser_ = ::RGeo::WKRep::WKTParser.new
|
88
|
+
obj_ = parser_.parse('POINT[1 2]')
|
89
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
90
|
+
assert_equal(1, obj_.x)
|
91
|
+
assert_equal(2, obj_.y)
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def test_point_empty
|
96
|
+
parser_ = ::RGeo::WKRep::WKTParser.new
|
97
|
+
obj_ = parser_.parse('POINT EMPTY')
|
98
|
+
assert_equal(::RGeo::Feature::MultiPoint, obj_.geometry_type)
|
99
|
+
assert_equal(0, obj_.num_geometries)
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def test_point_with_z
|
104
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
105
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
106
|
+
obj_ = parser_.parse('POINT(1 2 3)')
|
107
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
108
|
+
assert_equal(3, obj_.z)
|
109
|
+
assert_nil(obj_.m)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def test_point_with_m
|
114
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_m_coordinate => true)
|
115
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
116
|
+
obj_ = parser_.parse('POINT(1 2 3)')
|
117
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
118
|
+
assert_equal(3, obj_.m)
|
119
|
+
assert_nil(obj_.z)
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def test_point_with_too_many_coords
|
124
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
125
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
126
|
+
assert_raise(::RGeo::Error::ParseError) do
|
127
|
+
obj_ = parser_.parse('POINT(1 2 3)')
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def test_point_wkt12_z
|
133
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
134
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
135
|
+
obj_ = parser_.parse('POINT Z(1 2 3)')
|
136
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
137
|
+
assert_equal(3, obj_.z)
|
138
|
+
assert_nil(obj_.m)
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
def test_point_wkt12_z_unsupported_factory
|
143
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
144
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
145
|
+
assert_raise(::RGeo::Error::ParseError) do
|
146
|
+
obj_ = parser_.parse('POINT Z(1 2 3)')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def test_point_wkt12_m
|
152
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_m_coordinate => true)
|
153
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
154
|
+
obj_ = parser_.parse('POINT M(1 2 3)')
|
155
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
156
|
+
assert_equal(3, obj_.m)
|
157
|
+
assert_nil(obj_.z)
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def test_point_wkt12_m_with_factory_zm
|
162
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true, :has_m_coordinate => true)
|
163
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
164
|
+
obj_ = parser_.parse('POINT M(1 2 3)')
|
165
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
166
|
+
assert_equal(3, obj_.m)
|
167
|
+
assert_equal(0, obj_.z)
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
def test_point_wkt12_m_too_many_coords
|
172
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_m_coordinate => true)
|
173
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
174
|
+
assert_raise(::RGeo::Error::ParseError) do
|
175
|
+
obj_ = parser_.parse('POINT M(1 2 3 4)')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
def test_point_wkt12_zm
|
181
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true, :has_m_coordinate => true)
|
182
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
183
|
+
obj_ = parser_.parse('POINT ZM(1 2 3 4)')
|
184
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
185
|
+
assert_equal(3, obj_.z)
|
186
|
+
assert_equal(4, obj_.m)
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def test_point_wkt12_zm_not_enough_coords
|
191
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true, :has_m_coordinate => true)
|
192
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
193
|
+
assert_raise(::RGeo::Error::ParseError) do
|
194
|
+
obj_ = parser_.parse('POINT ZM(1 2 3)')
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
def test_point_ewkt_z
|
200
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
201
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_ewkt => true)
|
202
|
+
obj_ = parser_.parse('POINT(1 2 3)')
|
203
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
204
|
+
assert_equal(3, obj_.z)
|
205
|
+
assert_nil(obj_.m)
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
def test_point_ewkt_m
|
210
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_m_coordinate => true)
|
211
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_ewkt => true)
|
212
|
+
obj_ = parser_.parse('POINTM(1 2 3)')
|
213
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
214
|
+
assert_equal(3, obj_.m)
|
215
|
+
assert_nil(obj_.z)
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
def test_point_ewkt_with_srid
|
220
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(::RGeo::Cartesian.method(:preferred_factory), :support_ewkt => true)
|
221
|
+
obj_ = parser_.parse('SRID=1000;POINTM(1 2 3)')
|
222
|
+
assert_equal(::RGeo::Feature::Point, obj_.geometry_type)
|
223
|
+
assert_equal(3, obj_.m)
|
224
|
+
assert_nil(obj_.z)
|
225
|
+
assert_equal(1000, obj_.srid)
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
def test_point_ewkt_m_too_many_coords
|
230
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_m_coordinate => true)
|
231
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_ewkt => true)
|
232
|
+
assert_raise(::RGeo::Error::ParseError) do
|
233
|
+
obj_ = parser_.parse('POINTM(1 2 3 4)')
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
def test_point_strict_wkt11_with_z
|
239
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
240
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :strict_wkt11 => true)
|
241
|
+
assert_raise(::RGeo::Error::ParseError) do
|
242
|
+
obj_ = parser_.parse('POINT(1 2 3)')
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
def test_point_non_ewkt_with_srid
|
248
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
249
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
250
|
+
parser_.factory_generator = ::RGeo::Cartesian.method(:preferred_factory)
|
251
|
+
assert_raise(::RGeo::Error::ParseError) do
|
252
|
+
obj_ = parser_.parse('SRID=1000;POINT(1 2)')
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
def test_linestring_basic
|
258
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
259
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
260
|
+
obj_ = parser_.parse('LINESTRING(1 2, 3 4, 5 6)')
|
261
|
+
assert_equal(::RGeo::Feature::LineString, obj_.geometry_type)
|
262
|
+
assert_equal(3, obj_.num_points)
|
263
|
+
assert_equal(1, obj_.point_n(0).x)
|
264
|
+
assert_equal(6, obj_.point_n(2).y)
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
def test_linestring_with_z
|
269
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
270
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
271
|
+
obj_ = parser_.parse('LINESTRING(1 2 3, 4 5 6,7 8 9)')
|
272
|
+
assert_equal(::RGeo::Feature::LineString, obj_.geometry_type)
|
273
|
+
assert_equal(3, obj_.num_points)
|
274
|
+
assert_equal(1, obj_.point_n(0).x)
|
275
|
+
assert_equal(9, obj_.point_n(2).z)
|
276
|
+
end
|
277
|
+
|
278
|
+
|
279
|
+
def test_linestring_with_inconsistent_coords
|
280
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
281
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
282
|
+
assert_raise(::RGeo::Error::ParseError) do
|
283
|
+
obj_ = parser_.parse('LINESTRING(1 2 3, 4 5,7 8 9)')
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
def test_linestring_wkt12_m
|
289
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true, :has_m_coordinate => true)
|
290
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
291
|
+
obj_ = parser_.parse('LINESTRING M(1 2 3,5 6 7)')
|
292
|
+
assert_equal(::RGeo::Feature::LineString, obj_.geometry_type)
|
293
|
+
assert_equal(2, obj_.num_points)
|
294
|
+
assert_equal(0, obj_.point_n(0).z)
|
295
|
+
assert_equal(3, obj_.point_n(0).m)
|
296
|
+
assert_equal(0, obj_.point_n(1).z)
|
297
|
+
assert_equal(7, obj_.point_n(1).m)
|
298
|
+
end
|
299
|
+
|
300
|
+
|
301
|
+
def test_linestring_ewkt_with_srid
|
302
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(::RGeo::Cartesian.method(:preferred_factory), :support_ewkt => true)
|
303
|
+
obj_ = parser_.parse('SRID=1000;LINESTRINGM(1 2 3, 4 5 6)')
|
304
|
+
assert_equal(::RGeo::Feature::LineString, obj_.geometry_type)
|
305
|
+
assert_equal(3, obj_.point_n(0).m)
|
306
|
+
assert_nil(obj_.point_n(0).z)
|
307
|
+
assert_equal(1000, obj_.srid)
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
def test_linestring_empty
|
312
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
313
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
314
|
+
obj_ = parser_.parse('LINESTRING EMPTY')
|
315
|
+
assert_equal(::RGeo::Feature::LineString, obj_.geometry_type)
|
316
|
+
assert_equal(0, obj_.num_points)
|
317
|
+
end
|
318
|
+
|
319
|
+
|
320
|
+
def test_polygon_basic
|
321
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
322
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
323
|
+
obj_ = parser_.parse('POLYGON((1 2, 3 4, 5 7, 1 2))')
|
324
|
+
assert_equal(::RGeo::Feature::Polygon, obj_.geometry_type)
|
325
|
+
assert_equal(4, obj_.exterior_ring.num_points)
|
326
|
+
assert_equal(1, obj_.exterior_ring.point_n(0).x)
|
327
|
+
assert_equal(7, obj_.exterior_ring.point_n(2).y)
|
328
|
+
end
|
329
|
+
|
330
|
+
|
331
|
+
def test_polygon_with_holes_and_z
|
332
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
333
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
334
|
+
obj_ = parser_.parse('POLYGON((0 0 -1, 10 0 -2, 10 10 -3, 0 10 -4, 0 0 -5),(1 1 -6, 2 3 -7, 3 1 -8, 1 1 -9))')
|
335
|
+
assert_equal(::RGeo::Feature::Polygon, obj_.geometry_type)
|
336
|
+
assert_equal(5, obj_.exterior_ring.num_points)
|
337
|
+
assert_equal(0, obj_.exterior_ring.point_n(0).x)
|
338
|
+
assert_equal(10, obj_.exterior_ring.point_n(2).y)
|
339
|
+
assert_equal(1, obj_.num_interior_rings)
|
340
|
+
assert_equal(-6, obj_.interior_ring_n(0).point_n(0).z)
|
341
|
+
assert_equal(-7, obj_.interior_ring_n(0).point_n(1).z)
|
342
|
+
end
|
343
|
+
|
344
|
+
|
345
|
+
def test_polygon_empty
|
346
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
347
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
348
|
+
obj_ = parser_.parse('POLYGON EMPTY')
|
349
|
+
assert_equal(::RGeo::Feature::Polygon, obj_.geometry_type)
|
350
|
+
assert_equal(0, obj_.exterior_ring.num_points)
|
351
|
+
end
|
352
|
+
|
353
|
+
|
354
|
+
def test_multipoint_basic
|
355
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
356
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
357
|
+
obj_ = parser_.parse('MULTIPOINT((1 2),(0 3))')
|
358
|
+
assert_equal(::RGeo::Feature::MultiPoint, obj_.geometry_type)
|
359
|
+
assert_equal(2, obj_.num_geometries)
|
360
|
+
assert_equal(1, obj_[0].x)
|
361
|
+
assert_equal(3, obj_[1].y)
|
362
|
+
end
|
363
|
+
|
364
|
+
|
365
|
+
def test_multipoint_empty
|
366
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
367
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
368
|
+
obj_ = parser_.parse('MULTIPOINT EMPTY')
|
369
|
+
assert_equal(::RGeo::Feature::MultiPoint, obj_.geometry_type)
|
370
|
+
assert_equal(0, obj_.num_geometries)
|
371
|
+
end
|
372
|
+
|
373
|
+
|
374
|
+
def test_multilinestring_basic
|
375
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
376
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
377
|
+
obj_ = parser_.parse('MULTILINESTRING((1 2, 3 4, 5 6),(0 -3, 0 -4, 1 -5))')
|
378
|
+
assert_equal(::RGeo::Feature::MultiLineString, obj_.geometry_type)
|
379
|
+
assert_equal(2, obj_.num_geometries)
|
380
|
+
assert_equal(1, obj_[0].point_n(0).x)
|
381
|
+
assert_equal(-5, obj_[1].point_n(2).y)
|
382
|
+
end
|
383
|
+
|
384
|
+
|
385
|
+
def test_multilinestring_empty
|
386
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
387
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
388
|
+
obj_ = parser_.parse('MULTILINESTRING EMPTY')
|
389
|
+
assert_equal(::RGeo::Feature::MultiLineString, obj_.geometry_type)
|
390
|
+
assert_equal(0, obj_.num_geometries)
|
391
|
+
end
|
392
|
+
|
393
|
+
|
394
|
+
def test_multipolygon_basic
|
395
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
396
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
397
|
+
obj_ = parser_.parse('MULTIPOLYGON(((-1 -2 0, -3 -4 0, -5 -7 0, -1 -2 0)),((0 0 -1, 10 0 -2, 10 10 -3, 0 10 -4, 0 0 -5),(1 1 -6, 2 3 -7, 3 1 -8, 1 1 -9)))')
|
398
|
+
assert_equal(::RGeo::Feature::MultiPolygon, obj_.geometry_type)
|
399
|
+
assert_equal(2, obj_.num_geometries)
|
400
|
+
assert_equal(4, obj_[0].exterior_ring.num_points)
|
401
|
+
assert_equal(-1, obj_[0].exterior_ring.point_n(0).x)
|
402
|
+
assert_equal(-7, obj_[0].exterior_ring.point_n(2).y)
|
403
|
+
assert_equal(5, obj_[1].exterior_ring.num_points)
|
404
|
+
assert_equal(0, obj_[1].exterior_ring.point_n(0).x)
|
405
|
+
assert_equal(10, obj_[1].exterior_ring.point_n(2).y)
|
406
|
+
assert_equal(1, obj_[1].num_interior_rings)
|
407
|
+
assert_equal(-6, obj_[1].interior_ring_n(0).point_n(0).z)
|
408
|
+
assert_equal(-7, obj_[1].interior_ring_n(0).point_n(1).z)
|
409
|
+
end
|
410
|
+
|
411
|
+
|
412
|
+
def test_multipolygon_empty
|
413
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
414
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
415
|
+
obj_ = parser_.parse('MULTIPOLYGON EMPTY')
|
416
|
+
assert_equal(::RGeo::Feature::MultiPolygon, obj_.geometry_type)
|
417
|
+
assert_equal(0, obj_.num_geometries)
|
418
|
+
end
|
419
|
+
|
420
|
+
|
421
|
+
def test_collection_basic
|
422
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
423
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
424
|
+
obj_ = parser_.parse('GEOMETRYCOLLECTION(POINT(-1 -2),LINESTRING(1 2, 3 4, 5 6))')
|
425
|
+
assert_equal(::RGeo::Feature::GeometryCollection, obj_.geometry_type)
|
426
|
+
assert_equal(2, obj_.num_geometries)
|
427
|
+
assert_equal(::RGeo::Feature::Point, obj_[0].geometry_type)
|
428
|
+
assert_equal(-1, obj_[0].x)
|
429
|
+
assert_equal(::RGeo::Feature::LineString, obj_[1].geometry_type)
|
430
|
+
assert_equal(1, obj_[1].point_n(0).x)
|
431
|
+
assert_equal(6, obj_[1].point_n(2).y)
|
432
|
+
end
|
433
|
+
|
434
|
+
|
435
|
+
def test_collection_z
|
436
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
437
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
438
|
+
obj_ = parser_.parse('GEOMETRYCOLLECTION(POINT(-1 -2 0),LINESTRING(1 2 0, 3 4 0, 5 6 0))')
|
439
|
+
assert_equal(::RGeo::Feature::GeometryCollection, obj_.geometry_type)
|
440
|
+
assert_equal(2, obj_.num_geometries)
|
441
|
+
assert_equal(::RGeo::Feature::Point, obj_[0].geometry_type)
|
442
|
+
assert_equal(-1, obj_[0].x)
|
443
|
+
assert_equal(::RGeo::Feature::LineString, obj_[1].geometry_type)
|
444
|
+
assert_equal(1, obj_[1].point_n(0).x)
|
445
|
+
assert_equal(6, obj_[1].point_n(2).y)
|
446
|
+
end
|
447
|
+
|
448
|
+
|
449
|
+
def test_collection_dimension_mismatch
|
450
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true)
|
451
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
452
|
+
assert_raise(::RGeo::Error::ParseError) do
|
453
|
+
obj_ = parser_.parse('GEOMETRYCOLLECTION(POINT(-1 -2),LINESTRING(1 2 0, 3 4 0, 5 6 0))')
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
|
458
|
+
def test_collection_wkt12_type_mismatch
|
459
|
+
factory_ = ::RGeo::Cartesian.preferred_factory(:has_z_coordinate => true, :has_m_coordinate => true)
|
460
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_, :support_wkt12 => true)
|
461
|
+
assert_raise(::RGeo::Error::ParseError) do
|
462
|
+
obj_ = parser_.parse('GEOMETRYCOLLECTION Z(POINT Z(-1 -2 0),LINESTRING M(1 2 0, 3 4 0, 5 6 0))')
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
|
467
|
+
def test_collection_empty
|
468
|
+
factory_ = ::RGeo::Cartesian.preferred_factory
|
469
|
+
parser_ = ::RGeo::WKRep::WKTParser.new(factory_)
|
470
|
+
obj_ = parser_.parse('GEOMETRYCOLLECTION EMPTY')
|
471
|
+
assert_equal(::RGeo::Feature::GeometryCollection, obj_.geometry_type)
|
472
|
+
assert_equal(0, obj_.num_geometries)
|
473
|
+
end
|
474
|
+
|
475
|
+
|
476
|
+
end
|
477
|
+
|
478
|
+
end
|
479
|
+
end
|
480
|
+
end
|