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,235 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for GeometryCollection features
|
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
|
+
module RGeo
|
38
|
+
|
39
|
+
module ImplHelper # :nodoc:
|
40
|
+
|
41
|
+
|
42
|
+
module BasicGeometryCollectionMethods # :nodoc:
|
43
|
+
|
44
|
+
|
45
|
+
def initialize(factory_, elements_)
|
46
|
+
_set_factory(factory_)
|
47
|
+
@elements = elements_.map do |elem_|
|
48
|
+
elem_ = Feature.cast(elem_, factory_)
|
49
|
+
unless elem_
|
50
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}"
|
51
|
+
end
|
52
|
+
elem_
|
53
|
+
end
|
54
|
+
_validate_geometry
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def eql?(rhs_)
|
59
|
+
if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @elements.size == rhs_.num_geometries
|
60
|
+
rhs_.each_with_index{ |p_, i_| return false unless @elements[i_].eql?(p_) }
|
61
|
+
else
|
62
|
+
false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def num_geometries
|
68
|
+
@elements.size
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def geometry_n(n_)
|
73
|
+
@elements[n_]
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def each(&block_)
|
78
|
+
@elements.each(&block_)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def dimension
|
83
|
+
unless @dimension
|
84
|
+
@dimension = -1
|
85
|
+
@elements.each do |elem_|
|
86
|
+
dim_ = elem_.dimension
|
87
|
+
@dimension = dim_ if @dimension < dim_
|
88
|
+
end
|
89
|
+
end
|
90
|
+
@dimension
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def geometry_type
|
95
|
+
Feature::GeometryCollection
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def is_empty?
|
100
|
+
@elements.size == 0
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
module BasicMultiLineStringMethods # :nodoc:
|
108
|
+
|
109
|
+
|
110
|
+
def initialize(factory_, elements_)
|
111
|
+
_set_factory(factory_)
|
112
|
+
@elements = elements_.map do |elem_|
|
113
|
+
elem_ = Feature.cast(elem_, factory_, Feature::LineString, :keep_subtype)
|
114
|
+
unless elem_
|
115
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}"
|
116
|
+
end
|
117
|
+
elem_
|
118
|
+
end
|
119
|
+
_validate_geometry
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def geometry_type
|
124
|
+
Feature::MultiLineString
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def is_closed?
|
129
|
+
all?{ |elem_| elem_.is_closed? }
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def length
|
134
|
+
@elements.inject(0.0){ |sum_, obj_| sum_ + obj_.length }
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
def _add_boundary(hash_, point_) # :nodoc:
|
139
|
+
hval_ = [point_.x, point_.y].hash
|
140
|
+
(hash_[hval_] ||= [point_, 0])[1] += 1
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
def boundary
|
145
|
+
hash_ = {}
|
146
|
+
@elements.each do |line_|
|
147
|
+
if !line_.is_empty? && !line_.is_closed?
|
148
|
+
_add_boundary(hash_, line_.start_point)
|
149
|
+
_add_boundary(hash_, line_.end_point)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
array_ = []
|
153
|
+
hash_.each do |hval_, data_|
|
154
|
+
array_ << data_[0] if data_[1] % 2 == 1
|
155
|
+
end
|
156
|
+
factory.multi_point([array_])
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
module BasicMultiPointMethods # :nodoc:
|
164
|
+
|
165
|
+
|
166
|
+
def initialize(factory_, elements_)
|
167
|
+
_set_factory(factory_)
|
168
|
+
@elements = elements_.map do |elem_|
|
169
|
+
elem_ = Feature.cast(elem_, factory_, Feature::Point, :keep_subtype)
|
170
|
+
unless elem_
|
171
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}"
|
172
|
+
end
|
173
|
+
elem_
|
174
|
+
end
|
175
|
+
_validate_geometry
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
def geometry_type
|
180
|
+
Feature::MultiPoint
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
def boundary
|
185
|
+
factory.collection([])
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
module BasicMultiPolygonMethods # :nodoc:
|
193
|
+
|
194
|
+
|
195
|
+
def initialize(factory_, elements_)
|
196
|
+
_set_factory(factory_)
|
197
|
+
@elements = elements_.map do |elem_|
|
198
|
+
elem_ = Feature.cast(elem_, factory_, Feature::Polygon, :keep_subtype)
|
199
|
+
unless elem_
|
200
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}"
|
201
|
+
end
|
202
|
+
elem_
|
203
|
+
end
|
204
|
+
_validate_geometry
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def geometry_type
|
209
|
+
Feature::MultiPolygon
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
def area
|
214
|
+
@elements.inject(0.0){ |sum_, obj_| sum_ + obj_.area }
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
def boundary
|
219
|
+
array_ = []
|
220
|
+
@elements.each do |poly_|
|
221
|
+
unless poly_.is_empty?
|
222
|
+
array_ << poly_.exterior_ring
|
223
|
+
end
|
224
|
+
array_.concat(poly_.interior_rings)
|
225
|
+
end
|
226
|
+
factory.multi_line_string(array_)
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Basic methods used by geometry objects
|
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
|
+
module RGeo
|
38
|
+
|
39
|
+
module ImplHelper # :nodoc:
|
40
|
+
|
41
|
+
|
42
|
+
module BasicGeometryMethods # :nodoc:
|
43
|
+
|
44
|
+
include Feature::Instance
|
45
|
+
|
46
|
+
|
47
|
+
def inspect # :nodoc:
|
48
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s # :nodoc:
|
52
|
+
as_text
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def _validate_geometry # :nodoc:
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def _set_factory(factory_) # :nodoc:
|
61
|
+
@factory = factory_
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def factory
|
66
|
+
@factory
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def as_text
|
71
|
+
WKRep::WKTGenerator.new.generate(self)
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def as_binary
|
76
|
+
WKRep::WKBGenerator.new.generate(self)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for LineString features
|
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
|
+
module RGeo
|
38
|
+
|
39
|
+
module ImplHelper # :nodoc:
|
40
|
+
|
41
|
+
|
42
|
+
module BasicLineStringMethods # :nodoc:
|
43
|
+
|
44
|
+
|
45
|
+
def initialize(factory_, points_)
|
46
|
+
_set_factory(factory_)
|
47
|
+
@points = points_.map do |elem_|
|
48
|
+
elem_ = Feature.cast(elem_, factory_, Feature::Point)
|
49
|
+
unless elem_
|
50
|
+
raise Error::InvalidGeometry, "Could not cast #{elem_}"
|
51
|
+
end
|
52
|
+
elem_
|
53
|
+
end
|
54
|
+
_validate_geometry
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def _validate_geometry
|
59
|
+
if @points.size == 1
|
60
|
+
raise Error::InvalidGeometry, 'LineString cannot have 1 point'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def eql?(rhs_)
|
66
|
+
if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @points.size == rhs_.num_points
|
67
|
+
rhs_.points.each_with_index{ |p_, i_| return false unless @points[i_].eql?(p_) }
|
68
|
+
else
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def num_points
|
75
|
+
@points.size
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def point_n(n_)
|
80
|
+
@points[n_]
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def points
|
85
|
+
@points.dup
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def dimension
|
90
|
+
1
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def geometry_type
|
95
|
+
Feature::LineString
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def is_empty?
|
100
|
+
@points.size == 0
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def boundary
|
105
|
+
array_ = []
|
106
|
+
if !is_empty? && !is_closed?
|
107
|
+
array_ << @points.first << @points.last
|
108
|
+
end
|
109
|
+
factory.multi_point([array_])
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def start_point
|
114
|
+
@points.first
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
def end_point
|
119
|
+
@points.last
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def is_closed?
|
124
|
+
unless defined?(@is_closed)
|
125
|
+
@is_closed = @points.size > 2 && @points.first == @points.last
|
126
|
+
end
|
127
|
+
@is_closed
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def is_ring?
|
132
|
+
is_closed? && is_simple?
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
module BasicLineMethods # :nodoc:
|
140
|
+
|
141
|
+
|
142
|
+
def initialize(factory_, start_, end_)
|
143
|
+
_set_factory(factory_)
|
144
|
+
cstart_ = Feature.cast(start_, factory_, Feature::Point)
|
145
|
+
unless cstart_
|
146
|
+
raise Error::InvalidGeometry, "Could not cast start: #{start_}"
|
147
|
+
end
|
148
|
+
cend_ = Feature.cast(end_, factory_, Feature::Point)
|
149
|
+
unless cend_
|
150
|
+
raise Error::InvalidGeometry, "Could not cast end: #{end_}"
|
151
|
+
end
|
152
|
+
@points = [cstart_, cend_]
|
153
|
+
_validate_geometry
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def _validate_geometry # :nodoc:
|
158
|
+
super
|
159
|
+
if @points.size > 2
|
160
|
+
raise Error::InvalidGeometry, 'Line must have 0 or 2 points'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
def geometry_type
|
166
|
+
Feature::Line
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
module BasicLinearRingMethods # :nodoc:
|
174
|
+
|
175
|
+
|
176
|
+
def _validate_geometry # :nodoc:
|
177
|
+
super
|
178
|
+
if @points.size > 0
|
179
|
+
@points << @points.first if @points.first != @points.last
|
180
|
+
if !is_ring?
|
181
|
+
raise Error::InvalidGeometry, 'LinearRing failed ring test'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
def geometry_type
|
188
|
+
Feature::LinearRing
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|