rgeo 0.1.12 → 0.1.13
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 +9 -7
- data/README.rdoc +7 -5
- data/Version +1 -1
- data/ext/geos_c_impl/factory.c +12 -19
- data/ext/geos_c_impl/factory.h +15 -21
- data/ext/geos_c_impl/geometry.c +19 -36
- data/ext/geos_c_impl/geometry.h +2 -12
- data/ext/geos_c_impl/geometry_collection.c +38 -157
- data/ext/geos_c_impl/geometry_collection.h +2 -12
- data/ext/geos_c_impl/line_string.c +83 -80
- data/ext/geos_c_impl/line_string.h +2 -12
- data/ext/geos_c_impl/main.c +5 -0
- data/ext/geos_c_impl/point.c +2 -12
- data/ext/geos_c_impl/point.h +2 -12
- data/ext/geos_c_impl/polygon.c +5 -14
- data/ext/geos_c_impl/polygon.h +2 -12
- data/ext/geos_c_impl/preface.h +8 -0
- data/lib/rgeo.rb +34 -16
- data/lib/rgeo/{geography/simple_spherical/geometry_collection_impl.rb → cartesian.rb} +19 -26
- data/lib/rgeo/cartesian/calculations.rb +129 -0
- data/lib/rgeo/cartesian/interface.rb +85 -0
- data/lib/rgeo/cartesian/simple_factory.rb +159 -0
- data/lib/rgeo/cartesian/simple_feature_classes.rb +187 -0
- data/lib/rgeo/cartesian/simple_feature_methods.rb +97 -0
- data/lib/rgeo/features.rb +1 -0
- data/lib/rgeo/features/curve.rb +3 -2
- data/lib/rgeo/features/factory.rb +62 -37
- data/lib/rgeo/features/geometry.rb +10 -32
- data/lib/rgeo/features/geometry_collection.rb +3 -2
- data/lib/rgeo/features/line.rb +3 -2
- data/lib/rgeo/features/line_string.rb +3 -2
- data/lib/rgeo/features/linear_ring.rb +3 -2
- data/lib/rgeo/features/multi_curve.rb +3 -2
- data/lib/rgeo/features/multi_line_string.rb +3 -2
- data/lib/rgeo/features/multi_point.rb +3 -2
- data/lib/rgeo/features/multi_polygon.rb +3 -2
- data/lib/rgeo/features/multi_surface.rb +3 -2
- data/lib/rgeo/features/point.rb +3 -2
- data/lib/rgeo/features/polygon.rb +3 -2
- data/lib/rgeo/features/surface.rb +3 -2
- data/lib/rgeo/features/types.rb +198 -0
- data/lib/rgeo/geography.rb +4 -14
- data/lib/rgeo/geography/factory.rb +7 -64
- data/lib/rgeo/geography/{simple_spherical/geometry_methods.rb → helper.rb} +4 -13
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +35 -89
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +22 -31
- data/lib/rgeo/geography/simple_mercator/projector.rb +4 -8
- data/lib/rgeo/geography/simple_spherical/calculations.rb +11 -9
- data/lib/rgeo/geography/simple_spherical/feature_classes.rb +189 -0
- data/lib/rgeo/geography/simple_spherical/{line_string_impl.rb → feature_methods.rb} +16 -64
- data/lib/rgeo/geos/factory.rb +26 -40
- data/lib/rgeo/geos/impl_additions.rb +3 -5
- data/lib/rgeo/{geography/simple_spherical/polygon_impl.rb → impl_helpers.rb} +16 -26
- data/lib/rgeo/impl_helpers/basic_geometry_collection_methods.rb +186 -0
- data/lib/rgeo/impl_helpers/basic_geometry_methods.rb +90 -0
- data/lib/rgeo/impl_helpers/basic_line_string_methods.rb +188 -0
- data/lib/rgeo/impl_helpers/basic_point_methods.rb +149 -0
- data/lib/rgeo/{geography/common/helper.rb → impl_helpers/basic_polygon_methods.rb} +62 -53
- data/lib/rgeo/{geography/common/polygon_methods.rb → impl_helpers/serialization.rb} +50 -42
- data/tests/common/geometry_collection_tests.rb +9 -7
- data/tests/common/multi_line_string_tests.rb +16 -13
- data/tests/common/multi_point_tests.rb +16 -13
- data/tests/common/multi_polygon_tests.rb +8 -6
- data/tests/common/point_tests.rb +1 -2
- data/tests/common/polygon_tests.rb +9 -9
- data/tests/geos/tc_multi_line_string.rb +2 -2
- data/tests/simple_cartesian/tc_calculations.rb +138 -0
- data/tests/simple_cartesian/tc_geometry_collection.rb +68 -0
- data/tests/simple_cartesian/tc_line_string.rb +70 -0
- data/{lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb → tests/simple_cartesian/tc_multi_line_string.rb} +19 -19
- data/{lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb → tests/simple_cartesian/tc_multi_point.rb} +19 -19
- data/{lib/rgeo/geography/common/geometry_methods.rb → tests/simple_cartesian/tc_multi_polygon.rb} +19 -41
- data/{lib/rgeo/geography/simple_spherical/point_impl.rb → tests/simple_cartesian/tc_point.rb} +33 -35
- data/tests/simple_cartesian/tc_polygon.rb +67 -0
- data/tests/simple_spherical/tc_geometry_collection.rb +68 -0
- data/tests/simple_spherical/tc_line_string.rb +10 -171
- data/tests/simple_spherical/tc_multi_line_string.rb +67 -0
- data/{lib/rgeo/geography/simple_spherical/multi_point_impl.rb → tests/simple_spherical/tc_multi_point.rb} +19 -19
- data/tests/simple_spherical/tc_multi_polygon.rb +70 -0
- data/tests/simple_spherical/tc_point.rb +17 -115
- data/tests/simple_spherical/tc_polygon.rb +67 -0
- metadata +46 -18
- data/ext/geos_c_impl/globals.h +0 -58
- data/lib/rgeo/geography/common/geometry_collection_methods.rb +0 -217
- data/lib/rgeo/geography/common/line_string_methods.rb +0 -201
- data/lib/rgeo/geography/common/point_methods.rb +0 -153
@@ -0,0 +1,90 @@
|
|
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 ImplHelpers # :nodoc:
|
40
|
+
|
41
|
+
|
42
|
+
module BasicGeometryMethods # :nodoc:
|
43
|
+
|
44
|
+
include ::RGeo::Features::Type::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 cast(type_)
|
71
|
+
type_ == geometry_type ? self : nil
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def as_text
|
76
|
+
Serialization.unparse_wkt(self)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def as_binary
|
81
|
+
Serialization.unparse_wkb(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,188 @@
|
|
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 ImplHelpers # :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_ = Features.cast(elem_, factory_, Features::Point)
|
49
|
+
unless elem_
|
50
|
+
raise Errors::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 Errors::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
|
+
Features::LineString
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def is_empty?
|
100
|
+
@points.size == 0
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def start_point
|
105
|
+
@points.first
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def end_point
|
110
|
+
@points.last
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def is_closed?
|
115
|
+
if @is_closed.nil?
|
116
|
+
@is_closed = @points.size > 2 && @points.first == @points.last
|
117
|
+
end
|
118
|
+
@is_closed
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def is_ring?
|
123
|
+
is_closed? && is_simple?
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
module BasicLineMethods # :nodoc:
|
131
|
+
|
132
|
+
|
133
|
+
def initialize(factory_, start_, end_)
|
134
|
+
_set_factory(factory_)
|
135
|
+
cstart_ = Features.cast(start_, factory_, Features::Point)
|
136
|
+
unless cstart_
|
137
|
+
raise Errors::InvalidGeometry, "Could not cast start: #{start_}"
|
138
|
+
end
|
139
|
+
cend_ = Features.cast(end_, factory_, Features::Point)
|
140
|
+
unless cend_
|
141
|
+
raise Errors::InvalidGeometry, "Could not cast end: #{end_}"
|
142
|
+
end
|
143
|
+
@points = [cstart_, cend_]
|
144
|
+
_validate_geometry
|
145
|
+
end
|
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 BasicLinearRingMethods # :nodoc:
|
165
|
+
|
166
|
+
|
167
|
+
def _validate_geometry # :nodoc:
|
168
|
+
super
|
169
|
+
if @points.size > 0
|
170
|
+
@points << @points.first if @points.first != @points.last
|
171
|
+
if !is_ring?
|
172
|
+
raise Errors::InvalidGeometry, 'LinearRing failed ring test'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
def geometry_type
|
179
|
+
Features::LinearRing
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common methods for Point 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 ImplHelpers # :nodoc:
|
40
|
+
|
41
|
+
|
42
|
+
module BasicPointMethods # :nodoc:
|
43
|
+
|
44
|
+
|
45
|
+
def initialize(factory_, x_, y_)
|
46
|
+
_set_factory(factory_)
|
47
|
+
@x = x_.to_f
|
48
|
+
@y = y_.to_f
|
49
|
+
_validate_geometry
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def x
|
54
|
+
@x
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def y
|
59
|
+
@y
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def eql?(rhs_)
|
64
|
+
rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @x == rhs_.x && @y == rhs_.y
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def cast(type_)
|
69
|
+
case type_
|
70
|
+
when Features::Point
|
71
|
+
self
|
72
|
+
when Features::GeometryCollection
|
73
|
+
factory.collection([self]) rescue nil
|
74
|
+
when Features::MultiPoint
|
75
|
+
factory.multi_point([self]) rescue nil
|
76
|
+
else
|
77
|
+
super
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def dimension
|
83
|
+
0
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def geometry_type
|
88
|
+
Features::Point
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def is_empty?
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def is_simple?
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def envelope
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def boundary
|
108
|
+
factory.collection([])
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def convex_hull
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def equals?(rhs_)
|
118
|
+
return false unless rhs_.is_a?(self.class) && rhs_.factory == self.factory
|
119
|
+
case rhs_
|
120
|
+
when Features::Point
|
121
|
+
if @y == 90
|
122
|
+
rhs_.y == 90
|
123
|
+
elsif @y == -90
|
124
|
+
rhs_.y == -90
|
125
|
+
else
|
126
|
+
rhs_.x == @x && rhs_.y == @y
|
127
|
+
end
|
128
|
+
when Features::LineString
|
129
|
+
rhs_.num_points > 0 && rhs_.points.all?{ |elem_| equals?(elem_) }
|
130
|
+
when Features::GeometryCollection
|
131
|
+
rhs_.num_geometries > 0 && rhs_.all?{ |elem_| equals?(elem_) }
|
132
|
+
else
|
133
|
+
false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
alias_method :longitude, :x
|
139
|
+
alias_method :lon, :x
|
140
|
+
alias_method :latitude, :y
|
141
|
+
alias_method :lat, :y
|
142
|
+
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# Common methods for Polygon features
|
4
4
|
#
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
# Copyright 2010 Daniel Azuma
|
@@ -36,67 +36,76 @@
|
|
36
36
|
|
37
37
|
module RGeo
|
38
38
|
|
39
|
-
module
|
39
|
+
module ImplHelpers # :nodoc:
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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_.cast(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_.cast(obj_) : nil
|
41
|
+
|
42
|
+
module BasicPolygonMethods # :nodoc:
|
43
|
+
|
44
|
+
|
45
|
+
def initialize(factory_, exterior_ring_, interior_rings_)
|
46
|
+
_set_factory(factory_)
|
47
|
+
@exterior_ring = Features.cast(exterior_ring_, factory_, Features::LinearRing)
|
48
|
+
unless @exterior_ring
|
49
|
+
raise Errors::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring_}"
|
80
50
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
51
|
+
@interior_rings = (interior_rings_ || []).map do |elem_|
|
52
|
+
elem_ = Features.cast(elem_, factory_, Features::LinearRing)
|
53
|
+
unless elem_
|
54
|
+
raise Errors::InvalidGeometry, "Could not cast interior ring #{elem_}"
|
55
|
+
end
|
56
|
+
elem_
|
86
57
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
58
|
+
_validate_geometry
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def eql?(rhs_)
|
63
|
+
if rhs_.is_a?(self.class) && rhs_.factory.eql?(@factory) && @exterior_ring.eql?(rhs_.exterior_ring) && @interior_rings.size == rhs_.num_interior_rings
|
64
|
+
rhs_.interior_rings.each_with_index{ |r_, i_| return false unless @interior_rings[i_].eql?(r_) }
|
65
|
+
else
|
66
|
+
false
|
92
67
|
end
|
93
|
-
|
94
|
-
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def exterior_ring
|
72
|
+
@exterior_ring
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def num_interior_rings
|
77
|
+
@interior_rings.size
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def interior_ring_n(n_)
|
82
|
+
@interior_rings[n_]
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def interior_rings
|
87
|
+
@interior_rings.dup
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
def dimension
|
92
|
+
2
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def geometry_type
|
97
|
+
Features::Polygon
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def is_empty?
|
102
|
+
@exterior_ring.is_empty?
|
95
103
|
end
|
96
104
|
|
97
105
|
|
98
106
|
end
|
99
107
|
|
108
|
+
|
100
109
|
end
|
101
110
|
|
102
111
|
end
|