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,161 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Core calculations in the plane
|
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 Cartesian
|
40
|
+
|
41
|
+
|
42
|
+
# Represents a line segment in the plane.
|
43
|
+
|
44
|
+
class Segment # :nodoc:
|
45
|
+
|
46
|
+
def initialize(start_, end_)
|
47
|
+
@s = start_
|
48
|
+
@e = end_
|
49
|
+
@sx = @s.x
|
50
|
+
@sy = @s.y
|
51
|
+
@ex = @e.x
|
52
|
+
@ey = @e.y
|
53
|
+
@dx = @ex - @sx
|
54
|
+
@dy = @ey - @sy
|
55
|
+
@lensq = @dx * @dx + @dy * @dy
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
attr_reader :s
|
60
|
+
attr_reader :e
|
61
|
+
attr_reader :dx
|
62
|
+
attr_reader :dy
|
63
|
+
|
64
|
+
|
65
|
+
def to_s
|
66
|
+
"#{@s} - #{@e}"
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def eql?(rhs_)
|
71
|
+
rhs_.kind_of?(Segment) && @s == rhs_.s && @e == rhs_.e
|
72
|
+
end
|
73
|
+
alias_method :==, :eql?
|
74
|
+
|
75
|
+
|
76
|
+
def degenerate?
|
77
|
+
@lensq == 0
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
# Returns a negative value if the point is to the left,
|
82
|
+
# a positive value if the point is to the right, or
|
83
|
+
# 0 if the point is collinear to the segment.
|
84
|
+
|
85
|
+
def side(p_)
|
86
|
+
px_ = p_.x
|
87
|
+
py_ = p_.y
|
88
|
+
(@sx - px_) * (@ey - py_) - (@sy - py_) * (@ex - px_)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def tproj(p_)
|
93
|
+
if @lensq == 0
|
94
|
+
nil
|
95
|
+
else
|
96
|
+
(@dx * (p_.x - @sx) + @dy * (p_.y - @sy)) / @lensq
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def contains_point?(p_)
|
102
|
+
if side(p_) == 0
|
103
|
+
t_ = tproj(p_)
|
104
|
+
t_ && t_ >= 0.0 && t_ <= 1.0
|
105
|
+
else
|
106
|
+
false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def intersects_segment?(seg_)
|
112
|
+
s2_ = seg_.s
|
113
|
+
# Handle degenerate cases
|
114
|
+
if seg_.degenerate?
|
115
|
+
if @lensq == 0
|
116
|
+
return @s == s2_
|
117
|
+
else
|
118
|
+
return contains_point?(s2_)
|
119
|
+
end
|
120
|
+
elsif @lensq == 0
|
121
|
+
return seg_.contains_point?(@s)
|
122
|
+
end
|
123
|
+
# Both segments have nonzero length.
|
124
|
+
sx2_ = s2_.x
|
125
|
+
sy2_ = s2_.y
|
126
|
+
dx2_ = seg_.dx
|
127
|
+
dy2_ = seg_.dy
|
128
|
+
denom_ = @dx*dy2_ - @dy*dx2_
|
129
|
+
if denom_ == 0
|
130
|
+
# Segments are parallel. Make sure they are collinear.
|
131
|
+
return false unless side(s2_) == 0
|
132
|
+
# 1-D check.
|
133
|
+
ts_ = (@dx * (sx2_ - @sx) + @dy * (sy2_ - @sy)) / @lensq
|
134
|
+
te_ = (@dx * (sx2_ + dx2_ - @sx) + @dy * (sy2_ + dy2_ - @sy)) / @lensq
|
135
|
+
if ts_ < te_
|
136
|
+
te_ >= 0.0 && ts_ <= 1.0
|
137
|
+
else
|
138
|
+
ts_ >= 0.0 && te_ <= 1.0
|
139
|
+
end
|
140
|
+
else
|
141
|
+
# Segments are not parallel. Check the intersection of their
|
142
|
+
# containing lines.
|
143
|
+
t_ = (dy2_ * (sx2_ - @sx) + dx2_ * (@sy - sy2_)) / denom_
|
144
|
+
return false if t_ < 0.0 || t_ > 1.0
|
145
|
+
t2_ = (@dy * (sx2_ - @sx) + @dx * (@sy - sy2_)) / denom_
|
146
|
+
t2_ >= 0.0 && t2_ <= 1.0
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def length
|
152
|
+
::Math.sqrt(@lensq)
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Geographic data factory implementation
|
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 Cartesian
|
40
|
+
|
41
|
+
|
42
|
+
# This class implements the factory for the simple cartesian
|
43
|
+
# implementation.
|
44
|
+
|
45
|
+
class Factory
|
46
|
+
|
47
|
+
include Feature::Factory::Instance
|
48
|
+
|
49
|
+
|
50
|
+
# Create a new simple cartesian factory.
|
51
|
+
#
|
52
|
+
# See ::RGeo::Cartesian::simple_factory for a list of supported options.
|
53
|
+
|
54
|
+
def initialize(opts_={})
|
55
|
+
@has_z = opts_[:has_z_coordinate] ? true : false
|
56
|
+
@has_m = opts_[:has_m_coordinate] ? true : false
|
57
|
+
@proj4 = opts_[:proj4]
|
58
|
+
if CoordSys::Proj4.supported?
|
59
|
+
if @proj4.kind_of?(::String) || @proj4.kind_of?(::Hash)
|
60
|
+
@proj4 = CoordSys::Proj4.create(@proj4)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
@proj4 = nil
|
64
|
+
end
|
65
|
+
srid_ = opts_[:srid]
|
66
|
+
@coord_sys = opts_[:coord_sys]
|
67
|
+
if @coord_sys.kind_of?(::String)
|
68
|
+
@coord_sys = CoordSys::CS.create_from_wkt(@coord_sys) rescue nil
|
69
|
+
end
|
70
|
+
if (!@proj4 || !@coord_sys) && srid_ && (db_ = opts_[:srs_database])
|
71
|
+
entry_ = db_.get(srid_.to_i)
|
72
|
+
if entry_
|
73
|
+
@proj4 ||= entry_.proj4
|
74
|
+
@coord_sys ||= entry_.coord_sys
|
75
|
+
end
|
76
|
+
end
|
77
|
+
srid_ ||= @coord_sys.authority_code if @coord_sys
|
78
|
+
@srid = srid_.to_i
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
# Equivalence test.
|
83
|
+
|
84
|
+
def eql?(rhs_)
|
85
|
+
rhs_.is_a?(self.class) && @srid == rhs_.srid && @has_z == rhs_.property(:has_z_coordinate) && @has_m == rhs_.property(:has_m_coordinate)
|
86
|
+
end
|
87
|
+
alias_method :==, :eql?
|
88
|
+
|
89
|
+
|
90
|
+
# Returns the SRID.
|
91
|
+
|
92
|
+
def srid
|
93
|
+
@srid
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# See ::RGeo::Feature::Factory#property
|
98
|
+
|
99
|
+
def property(name_)
|
100
|
+
case name_
|
101
|
+
when :has_z_coordinate
|
102
|
+
@has_z
|
103
|
+
when :has_m_coordinate
|
104
|
+
@has_m
|
105
|
+
when :is_cartesian
|
106
|
+
true
|
107
|
+
else
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
# See ::RGeo::Feature::Factory#parse_wkt
|
114
|
+
|
115
|
+
def parse_wkt(str_)
|
116
|
+
WKRep::WKTParser.new(self).parse(str_)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# See ::RGeo::Feature::Factory#parse_wkb
|
121
|
+
|
122
|
+
def parse_wkb(str_)
|
123
|
+
WKRep::WKBParser.new(self).parse(str_)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
# See ::RGeo::Feature::Factory#point
|
128
|
+
|
129
|
+
def point(x_, y_, *extra_)
|
130
|
+
PointImpl.new(self, x_, y_, *extra_) rescue nil
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
# See ::RGeo::Feature::Factory#line_string
|
135
|
+
|
136
|
+
def line_string(points_)
|
137
|
+
LineStringImpl.new(self, points_) rescue nil
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
# See ::RGeo::Feature::Factory#line
|
142
|
+
|
143
|
+
def line(start_, end_)
|
144
|
+
LineImpl.new(self, start_, end_) rescue nil
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
# See ::RGeo::Feature::Factory#linear_ring
|
149
|
+
|
150
|
+
def linear_ring(points_)
|
151
|
+
LinearRingImpl.new(self, points_) rescue nil
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
# See ::RGeo::Feature::Factory#polygon
|
156
|
+
|
157
|
+
def polygon(outer_ring_, inner_rings_=nil)
|
158
|
+
PolygonImpl.new(self, outer_ring_, inner_rings_) rescue nil
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
# See ::RGeo::Feature::Factory#collection
|
163
|
+
|
164
|
+
def collection(elems_)
|
165
|
+
GeometryCollectionImpl.new(self, elems_) rescue nil
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
# See ::RGeo::Feature::Factory#multi_point
|
170
|
+
|
171
|
+
def multi_point(elems_)
|
172
|
+
MultiPointImpl.new(self, elems_) rescue nil
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
# See ::RGeo::Feature::Factory#multi_line_string
|
177
|
+
|
178
|
+
def multi_line_string(elems_)
|
179
|
+
MultiLineStringImpl.new(self, elems_) rescue nil
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
# See ::RGeo::Feature::Factory#multi_polygon
|
184
|
+
|
185
|
+
def multi_polygon(elems_)
|
186
|
+
MultiPolygonImpl.new(self, elems_) rescue nil
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
# See ::RGeo::Feature::Factory#proj4
|
191
|
+
|
192
|
+
def proj4
|
193
|
+
@proj4
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
# See ::RGeo::Feature::Factory#coord_sys
|
198
|
+
|
199
|
+
def coord_sys
|
200
|
+
@coord_sys
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Spherical geography feature classes
|
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 Cartesian
|
40
|
+
|
41
|
+
|
42
|
+
class PointImpl # :nodoc:
|
43
|
+
|
44
|
+
|
45
|
+
include ::RGeo::Feature::Point
|
46
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
47
|
+
include ::RGeo::ImplHelper::BasicPointMethods
|
48
|
+
include ::RGeo::Cartesian::GeometryMethods
|
49
|
+
|
50
|
+
|
51
|
+
def distance(rhs_)
|
52
|
+
rhs_ = ::RGeo::Feature.cast(rhs_, @factory)
|
53
|
+
case rhs_
|
54
|
+
when PointImpl
|
55
|
+
dx_ = @x - rhs_.x
|
56
|
+
dy_ = @y - rhs_.y
|
57
|
+
::Math.sqrt(dx_ * dx_ + dy_ * dy_)
|
58
|
+
else
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
class LineStringImpl # :nodoc:
|
68
|
+
|
69
|
+
|
70
|
+
include ::RGeo::Feature::LineString
|
71
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
72
|
+
include ::RGeo::ImplHelper::BasicLineStringMethods
|
73
|
+
include ::RGeo::Cartesian::GeometryMethods
|
74
|
+
include ::RGeo::Cartesian::LineStringMethods
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
class LineImpl # :nodoc:
|
81
|
+
|
82
|
+
|
83
|
+
include ::RGeo::Feature::Line
|
84
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
85
|
+
include ::RGeo::ImplHelper::BasicLineStringMethods
|
86
|
+
include ::RGeo::ImplHelper::BasicLineMethods
|
87
|
+
include ::RGeo::Cartesian::GeometryMethods
|
88
|
+
include ::RGeo::Cartesian::LineStringMethods
|
89
|
+
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
class LinearRingImpl # :nodoc:
|
95
|
+
|
96
|
+
|
97
|
+
include ::RGeo::Feature::Line
|
98
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
99
|
+
include ::RGeo::ImplHelper::BasicLineStringMethods
|
100
|
+
include ::RGeo::ImplHelper::BasicLinearRingMethods
|
101
|
+
include ::RGeo::Cartesian::GeometryMethods
|
102
|
+
include ::RGeo::Cartesian::LineStringMethods
|
103
|
+
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
class PolygonImpl # :nodoc:
|
109
|
+
|
110
|
+
|
111
|
+
include ::RGeo::Feature::Polygon
|
112
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
113
|
+
include ::RGeo::ImplHelper::BasicPolygonMethods
|
114
|
+
include ::RGeo::Cartesian::GeometryMethods
|
115
|
+
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
class GeometryCollectionImpl # :nodoc:
|
121
|
+
|
122
|
+
|
123
|
+
include ::RGeo::Feature::GeometryCollection
|
124
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
125
|
+
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
|
126
|
+
include ::RGeo::Cartesian::GeometryMethods
|
127
|
+
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
class MultiPointImpl # :nodoc:
|
133
|
+
|
134
|
+
|
135
|
+
include ::RGeo::Feature::GeometryCollection
|
136
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
137
|
+
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
|
138
|
+
include ::RGeo::ImplHelper::BasicMultiPointMethods
|
139
|
+
include ::RGeo::Cartesian::GeometryMethods
|
140
|
+
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
class MultiLineStringImpl # :nodoc:
|
146
|
+
|
147
|
+
|
148
|
+
include ::RGeo::Feature::GeometryCollection
|
149
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
150
|
+
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
|
151
|
+
include ::RGeo::ImplHelper::BasicMultiLineStringMethods
|
152
|
+
include ::RGeo::Cartesian::GeometryMethods
|
153
|
+
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
class MultiPolygonImpl # :nodoc:
|
159
|
+
|
160
|
+
|
161
|
+
include ::RGeo::Feature::GeometryCollection
|
162
|
+
include ::RGeo::ImplHelper::BasicGeometryMethods
|
163
|
+
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
|
164
|
+
include ::RGeo::ImplHelper::BasicMultiPolygonMethods
|
165
|
+
include ::RGeo::Cartesian::GeometryMethods
|
166
|
+
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|