rgeo 0.1.19 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +11 -0
- data/README.rdoc +23 -7
- data/Version +1 -1
- data/ext/geos_c_impl/factory.c +1 -1
- data/{lib/rgeo/geography/simple_mercator.rb → ext/proj4_c_impl/extconf.rb} +35 -30
- data/ext/proj4_c_impl/main.c +256 -0
- data/lib/rgeo.rb +54 -42
- data/lib/rgeo/active_record/arel_modifications.rb +2 -2
- data/lib/rgeo/active_record/base_modifications.rb +1 -1
- data/lib/rgeo/active_record/mysql_common.rb +12 -12
- data/lib/rgeo/all.rb +5 -4
- data/lib/rgeo/cartesian.rb +3 -2
- data/lib/rgeo/cartesian/bounding_box.rb +9 -9
- data/lib/rgeo/cartesian/factory.rb +30 -13
- data/lib/rgeo/cartesian/feature_classes.rb +33 -33
- data/lib/rgeo/cartesian/interface.rb +2 -2
- data/lib/rgeo/{geography/all.rb → coord_sys.rb} +22 -4
- data/lib/rgeo/coord_sys/proj4.rb +275 -0
- data/lib/rgeo/{errors.rb → error.rb} +5 -6
- data/lib/rgeo/{features.rb → feature.rb} +22 -20
- data/lib/rgeo/{features → feature}/curve.rb +6 -6
- data/lib/rgeo/{features → feature}/factory.rb +19 -3
- data/lib/rgeo/{features → feature}/factory_generator.rb +1 -1
- data/lib/rgeo/{features → feature}/geometry.rb +34 -34
- data/lib/rgeo/{features → feature}/geometry_collection.rb +4 -4
- data/lib/rgeo/{features → feature}/line.rb +1 -1
- data/lib/rgeo/{features → feature}/line_string.rb +4 -4
- data/lib/rgeo/{features → feature}/linear_ring.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_curve.rb +3 -3
- data/lib/rgeo/{features → feature}/multi_line_string.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_point.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_polygon.rb +1 -1
- data/lib/rgeo/{features → feature}/multi_surface.rb +4 -4
- data/lib/rgeo/{features → feature}/point.rb +5 -5
- data/lib/rgeo/{features → feature}/polygon.rb +5 -5
- data/lib/rgeo/{features → feature}/surface.rb +4 -4
- data/lib/rgeo/feature/types.rb +301 -0
- data/lib/rgeo/geo_json.rb +1 -1
- data/lib/rgeo/geo_json/coder.rb +13 -13
- data/lib/rgeo/geo_json/interface.rb +2 -2
- data/lib/rgeo/geography.rb +33 -6
- data/lib/rgeo/geography/factory.rb +82 -39
- data/lib/rgeo/geography/interface.rb +135 -89
- data/lib/rgeo/geography/proj4_projector.rb +98 -0
- data/lib/rgeo/geography/projected_feature_classes.rb +213 -0
- data/lib/rgeo/geography/projected_feature_methods.rb +228 -0
- data/lib/rgeo/geography/projected_window.rb +7 -7
- data/lib/rgeo/geography/simple_mercator_projector.rb +133 -0
- data/lib/rgeo/geography/spherical_feature_classes.rb +212 -0
- data/lib/rgeo/geography/{simple_spherical/feature_methods.rb → spherical_feature_methods.rb} +39 -43
- data/lib/rgeo/geography/{simple_spherical/calculations.rb → spherical_math.rb} +7 -7
- data/lib/rgeo/geos.rb +1 -1
- data/lib/rgeo/geos/factory.rb +37 -19
- data/lib/rgeo/geos/impl_additions.rb +10 -11
- data/lib/rgeo/geos/interface.rb +1 -1
- data/lib/rgeo/geos/zm_factory.rb +15 -15
- data/lib/rgeo/geos/zm_impl.rb +10 -10
- data/lib/rgeo/{impl_helpers.rb → impl_helper.rb} +8 -8
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_geometry_collection_methods.rb +13 -13
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_geometry_methods.rb +2 -2
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_line_string_methods.rb +13 -13
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_point_methods.rb +5 -5
- data/lib/rgeo/{impl_helpers → impl_helper}/basic_polygon_methods.rb +6 -6
- data/lib/rgeo/{impl_helpers → impl_helper}/math.rb +1 -1
- data/lib/rgeo/shapefile.rb +1 -1
- data/lib/rgeo/shapefile/reader.rb +3 -3
- data/lib/rgeo/wkrep.rb +1 -1
- data/lib/rgeo/wkrep/wkb_generator.rb +17 -17
- data/lib/rgeo/wkrep/wkb_parser.rb +12 -12
- data/lib/rgeo/wkrep/wkt_generator.rb +8 -8
- data/lib/rgeo/wkrep/wkt_parser.rb +10 -10
- data/{tests → test}/active_record/readme.txt +0 -0
- data/{tests → test}/active_record/tc_mysqlspatial.rb +2 -2
- data/{tests → test}/common/geometry_collection_tests.rb +22 -22
- data/{tests → test}/common/line_string_tests.rb +20 -20
- data/{tests → test}/common/multi_line_string_tests.rb +19 -19
- data/{tests → test}/common/multi_point_tests.rb +17 -17
- data/{tests → test}/common/multi_polygon_tests.rb +16 -16
- data/{tests → test}/common/point_tests.rb +9 -9
- data/{tests → test}/common/polygon_tests.rb +9 -9
- data/test/coord_sys/tc_proj4.rb +111 -0
- data/{tests → test}/geos/tc_factory.rb +1 -1
- data/{tests → test}/geos/tc_geometry_collection.rb +1 -1
- data/{tests → test}/geos/tc_line_string.rb +0 -0
- data/{tests → test}/geos/tc_misc.rb +1 -1
- data/{tests → test}/geos/tc_multi_line_string.rb +1 -1
- data/{tests → test}/geos/tc_multi_point.rb +1 -1
- data/{tests → test}/geos/tc_multi_polygon.rb +1 -1
- data/{tests → test}/geos/tc_point.rb +1 -1
- data/{tests → test}/geos/tc_polygon.rb +0 -0
- data/{tests → test}/geos/tc_zmfactory.rb +2 -2
- data/test/projected_geography/tc_geometry_collection.rb +62 -0
- data/test/projected_geography/tc_line_string.rb +62 -0
- data/test/projected_geography/tc_multi_line_string.rb +62 -0
- data/test/projected_geography/tc_multi_point.rb +62 -0
- data/test/projected_geography/tc_multi_polygon.rb +63 -0
- data/test/projected_geography/tc_point.rb +93 -0
- data/test/projected_geography/tc_polygon.rb +62 -0
- data/{tests → test}/shapefile/shapelib_testcases/readme.txt +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test.dbf +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test0.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test0.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test1.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test1.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test10.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test10.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test11.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test11.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test12.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test12.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test13.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test13.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test2.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test2.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test3.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test3.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test4.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test4.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test5.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test5.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test6.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test6.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test7.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test7.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test8.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test8.shx +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test9.shp +0 -0
- data/{tests → test}/shapefile/shapelib_testcases/test9.shx +0 -0
- data/{tests → test}/shapefile/tc_shapelib_tests.rb +17 -17
- data/{tests → test}/simple_cartesian/tc_calculations.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_geometry_collection.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_line_string.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_multi_line_string.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_multi_point.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_multi_polygon.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_point.rb +0 -0
- data/{tests → test}/simple_cartesian/tc_polygon.rb +0 -0
- data/{tests → test}/simple_mercator/tc_geometry_collection.rb +1 -1
- data/{tests → test}/simple_mercator/tc_line_string.rb +0 -0
- data/{tests → test}/simple_mercator/tc_multi_line_string.rb +1 -1
- data/{tests → test}/simple_mercator/tc_multi_point.rb +1 -1
- data/{tests → test}/simple_mercator/tc_multi_polygon.rb +1 -1
- data/{tests → test}/simple_mercator/tc_point.rb +2 -2
- data/{tests → test}/simple_mercator/tc_polygon.rb +0 -0
- data/{tests → test}/simple_mercator/tc_window.rb +1 -1
- data/test/spherical_geography/tc_calculations.rb +203 -0
- data/{tests/simple_spherical → test/spherical_geography}/tc_geometry_collection.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_line_string.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_multi_line_string.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_multi_point.rb +2 -2
- data/{tests/simple_spherical → test/spherical_geography}/tc_multi_polygon.rb +3 -3
- data/{tests/simple_spherical → test/spherical_geography}/tc_point.rb +7 -7
- data/{tests/simple_spherical → test/spherical_geography}/tc_polygon.rb +2 -2
- data/{tests → test}/tc_cartesian_analysis.rb +0 -0
- data/{tests → test}/tc_geojson.rb +0 -0
- data/{tests → test}/tc_oneoff.rb +2 -1
- data/{tests → test}/wkrep/tc_wkb_generator.rb +0 -0
- data/{tests → test}/wkrep/tc_wkb_parser.rb +32 -32
- data/{tests → test}/wkrep/tc_wkt_generator.rb +0 -0
- data/{tests → test}/wkrep/tc_wkt_parser.rb +46 -46
- metadata +183 -164
- data/lib/rgeo/features/types.rb +0 -272
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +0 -279
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +0 -278
- data/lib/rgeo/geography/simple_mercator/projector.rb +0 -112
- data/lib/rgeo/geography/simple_spherical.rb +0 -68
- data/lib/rgeo/geography/simple_spherical/feature_classes.rb +0 -216
- data/tests/simple_spherical/tc_calculations.rb +0 -203
@@ -0,0 +1,275 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Proj4 wrapper for RGeo
|
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 CoordSys
|
40
|
+
|
41
|
+
|
42
|
+
# This is a Ruby wrapper around a Proj4 coordinate system.
|
43
|
+
# It represents a single geographic coordinate system, which may be
|
44
|
+
# a flat projection, a geocentric (3-dimensional) coordinate system,
|
45
|
+
# or a geographic (latitude-longitude) coordinate system.
|
46
|
+
#
|
47
|
+
# Generally, these are used to define the projection for a
|
48
|
+
# Feature::Factory. You can then convert between coordinate systems
|
49
|
+
# by casting geometries between such factories using the :project
|
50
|
+
# option. You may also use this object directly to perform low-level
|
51
|
+
# coordinate transformations.
|
52
|
+
|
53
|
+
class Proj4
|
54
|
+
|
55
|
+
|
56
|
+
def inspect # :nodoc:
|
57
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} #{_canonical_str.inspect}>"
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def to_s # :nodoc:
|
62
|
+
canonical_str
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def hash # :nodoc:
|
67
|
+
canonical_hash.hash
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# Returns true if this Proj4 is equivalent to the given Proj4.
|
72
|
+
#
|
73
|
+
# Note: this tests for equivalence by comparing only the hash
|
74
|
+
# definitions of the Proj4 objects, and returning true if those
|
75
|
+
# definitions are equivalent. In some cases, this may still return
|
76
|
+
# false even if the actual coordinate systems are identical, since
|
77
|
+
# there are sometimes multiple ways to express a given coordinate
|
78
|
+
# system.
|
79
|
+
|
80
|
+
def eql?(rhs_)
|
81
|
+
rhs_.is_a?(Proj4) && rhs_._canonical_hash == canonical_hash
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
# Returns the "canonical" string definition for this coordinate
|
86
|
+
# system, as reported by Proj4. This may be slightly different
|
87
|
+
# from the definition used to construct this object.
|
88
|
+
|
89
|
+
def canonical_str
|
90
|
+
unless defined?(@canonical_str)
|
91
|
+
@canonical_str = _canonical_str
|
92
|
+
end
|
93
|
+
@canonical_str
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# Returns the "canonical" hash definition for this coordinate
|
98
|
+
# system, as reported by Proj4. This may be slightly different
|
99
|
+
# from the definition used to construct this object.
|
100
|
+
|
101
|
+
def canonical_hash
|
102
|
+
unless defined?(@canonical_hash)
|
103
|
+
@canonical_hash = {}
|
104
|
+
canonical_str.strip.split(/\s+/).each do |elem_|
|
105
|
+
if elem_ =~ /^\+(\w+)(=(\S+))?$/
|
106
|
+
@canonical_hash[$1] = $3
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
@canonical_hash
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
# Returns the string definition originally used to construct this
|
115
|
+
# object. Returns nil if this object wasn't created by a string
|
116
|
+
# definition; i.e. if it was created using get_geographic.
|
117
|
+
|
118
|
+
def original_str
|
119
|
+
_original_str
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
# Returns true if this Proj4 object is a geographic (lat-long)
|
124
|
+
# coordinate system.
|
125
|
+
|
126
|
+
def geographic?
|
127
|
+
_geographic?
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
# Returns true if this Proj4 object is a geocentric (3dz)
|
132
|
+
# coordinate system.
|
133
|
+
|
134
|
+
def geocentric?
|
135
|
+
_geocentric?
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
# Get the geographic (unprojected lat-long) coordinate system
|
140
|
+
# corresponding to this coordinate system; i.e. the one that uses
|
141
|
+
# the same ellipsoid and datum.
|
142
|
+
|
143
|
+
def get_geographic
|
144
|
+
_get_geographic
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
class << self
|
149
|
+
|
150
|
+
|
151
|
+
# Returns true if Proj4 is supported in this installation.
|
152
|
+
# If this returns false, the other methods such as create
|
153
|
+
# will not work.
|
154
|
+
|
155
|
+
def supported?
|
156
|
+
respond_to?(:_create)
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
# Create a new Proj4 object, given a definition, which may be
|
161
|
+
# either a string or a hash. Returns nil if the given definition
|
162
|
+
# is invalid or Proj4 is not supported.
|
163
|
+
|
164
|
+
def create(defn_)
|
165
|
+
result_ = nil
|
166
|
+
if supported?
|
167
|
+
if defn_.kind_of?(::Hash)
|
168
|
+
defn_ = defn_.map{ |k_, v_| v_ ? "+#{k_}=#{v_}" : "+#{k_}" }.join(' ')
|
169
|
+
end
|
170
|
+
result_ = _create(defn_)
|
171
|
+
result_ = nil unless result_._valid?
|
172
|
+
end
|
173
|
+
result_
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
# Create a new Proj4 object, given a definition, which may be
|
178
|
+
# either a string or a hash. Raises Error::UnsupportedCapability
|
179
|
+
# if the given definition is invalid or Proj4 is not supported.
|
180
|
+
|
181
|
+
def new(defn_)
|
182
|
+
result_ = create(defn_)
|
183
|
+
unless result_
|
184
|
+
raise Error::UnsupportedCapability, "Proj4 not supported in this installation"
|
185
|
+
end
|
186
|
+
result_
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
# Low-level coordinate transform method.
|
191
|
+
# Transforms the given coordinate (x, y, [z]) from one proj4
|
192
|
+
# coordinate system to another. Returns an array with either two
|
193
|
+
# or three elements.
|
194
|
+
|
195
|
+
def transform_coords(from_proj_, to_proj_, x_, y_, z_=nil, opts_={})
|
196
|
+
degrees_ = !opts_[:radians]
|
197
|
+
if degrees_ && from_proj_._geographic?
|
198
|
+
x_ *= ImplHelper::Math::RADIANS_PER_DEGREE
|
199
|
+
y_ *= ImplHelper::Math::RADIANS_PER_DEGREE
|
200
|
+
end
|
201
|
+
result_ = _transform_coords(from_proj_, to_proj_, x_, y_, z_)
|
202
|
+
if result_ && degrees_ && to_proj_._geographic?
|
203
|
+
result_[0] *= ImplHelper::Math::DEGREES_PER_RADIAN
|
204
|
+
result_[1] *= ImplHelper::Math::DEGREES_PER_RADIAN
|
205
|
+
end
|
206
|
+
result_
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
# Low-level geometry transform method.
|
211
|
+
# Transforms the given geometry between the given two projections.
|
212
|
+
# The resulting geometry is constructed using the to_factory.
|
213
|
+
# Any projections associated with the factories themselves are
|
214
|
+
# ignored.
|
215
|
+
|
216
|
+
def transform(from_proj_, from_geometry_, to_proj_, to_factory_)
|
217
|
+
case from_geometry_
|
218
|
+
when Feature::Point
|
219
|
+
_transform_point(from_proj_, from_geometry_, to_proj_, to_factory_)
|
220
|
+
when Feature::Line
|
221
|
+
to_factory_.line(from_geometry_.points.map{ |p_| transform(from_proj_, p_, to_proj_, to_factory_) })
|
222
|
+
when Feature::LinearRing
|
223
|
+
_transform_linear_ring(from_proj_, from_geometry_, to_proj_, to_factory_)
|
224
|
+
when Feature::LineString
|
225
|
+
to_factory_.line_string(from_geometry_.points.map{ |p_| transform(from_proj_, p_, to_proj_, to_factory_) })
|
226
|
+
when Feature::Polygon
|
227
|
+
_transform_polygon(from_proj_, from_geometry_, to_proj_, to_factory_)
|
228
|
+
when Feature::MultiPoint
|
229
|
+
to_factory_.multi_point(from_geometry_.map{ |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
230
|
+
when Feature::MultiLineString
|
231
|
+
to_factory_.multi_line_string(from_geometry_.map{ |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
|
232
|
+
when Feature::MultiPolygon
|
233
|
+
to_factory_.multi_polygon(from_geometry_.map{ |p_| _transform_polygon(from_proj_, p_, to_proj_, to_factory_) })
|
234
|
+
when Feature::GeometryCollection
|
235
|
+
to_factory_.collection(from_geometry_.map{ |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
def _transform_point(from_proj_, from_point_, to_proj_, to_factory_) # :nodoc:
|
241
|
+
from_factory_ = from_point_.factory
|
242
|
+
from_has_z_ = from_factory_.has_capability?(:z_coordinate)
|
243
|
+
from_has_m_ = from_factory_.has_capability?(:m_coordinate)
|
244
|
+
to_has_z_ = to_factory_.has_capability?(:z_coordinate)
|
245
|
+
to_has_m_ = to_factory_.has_capability?(:m_coordinate)
|
246
|
+
coords_ = _transform_coords(from_proj_, to_proj_, from_point_.x, from_point_.y,
|
247
|
+
from_has_z_ ? from_point_.z : nil)
|
248
|
+
extras_ = []
|
249
|
+
extras_ << coords_[2].to_f if to_has_z_
|
250
|
+
extras_ << from_has_m_ ? from_point_.m : 0.0 if to_has_m_?
|
251
|
+
to_factory_.point(coords_[0], coords_[1], extras_)
|
252
|
+
end
|
253
|
+
|
254
|
+
|
255
|
+
def _transform_linear_ring(from_proj_, from_ring_, to_proj_, to_factory_) # :nodoc:
|
256
|
+
to_factory_.linear_ring(from_ring_.points[0..-2].map{ |p_| transform(from_proj_, p_, to_proj_, to_factory_) })
|
257
|
+
end
|
258
|
+
|
259
|
+
|
260
|
+
def _transform_polygon(from_proj_, from_polygon_, to_proj_, to_factory_) # :nodoc:
|
261
|
+
ext_ = _transform_linear_ring(from_proj_, from_polygon_.exterior_ring, to_proj_, to_factory_)
|
262
|
+
int_ = from_polygon_.interior_rings.map{ |r_| _transform_linear_ring(from_proj_, r_, to_proj_, to_factory_) }
|
263
|
+
to_factory_.polygon(ext_, int_)
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
@@ -43,21 +43,17 @@ module RGeo
|
|
43
43
|
|
44
44
|
# All RGeo errors are members of this namespace.
|
45
45
|
|
46
|
-
module
|
46
|
+
module Error
|
47
47
|
|
48
48
|
# Base class for all RGeo-related exceptions
|
49
49
|
class RGeoError < ::RuntimeError
|
50
50
|
end
|
51
51
|
|
52
|
-
# The method is unimplemented
|
53
|
-
class MethodUnimplemented < RGeoError
|
54
|
-
end
|
55
|
-
|
56
52
|
# The specified geometry is invalid
|
57
53
|
class InvalidGeometry < RGeoError
|
58
54
|
end
|
59
55
|
|
60
|
-
# The specified capability is not supported
|
56
|
+
# The specified capability is not supported or not implemented
|
61
57
|
class UnsupportedCapability < RGeoError
|
62
58
|
end
|
63
59
|
|
@@ -67,5 +63,8 @@ module RGeo
|
|
67
63
|
|
68
64
|
end
|
69
65
|
|
66
|
+
# Deprecated alias
|
67
|
+
Errors = Error
|
68
|
+
|
70
69
|
|
71
70
|
end
|
@@ -41,7 +41,7 @@ require 'rgeo'
|
|
41
41
|
module RGeo
|
42
42
|
|
43
43
|
|
44
|
-
# The
|
44
|
+
# The Feature namespace contains interfaces and general tools for
|
45
45
|
# implementations of the Open Geospatial Consortium Simple Features
|
46
46
|
# Specification (SFS), version 1.1.0.
|
47
47
|
#
|
@@ -65,31 +65,33 @@ module RGeo
|
|
65
65
|
# itself. The implementation should separately document any such
|
66
66
|
# extensions that it may provide.
|
67
67
|
|
68
|
-
module
|
68
|
+
module Feature
|
69
69
|
end
|
70
70
|
|
71
|
+
# Deprecated alias
|
72
|
+
Features = Feature
|
73
|
+
|
71
74
|
|
72
75
|
end
|
73
76
|
|
74
77
|
|
75
78
|
# Dependency files
|
76
|
-
require 'rgeo/
|
79
|
+
require 'rgeo/error'
|
77
80
|
|
78
81
|
# Implementation files
|
79
|
-
require 'rgeo/
|
80
|
-
require 'rgeo/
|
81
|
-
require 'rgeo/
|
82
|
-
require 'rgeo/
|
83
|
-
require 'rgeo/
|
84
|
-
require 'rgeo/
|
85
|
-
require 'rgeo/
|
86
|
-
require 'rgeo/
|
87
|
-
require 'rgeo/
|
88
|
-
require 'rgeo/
|
89
|
-
require 'rgeo/
|
90
|
-
require 'rgeo/
|
91
|
-
require 'rgeo/
|
92
|
-
require 'rgeo/
|
93
|
-
require 'rgeo/
|
94
|
-
require 'rgeo/
|
95
|
-
|
82
|
+
require 'rgeo/feature/factory'
|
83
|
+
require 'rgeo/feature/types'
|
84
|
+
require 'rgeo/feature/geometry'
|
85
|
+
require 'rgeo/feature/point'
|
86
|
+
require 'rgeo/feature/curve'
|
87
|
+
require 'rgeo/feature/line_string'
|
88
|
+
require 'rgeo/feature/linear_ring'
|
89
|
+
require 'rgeo/feature/line'
|
90
|
+
require 'rgeo/feature/surface'
|
91
|
+
require 'rgeo/feature/polygon'
|
92
|
+
require 'rgeo/feature/geometry_collection'
|
93
|
+
require 'rgeo/feature/multi_point'
|
94
|
+
require 'rgeo/feature/multi_curve'
|
95
|
+
require 'rgeo/feature/multi_line_string'
|
96
|
+
require 'rgeo/feature/multi_surface'
|
97
|
+
require 'rgeo/feature/multi_polygon'
|
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
module RGeo
|
38
38
|
|
39
|
-
module
|
39
|
+
module Feature
|
40
40
|
|
41
41
|
|
42
42
|
# == SFS 1.1 Description
|
@@ -88,7 +88,7 @@ module RGeo
|
|
88
88
|
# Returns a floating-point scalar value.
|
89
89
|
|
90
90
|
def length
|
91
|
-
raise
|
91
|
+
raise Error::UnsupportedCapability, "Method Curve#length not defined."
|
92
92
|
end
|
93
93
|
|
94
94
|
|
@@ -101,7 +101,7 @@ module RGeo
|
|
101
101
|
# Returns an object that supports the Point interface.
|
102
102
|
|
103
103
|
def start_point
|
104
|
-
raise
|
104
|
+
raise Error::UnsupportedCapability, "Method Curve#start_point not defined."
|
105
105
|
end
|
106
106
|
|
107
107
|
|
@@ -114,7 +114,7 @@ module RGeo
|
|
114
114
|
# Returns an object that supports the Point interface.
|
115
115
|
|
116
116
|
def end_point
|
117
|
-
raise
|
117
|
+
raise Error::UnsupportedCapability, "Method Curve#end_point not defined."
|
118
118
|
end
|
119
119
|
|
120
120
|
|
@@ -128,7 +128,7 @@ module RGeo
|
|
128
128
|
# specification, which stipulates an integer return value.
|
129
129
|
|
130
130
|
def is_closed?
|
131
|
-
raise
|
131
|
+
raise Error::UnsupportedCapability, "Method Curve#is_closed? not defined."
|
132
132
|
end
|
133
133
|
|
134
134
|
|
@@ -144,7 +144,7 @@ module RGeo
|
|
144
144
|
# specification, which stipulates an integer return value.
|
145
145
|
|
146
146
|
def is_ring?
|
147
|
-
raise
|
147
|
+
raise Error::UnsupportedCapability, "Method Curve#is_ring? not defined."
|
148
148
|
end
|
149
149
|
|
150
150
|
|
@@ -36,11 +36,11 @@
|
|
36
36
|
|
37
37
|
module RGeo
|
38
38
|
|
39
|
-
module
|
39
|
+
module Feature
|
40
40
|
|
41
41
|
|
42
42
|
# This is a standard interface for factories of features.
|
43
|
-
# Generally, each
|
43
|
+
# Generally, each Feature implementation will implement these
|
44
44
|
# methods as a standard way to create features.
|
45
45
|
#
|
46
46
|
# If the implementation is unable to create the given feature,
|
@@ -96,6 +96,9 @@ module RGeo
|
|
96
96
|
# Supports an "m" coordinate. When an implementation supports
|
97
97
|
# this capability, geometries know about M coordinates, and the
|
98
98
|
# Point#m method is available.
|
99
|
+
# <tt>:proj4</tt>::
|
100
|
+
# Has a proj4-defined projection. When an implementation supports
|
101
|
+
# this capability, the Factory#proj4 method is available.
|
99
102
|
|
100
103
|
def has_capability?(name_)
|
101
104
|
nil
|
@@ -238,7 +241,7 @@ module RGeo
|
|
238
241
|
#
|
239
242
|
# It should return either a casted result object, false, or nil.
|
240
243
|
# A nil return value indicates that casting should be forced to
|
241
|
-
# fail (and ::RGeo::
|
244
|
+
# fail (and ::RGeo::Feature::cast will return nil).
|
242
245
|
# A false return value indicates that this method declines to
|
243
246
|
# override the casting algorithm, and RGeo should use its default
|
244
247
|
# algorithm to cast the object. Therefore, by default, you should
|
@@ -249,6 +252,19 @@ module RGeo
|
|
249
252
|
end
|
250
253
|
|
251
254
|
|
255
|
+
# This is an optional method that returns a RGeo::CoordSys::Proj4
|
256
|
+
# representing the projection for the coordinate system of features
|
257
|
+
# created by this factory, or nil if there is no such proj4
|
258
|
+
# projection.
|
259
|
+
#
|
260
|
+
# If a factory supports this method, it should indicate this by
|
261
|
+
# returning true for the <tt>:proj4</tt> capability.
|
262
|
+
|
263
|
+
def proj4
|
264
|
+
nil
|
265
|
+
end
|
266
|
+
|
267
|
+
|
252
268
|
end
|
253
269
|
|
254
270
|
|