rgeo 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- 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,206 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for GeometryCollection geography 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 Geography
|
40
|
+
|
41
|
+
module Common
|
42
|
+
|
43
|
+
|
44
|
+
module GeometryCollectionMethods
|
45
|
+
|
46
|
+
|
47
|
+
def _setup(elements_)
|
48
|
+
@elements = elements_.map{ |elem_| factory.convert(elem_) }
|
49
|
+
_validate_geometry
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def num_geometries
|
54
|
+
@elements.size
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def geometry_n(n_)
|
59
|
+
@elements[n_]
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def each(&block_)
|
64
|
+
@elements.each(&block_)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def dimension
|
69
|
+
unless @dimension
|
70
|
+
@dimension = -1
|
71
|
+
@elements.each do |elem_|
|
72
|
+
dim_ = elem_.dimension
|
73
|
+
@dimension = dim_ if @dimension < dim_
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@dimension
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def geometry_type
|
81
|
+
Features::GeometryCollection
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def is_empty?
|
86
|
+
@elements.size == 0
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def cast(type_)
|
91
|
+
if type_ == self.geometry_type
|
92
|
+
self
|
93
|
+
else
|
94
|
+
case type_
|
95
|
+
when Features::MultiPoint
|
96
|
+
factory.multi_point(@elements) rescue nil
|
97
|
+
when Features::MultiLineString
|
98
|
+
factory.multi_line_string(@elements) rescue nil
|
99
|
+
when Features::MultiPolygon
|
100
|
+
factory.multi_polygon(@elements) rescue nil
|
101
|
+
when Features::GeometryCollection
|
102
|
+
factory.collection(@elements) rescue nil
|
103
|
+
else
|
104
|
+
@elements.size == 1 ? @elements[0].cast(type_) : nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
module MultiLineStringMethods
|
114
|
+
|
115
|
+
|
116
|
+
def _validate_geometry # :nodoc:
|
117
|
+
super
|
118
|
+
if any?{ |elem_| !Features::LineString.check_type(elem_) }
|
119
|
+
raise Errors::InvalidGeometry, 'Collection element is not a LineString'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
def geometry_type
|
125
|
+
Features::MultiLineString
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def is_closed?
|
130
|
+
all?{ |elem_| elem_.is_closed? }
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
def cast(type_)
|
135
|
+
if type_ == Features::LineString && @elements.size == 1
|
136
|
+
@elements[0]
|
137
|
+
else
|
138
|
+
super
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
module MultiPointMethods
|
147
|
+
|
148
|
+
|
149
|
+
def _validate_geometry # :nodoc:
|
150
|
+
super
|
151
|
+
if any?{ |elem_| !Features::Point.check_type(elem_) }
|
152
|
+
raise Errors::InvalidGeometry, "Collection element is not a Point"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def geometry_type
|
158
|
+
Features::MultiPoint
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
def cast(type_)
|
163
|
+
if type_.name == Features::Point && @elements.size == 1
|
164
|
+
@elements[0]
|
165
|
+
else
|
166
|
+
super
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
module MultiPolygonMethods
|
175
|
+
|
176
|
+
|
177
|
+
def _validate_geometry # :nodoc:
|
178
|
+
super
|
179
|
+
if any?{ |elem_| !Features::Polygon.check_type(elem_) }
|
180
|
+
raise Errors::InvalidGeometry, 'Collection element is not a Polygon'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
def geometry_type
|
186
|
+
Features::MultiPolygon
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def cast(type_)
|
191
|
+
if type_ == Features::Polygon && @elements.size == 1
|
192
|
+
@elements[0]
|
193
|
+
else
|
194
|
+
super
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Basic methods used by all geography 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 Geography
|
40
|
+
|
41
|
+
module Common
|
42
|
+
|
43
|
+
|
44
|
+
module GeometryMethods
|
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 cast(type_)
|
71
|
+
type_ == geometry_type ? self : nil
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def as_text
|
76
|
+
Helper.unparse_wkt(self)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def as_binary
|
81
|
+
Helper.unparse_wkb(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Geography helpers
|
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 Geography
|
40
|
+
|
41
|
+
module Common
|
42
|
+
|
43
|
+
|
44
|
+
# This is an internal module used by Geography. You generally should
|
45
|
+
# not need to call these methods directly.
|
46
|
+
|
47
|
+
module Helper
|
48
|
+
|
49
|
+
|
50
|
+
RADIANS_PER_DEGREE = ::Math::PI/180.0
|
51
|
+
DEGREES_PER_RADIAN = 180.0/::Math::PI
|
52
|
+
|
53
|
+
|
54
|
+
@basic_factory = false
|
55
|
+
|
56
|
+
|
57
|
+
def self.factory
|
58
|
+
if @basic_factory == false
|
59
|
+
if Geos.supported?
|
60
|
+
@basic_factory = Geos.factory(:srid => 0)
|
61
|
+
else
|
62
|
+
@basic_factory = nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@basic_factory
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def self.parse_wkt(str_, factory_)
|
70
|
+
helper_factory_ = self.factory
|
71
|
+
obj_ = helper_factory_ ? helper_factory_.parse_wkt(str_) : nil
|
72
|
+
obj_ ? factory_.convert(obj_) : nil
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def self.parse_wkb(str_, factory_)
|
77
|
+
helper_factory_ = self.factory
|
78
|
+
obj_ = helper_factory_ ? helper_factory_.parse_wkb(str_) : nil
|
79
|
+
obj_ ? factory_.convert(obj_) : nil
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def self.unparse_wkt(obj_)
|
84
|
+
helper_factory_ = self.factory
|
85
|
+
helper_factory_ ? helper_factory_.convert(obj_).as_text : nil
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def self.unparse_wkb(obj_)
|
90
|
+
helper_factory_ = self.factory
|
91
|
+
helper_factory_ ? helper_factory_.convert(obj_).as_binary : nil
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for LineString geography 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 Geography
|
40
|
+
|
41
|
+
module Common
|
42
|
+
|
43
|
+
|
44
|
+
module LineStringMethods
|
45
|
+
|
46
|
+
|
47
|
+
def _setup(points_)
|
48
|
+
@points = points_.map{ |elem_| factory.convert(elem_) }
|
49
|
+
_validate_geometry
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def _validate_geometry
|
54
|
+
if @points.size == 1
|
55
|
+
raise Errors::InvalidGeometry, 'LineString cannot have 1 point'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def cast(type_)
|
61
|
+
if type_ == self.geometry_type
|
62
|
+
self
|
63
|
+
else
|
64
|
+
case type_
|
65
|
+
when Features::Line
|
66
|
+
if @points.size == 0 || @points.size == 2
|
67
|
+
factory.line(@points.first, @points.last) rescue nil
|
68
|
+
else
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
when Features::LinearRing
|
72
|
+
factory.linear_ring(@points) rescue nil
|
73
|
+
when Features::LineString
|
74
|
+
factory.line_string(@points) rescue nil
|
75
|
+
when Features::GeometryCollection
|
76
|
+
factory.collection([self]) rescue nil
|
77
|
+
when Features::MultiLineString
|
78
|
+
factory.multi_line_string([self]) rescue nil
|
79
|
+
when Features::Polygon
|
80
|
+
ring_ = factory.linear_ring(@points) rescue nil
|
81
|
+
ring_ ? factory.polygon(ring_, nil) : nil rescue nil
|
82
|
+
else
|
83
|
+
super
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def num_points
|
90
|
+
@points.size
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def point_n(n_)
|
95
|
+
@points[n_]
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def points
|
100
|
+
@points.dup
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def dimension
|
105
|
+
1
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def geometry_type
|
110
|
+
Features::LineString
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def is_empty?
|
115
|
+
@points.size == 0
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def start_point
|
120
|
+
@points.first
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
def end_point
|
125
|
+
@points.last
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def is_closed?
|
130
|
+
if @is_closed.nil?
|
131
|
+
@is_closed = @points.size > 2 && @points.first == @points.last
|
132
|
+
end
|
133
|
+
@is_closed
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def is_ring?
|
138
|
+
is_closed? && is_simple?
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
module LineMethods
|
146
|
+
|
147
|
+
|
148
|
+
def _validate_geometry # :nodoc:
|
149
|
+
super
|
150
|
+
if @points.size > 2
|
151
|
+
raise Errors::InvalidGeometry, 'Line must have 0 or 2 points'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
def geometry_type
|
157
|
+
Features::Line
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
module LinearRingMethods
|
165
|
+
|
166
|
+
|
167
|
+
def _validate_geometry # :nodoc:
|
168
|
+
super
|
169
|
+
if @points.size > 0 && !is_ring?
|
170
|
+
raise Errors::InvalidGeometry, 'LinearRing failed ring test'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
def geometry_type
|
176
|
+
Features::LinearRing
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|