rgeo 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +29 -0
- data/ext/geos_c_impl/Makefile_2.2.3 +260 -0
- data/ext/geos_c_impl/coordinates.c +65 -0
- data/ext/geos_c_impl/coordinates.h +2 -0
- data/ext/geos_c_impl/extconf.rb +19 -43
- data/ext/geos_c_impl/geometry.c +24 -0
- data/ext/geos_c_impl/geometry_collection.c +99 -1
- data/ext/geos_c_impl/geos_c_impl_2.2.3.bundle +0 -0
- data/ext/geos_c_impl/line_string.c +38 -0
- data/ext/geos_c_impl/mkmf.log +123 -0
- data/ext/geos_c_impl/point.c +27 -0
- data/ext/geos_c_impl/polygon.c +26 -0
- data/ext/proj4_c_impl/Makefile_2.2.3 +260 -0
- data/ext/proj4_c_impl/extconf.rb +32 -32
- data/ext/proj4_c_impl/mkmf.log +47 -0
- data/ext/proj4_c_impl/proj4_c_impl_2.2.3.bundle +0 -0
- data/lib/rgeo.rb +10 -11
- data/lib/rgeo/cartesian.rb +7 -12
- data/lib/rgeo/cartesian/analysis.rb +13 -26
- data/lib/rgeo/cartesian/bounding_box.rb +45 -114
- data/lib/rgeo/cartesian/calculations.rb +3 -21
- data/lib/rgeo/cartesian/factory.rb +101 -122
- data/lib/rgeo/cartesian/feature_classes.rb +9 -59
- data/lib/rgeo/cartesian/feature_methods.rb +15 -45
- data/lib/rgeo/cartesian/interface.rb +6 -17
- data/lib/rgeo/coord_sys.rb +9 -15
- data/lib/rgeo/coord_sys/cs/entities.rb +84 -330
- data/lib/rgeo/coord_sys/cs/factories.rb +2 -32
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +52 -80
- data/lib/rgeo/coord_sys/proj4.rb +28 -67
- data/lib/rgeo/coord_sys/proj4_c_impl.bundle +0 -0
- data/lib/rgeo/coord_sys/srs_database/interface.rb +4 -24
- data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +20 -38
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +6 -22
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +6 -21
- data/lib/rgeo/error.rb +0 -6
- data/lib/rgeo/feature.rb +18 -23
- data/lib/rgeo/feature/curve.rb +0 -14
- data/lib/rgeo/feature/factory.rb +13 -38
- data/lib/rgeo/feature/factory_generator.rb +4 -16
- data/lib/rgeo/feature/geometry.rb +18 -60
- data/lib/rgeo/feature/geometry_collection.rb +3 -17
- data/lib/rgeo/feature/line.rb +0 -10
- data/lib/rgeo/feature/line_string.rb +1 -13
- data/lib/rgeo/feature/linear_ring.rb +0 -9
- data/lib/rgeo/feature/mixins.rb +11 -36
- data/lib/rgeo/feature/multi_curve.rb +0 -11
- data/lib/rgeo/feature/multi_line_string.rb +0 -9
- data/lib/rgeo/feature/multi_point.rb +0 -9
- data/lib/rgeo/feature/multi_polygon.rb +0 -9
- data/lib/rgeo/feature/multi_surface.rb +0 -12
- data/lib/rgeo/feature/point.rb +0 -13
- data/lib/rgeo/feature/polygon.rb +1 -14
- data/lib/rgeo/feature/surface.rb +0 -12
- data/lib/rgeo/feature/types.rb +19 -61
- data/lib/rgeo/geographic.rb +10 -15
- data/lib/rgeo/geographic/factory.rb +126 -147
- data/lib/rgeo/geographic/interface.rb +67 -81
- data/lib/rgeo/geographic/proj4_projector.rb +13 -37
- data/lib/rgeo/geographic/projected_feature_classes.rb +7 -66
- data/lib/rgeo/geographic/projected_feature_methods.rb +15 -80
- data/lib/rgeo/geographic/projected_window.rb +15 -67
- data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -56
- data/lib/rgeo/geographic/spherical_feature_classes.rb +9 -68
- data/lib/rgeo/geographic/spherical_feature_methods.rb +18 -51
- data/lib/rgeo/geographic/spherical_math.rb +26 -51
- data/lib/rgeo/geos.rb +23 -20
- data/lib/rgeo/geos/capi_factory.rb +125 -131
- data/lib/rgeo/geos/capi_feature_classes.rb +21 -88
- data/lib/rgeo/geos/ffi_factory.rb +90 -143
- data/lib/rgeo/geos/ffi_feature_classes.rb +8 -63
- data/lib/rgeo/geos/ffi_feature_methods.rb +46 -162
- data/lib/rgeo/geos/geos_c_impl.bundle +0 -0
- data/lib/rgeo/geos/interface.rb +4 -23
- data/lib/rgeo/geos/utils.rb +4 -19
- data/lib/rgeo/geos/zm_factory.rb +82 -131
- data/lib/rgeo/geos/zm_feature_classes.rb +8 -63
- data/lib/rgeo/geos/zm_feature_methods.rb +34 -107
- data/lib/rgeo/impl_helper.rb +8 -13
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +27 -71
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +10 -28
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +21 -57
- data/lib/rgeo/impl_helper/basic_point_methods.rb +12 -30
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +9 -28
- data/lib/rgeo/impl_helper/math.rb +4 -10
- data/lib/rgeo/impl_helper/utils.rb +2 -10
- data/lib/rgeo/version.rb +1 -1
- data/lib/rgeo/wkrep.rb +4 -9
- data/lib/rgeo/wkrep/wkb_generator.rb +22 -46
- data/lib/rgeo/wkrep/wkb_parser.rb +25 -52
- data/lib/rgeo/wkrep/wkt_generator.rb +39 -69
- data/lib/rgeo/wkrep/wkt_parser.rb +52 -89
- data/lib/rgeo/yaml.rb +1 -7
- data/test/common/factory_tests.rb +4 -19
- data/test/common/geometry_collection_tests.rb +6 -39
- data/test/common/line_string_tests.rb +10 -39
- data/test/common/multi_line_string_tests.rb +10 -30
- data/test/common/multi_point_tests.rb +15 -34
- data/test/common/multi_polygon_tests.rb +26 -28
- data/test/common/point_tests.rb +37 -59
- data/test/common/polygon_tests.rb +16 -25
- data/test/coord_sys/tc_ogc_cs.rb +151 -186
- data/test/coord_sys/tc_proj4.rb +35 -60
- data/test/coord_sys/tc_proj4_srs_data.rb +15 -24
- data/test/coord_sys/tc_sr_org.rb +11 -19
- data/test/coord_sys/tc_url_reader.rb +13 -23
- data/test/geos_capi/tc_factory.rb +7 -16
- data/test/geos_capi/tc_geometry_collection.rb +6 -14
- data/test/geos_capi/tc_line_string.rb +7 -15
- data/test/geos_capi/tc_misc.rb +26 -41
- data/test/geos_capi/tc_multi_line_string.rb +6 -14
- data/test/geos_capi/tc_multi_point.rb +7 -15
- data/test/geos_capi/tc_multi_polygon.rb +8 -18
- data/test/geos_capi/tc_parsing_unparsing.rb +11 -21
- data/test/geos_capi/tc_point.rb +12 -26
- data/test/geos_capi/tc_polygon.rb +52 -17
- data/test/geos_capi/tc_zmfactory.rb +7 -18
- data/test/geos_ffi/tc_factory.rb +7 -16
- data/test/geos_ffi/tc_geometry_collection.rb +7 -15
- data/test/geos_ffi/tc_line_string.rb +7 -15
- data/test/geos_ffi/tc_misc.rb +8 -18
- data/test/geos_ffi/tc_multi_line_string.rb +7 -15
- data/test/geos_ffi/tc_multi_point.rb +8 -16
- data/test/geos_ffi/tc_multi_polygon.rb +9 -18
- data/test/geos_ffi/tc_parsing_unparsing.rb +14 -24
- data/test/geos_ffi/tc_point.rb +13 -28
- data/test/geos_ffi/tc_polygon.rb +7 -17
- data/test/geos_ffi/tc_zmfactory.rb +8 -19
- data/test/projected_geographic/tc_factory.rb +7 -15
- data/test/projected_geographic/tc_geometry_collection.rb +7 -15
- data/test/projected_geographic/tc_line_string.rb +7 -15
- data/test/projected_geographic/tc_multi_line_string.rb +7 -16
- data/test/projected_geographic/tc_multi_point.rb +8 -17
- data/test/projected_geographic/tc_multi_polygon.rb +8 -16
- data/test/projected_geographic/tc_point.rb +11 -23
- data/test/projected_geographic/tc_polygon.rb +7 -15
- data/test/simple_cartesian/tc_calculations.rb +6 -22
- data/test/simple_cartesian/tc_factory.rb +7 -16
- data/test/simple_cartesian/tc_geometry_collection.rb +6 -15
- data/test/simple_cartesian/tc_line_string.rb +6 -15
- data/test/simple_cartesian/tc_multi_line_string.rb +6 -15
- data/test/simple_cartesian/tc_multi_point.rb +7 -16
- data/test/simple_cartesian/tc_multi_polygon.rb +7 -16
- data/test/simple_cartesian/tc_point.rb +10 -21
- data/test/simple_cartesian/tc_polygon.rb +6 -15
- data/test/simple_mercator/tc_factory.rb +6 -14
- data/test/simple_mercator/tc_geometry_collection.rb +6 -14
- data/test/simple_mercator/tc_line_string.rb +6 -14
- data/test/simple_mercator/tc_multi_line_string.rb +6 -15
- data/test/simple_mercator/tc_multi_point.rb +7 -16
- data/test/simple_mercator/tc_multi_polygon.rb +7 -15
- data/test/simple_mercator/tc_point.rb +11 -24
- data/test/simple_mercator/tc_polygon.rb +6 -14
- data/test/simple_mercator/tc_window.rb +10 -34
- data/test/spherical_geographic/tc_calculations.rb +5 -32
- data/test/spherical_geographic/tc_factory.rb +6 -15
- data/test/spherical_geographic/tc_geometry_collection.rb +6 -15
- data/test/spherical_geographic/tc_line_string.rb +6 -15
- data/test/spherical_geographic/tc_multi_line_string.rb +6 -15
- data/test/spherical_geographic/tc_multi_point.rb +7 -16
- data/test/spherical_geographic/tc_multi_polygon.rb +7 -16
- data/test/spherical_geographic/tc_point.rb +10 -22
- data/test/spherical_geographic/tc_polygon.rb +6 -15
- data/test/tc_cartesian_analysis.rb +4 -16
- data/test/tc_cartesian_bbox.rb +7 -21
- data/test/tc_mixins.rb +8 -25
- data/test/tc_oneoff.rb +5 -13
- data/test/tc_types.rb +7 -16
- data/test/wkrep/tc_wkb_generator.rb +63 -97
- data/test/wkrep/tc_wkb_parser.rb +63 -100
- data/test/wkrep/tc_wkt_generator.rb +54 -92
- data/test/wkrep/tc_wkt_parser.rb +84 -133
- metadata +39 -9
- data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +0 -166
- data/test/coord_sys/tc_active_record_table.rb +0 -79
data/lib/rgeo/coord_sys/proj4.rb
CHANGED
@@ -5,10 +5,7 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module CoordSys
|
10
|
-
|
11
|
-
|
12
9
|
# This is a Ruby wrapper around a Proj4 coordinate system.
|
13
10
|
# It represents a single geographic coordinate system, which may be
|
14
11
|
# a flat projection, a geocentric (3-dimensional) coordinate system,
|
@@ -21,23 +18,18 @@ module RGeo
|
|
21
18
|
# coordinate transformations.
|
22
19
|
|
23
20
|
class Proj4
|
24
|
-
|
25
|
-
|
26
|
-
def inspect # :nodoc:
|
21
|
+
def inspect # :nodoc:
|
27
22
|
"#<#{self.class}:0x#{object_id.to_s(16)} #{canonical_str.inspect}>"
|
28
23
|
end
|
29
24
|
|
30
|
-
|
31
25
|
def to_s # :nodoc:
|
32
26
|
canonical_str
|
33
27
|
end
|
34
28
|
|
35
|
-
|
36
29
|
def hash # :nodoc:
|
37
30
|
@hash ||= canonical_hash.hash
|
38
31
|
end
|
39
32
|
|
40
|
-
|
41
33
|
# Returns true if this Proj4 is equivalent to the given Proj4.
|
42
34
|
#
|
43
35
|
# Note: this tests for equivalence by comparing only the hash
|
@@ -52,34 +44,31 @@ module RGeo
|
|
52
44
|
end
|
53
45
|
alias_method :==, :eql?
|
54
46
|
|
55
|
-
|
56
47
|
# Marshal support
|
57
48
|
|
58
|
-
def marshal_dump
|
59
|
-
{
|
49
|
+
def marshal_dump # :nodoc:
|
50
|
+
{ "rad" => radians?, "str" => original_str || canonical_str }
|
60
51
|
end
|
61
52
|
|
62
|
-
def marshal_load(data_)
|
63
|
-
_set_value(data_[
|
53
|
+
def marshal_load(data_) # :nodoc:
|
54
|
+
_set_value(data_["str"], data_["rad"])
|
64
55
|
end
|
65
56
|
|
66
|
-
|
67
57
|
# Psych support
|
68
58
|
|
69
|
-
def encode_with(coder_)
|
70
|
-
coder_[
|
71
|
-
coder_[
|
59
|
+
def encode_with(coder_) # :nodoc:
|
60
|
+
coder_["proj4"] = original_str || canonical_str
|
61
|
+
coder_["radians"] = radians?
|
72
62
|
end
|
73
63
|
|
74
|
-
def init_with(coder_)
|
64
|
+
def init_with(coder_) # :nodoc:
|
75
65
|
if coder_.type == :scalar
|
76
66
|
_set_value(coder_.scalar, false)
|
77
67
|
else
|
78
|
-
_set_value(coder_[
|
68
|
+
_set_value(coder_["proj4"], coder_["radians"])
|
79
69
|
end
|
80
70
|
end
|
81
71
|
|
82
|
-
|
83
72
|
# Returns the "canonical" string definition for this coordinate
|
84
73
|
# system, as reported by Proj4. This may be slightly different
|
85
74
|
# from the definition used to construct this object.
|
@@ -88,13 +77,12 @@ module RGeo
|
|
88
77
|
unless defined?(@canonical_str)
|
89
78
|
@canonical_str = _canonical_str
|
90
79
|
if @canonical_str.respond_to?(:force_encoding)
|
91
|
-
@canonical_str.force_encoding(
|
80
|
+
@canonical_str.force_encoding("US-ASCII")
|
92
81
|
end
|
93
82
|
end
|
94
83
|
@canonical_str
|
95
84
|
end
|
96
85
|
|
97
|
-
|
98
86
|
# Returns the "canonical" hash definition for this coordinate
|
99
87
|
# system, as reported by Proj4. This may be slightly different
|
100
88
|
# from the definition used to construct this object.
|
@@ -103,15 +91,12 @@ module RGeo
|
|
103
91
|
unless defined?(@canonical_hash)
|
104
92
|
@canonical_hash = {}
|
105
93
|
canonical_str.strip.split(/\s+/).each do |elem_|
|
106
|
-
if elem_ =~ /^\+(\w+)(=(\S+))?$/
|
107
|
-
@canonical_hash[$1] = $3
|
108
|
-
end
|
94
|
+
@canonical_hash[Regexp.last_match(1)] = Regexp.last_match(3) if elem_ =~ /^\+(\w+)(=(\S+))?$/
|
109
95
|
end
|
110
96
|
end
|
111
97
|
@canonical_hash
|
112
98
|
end
|
113
99
|
|
114
|
-
|
115
100
|
# Returns the string definition originally used to construct this
|
116
101
|
# object. Returns nil if this object wasn't created by a string
|
117
102
|
# definition; i.e. if it was created using get_geographic.
|
@@ -120,7 +105,6 @@ module RGeo
|
|
120
105
|
_original_str
|
121
106
|
end
|
122
107
|
|
123
|
-
|
124
108
|
# Returns true if this Proj4 object is a geographic (lat-long)
|
125
109
|
# coordinate system.
|
126
110
|
|
@@ -128,7 +112,6 @@ module RGeo
|
|
128
112
|
_geographic?
|
129
113
|
end
|
130
114
|
|
131
|
-
|
132
115
|
# Returns true if this Proj4 object is a geocentric (3dz)
|
133
116
|
# coordinate system.
|
134
117
|
|
@@ -136,7 +119,6 @@ module RGeo
|
|
136
119
|
_geocentric?
|
137
120
|
end
|
138
121
|
|
139
|
-
|
140
122
|
# Returns true if this Proj4 object uses radians rather than degrees
|
141
123
|
# if it is a geographic coordinate system.
|
142
124
|
|
@@ -144,7 +126,6 @@ module RGeo
|
|
144
126
|
_radians?
|
145
127
|
end
|
146
128
|
|
147
|
-
|
148
129
|
# Get the geographic (unprojected lat-long) coordinate system
|
149
130
|
# corresponding to this coordinate system; i.e. the one that uses
|
150
131
|
# the same ellipsoid and datum.
|
@@ -153,10 +134,7 @@ module RGeo
|
|
153
134
|
_get_geographic
|
154
135
|
end
|
155
136
|
|
156
|
-
|
157
137
|
class << self
|
158
|
-
|
159
|
-
|
160
138
|
# Returns true if Proj4 is supported in this installation.
|
161
139
|
# If this returns false, the other methods such as create
|
162
140
|
# will not work.
|
@@ -165,14 +143,12 @@ module RGeo
|
|
165
143
|
respond_to?(:_create)
|
166
144
|
end
|
167
145
|
|
168
|
-
|
169
146
|
# Returns the Proj library version as a string of the format "x.y.z".
|
170
147
|
|
171
148
|
def version
|
172
149
|
::RGeo::VERSION
|
173
150
|
end
|
174
151
|
|
175
|
-
|
176
152
|
# Create a new Proj4 object, given a definition, which may be
|
177
153
|
# either a string or a hash. Returns nil if the given definition
|
178
154
|
# is invalid or Proj4 is not supported.
|
@@ -190,11 +166,11 @@ module RGeo
|
|
190
166
|
# coordinate system, this has no effect. Default is false.
|
191
167
|
# (That is all coordinates are in degrees by default.)
|
192
168
|
|
193
|
-
def create(defn_, opts_={})
|
169
|
+
def create(defn_, opts_ = {})
|
194
170
|
result_ = nil
|
195
171
|
if supported?
|
196
|
-
if defn_.
|
197
|
-
defn_ = defn_.map{ |k_, v_| v_ ? "+#{k_}=#{v_}" : "+#{k_}" }.join(
|
172
|
+
if defn_.is_a?(::Hash)
|
173
|
+
defn_ = defn_.map { |k_, v_| v_ ? "+#{k_}=#{v_}" : "+#{k_}" }.join(" ")
|
198
174
|
end
|
199
175
|
unless defn_ =~ /^\s*\+/
|
200
176
|
defn_ = defn_.sub(/^(\s*)/, '\1+').gsub(/(\s+)([^+\s])/, '\1+\2')
|
@@ -205,7 +181,6 @@ module RGeo
|
|
205
181
|
result_
|
206
182
|
end
|
207
183
|
|
208
|
-
|
209
184
|
# Create a new Proj4 object, given a definition, which may be
|
210
185
|
# either a string or a hash. Raises Error::UnsupportedOperation
|
211
186
|
# if the given definition is invalid or Proj4 is not supported.
|
@@ -223,7 +198,7 @@ module RGeo
|
|
223
198
|
# coordinate system, this has no effect. Default is false.
|
224
199
|
# (That is all coordinates are in degrees by default.)
|
225
200
|
|
226
|
-
def new(defn_, opts_={})
|
201
|
+
def new(defn_, opts_ = {})
|
227
202
|
result_ = create(defn_, opts_)
|
228
203
|
unless result_
|
229
204
|
raise Error::UnsupportedOperation, "Proj4 not supported in this installation"
|
@@ -231,13 +206,12 @@ module RGeo
|
|
231
206
|
result_
|
232
207
|
end
|
233
208
|
|
234
|
-
|
235
209
|
# Low-level coordinate transform method.
|
236
210
|
# Transforms the given coordinate (x, y, [z]) from one proj4
|
237
211
|
# coordinate system to another. Returns an array with either two
|
238
212
|
# or three elements.
|
239
213
|
|
240
|
-
def transform_coords(from_proj_, to_proj_, x_, y_, z_=nil)
|
214
|
+
def transform_coords(from_proj_, to_proj_, x_, y_, z_ = nil)
|
241
215
|
if !from_proj_._radians? && from_proj_._geographic?
|
242
216
|
x_ *= ImplHelper::Math::RADIANS_PER_DEGREE
|
243
217
|
y_ *= ImplHelper::Math::RADIANS_PER_DEGREE
|
@@ -250,7 +224,6 @@ module RGeo
|
|
250
224
|
result_
|
251
225
|
end
|
252
226
|
|
253
|
-
|
254
227
|
# Low-level geometry transform method.
|
255
228
|
# Transforms the given geometry between the given two projections.
|
256
229
|
# The resulting geometry is constructed using the to_factory.
|
@@ -262,26 +235,25 @@ module RGeo
|
|
262
235
|
when Feature::Point
|
263
236
|
_transform_point(from_proj_, from_geometry_, to_proj_, to_factory_)
|
264
237
|
when Feature::Line
|
265
|
-
to_factory_.line(from_geometry_.points.map{ |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
238
|
+
to_factory_.line(from_geometry_.points.map { |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
266
239
|
when Feature::LinearRing
|
267
240
|
_transform_linear_ring(from_proj_, from_geometry_, to_proj_, to_factory_)
|
268
241
|
when Feature::LineString
|
269
|
-
to_factory_.line_string(from_geometry_.points.map{ |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
242
|
+
to_factory_.line_string(from_geometry_.points.map { |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
270
243
|
when Feature::Polygon
|
271
244
|
_transform_polygon(from_proj_, from_geometry_, to_proj_, to_factory_)
|
272
245
|
when Feature::MultiPoint
|
273
|
-
to_factory_.multi_point(from_geometry_.map{ |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
246
|
+
to_factory_.multi_point(from_geometry_.map { |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
274
247
|
when Feature::MultiLineString
|
275
|
-
to_factory_.multi_line_string(from_geometry_.map{ |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
|
248
|
+
to_factory_.multi_line_string(from_geometry_.map { |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
|
276
249
|
when Feature::MultiPolygon
|
277
|
-
to_factory_.multi_polygon(from_geometry_.map{ |p_| _transform_polygon(from_proj_, p_, to_proj_, to_factory_) })
|
250
|
+
to_factory_.multi_polygon(from_geometry_.map { |p_| _transform_polygon(from_proj_, p_, to_proj_, to_factory_) })
|
278
251
|
when Feature::GeometryCollection
|
279
|
-
to_factory_.collection(from_geometry_.map{ |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
|
252
|
+
to_factory_.collection(from_geometry_.map { |g_| transform(from_proj_, g_, to_proj_, to_factory_) })
|
280
253
|
end
|
281
254
|
end
|
282
255
|
|
283
|
-
|
284
|
-
def _transform_point(from_proj_, from_point_, to_proj_, to_factory_) # :nodoc:
|
256
|
+
def _transform_point(from_proj_, from_point_, to_proj_, to_factory_) # :nodoc:
|
285
257
|
from_factory_ = from_point_.factory
|
286
258
|
from_has_z_ = from_factory_.property(:has_z_coordinate)
|
287
259
|
from_has_m_ = from_factory_.property(:has_m_coordinate)
|
@@ -303,30 +275,19 @@ module RGeo
|
|
303
275
|
extras_ << coords_[2].to_f if to_has_z_
|
304
276
|
extras_ << from_has_m_ ? from_point_.m : 0.0 if to_has_m_
|
305
277
|
to_factory_.point(coords_[0], coords_[1], *extras_)
|
306
|
-
else
|
307
|
-
nil
|
308
278
|
end
|
309
279
|
end
|
310
280
|
|
311
|
-
|
312
|
-
|
313
|
-
to_factory_.linear_ring(from_ring_.points[0..-2].map{ |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
281
|
+
def _transform_linear_ring(from_proj_, from_ring_, to_proj_, to_factory_) # :nodoc:
|
282
|
+
to_factory_.linear_ring(from_ring_.points[0..-2].map { |p_| _transform_point(from_proj_, p_, to_proj_, to_factory_) })
|
314
283
|
end
|
315
284
|
|
316
|
-
|
317
|
-
def _transform_polygon(from_proj_, from_polygon_, to_proj_, to_factory_) # :nodoc:
|
285
|
+
def _transform_polygon(from_proj_, from_polygon_, to_proj_, to_factory_) # :nodoc:
|
318
286
|
ext_ = _transform_linear_ring(from_proj_, from_polygon_.exterior_ring, to_proj_, to_factory_)
|
319
|
-
int_ = from_polygon_.interior_rings.map{ |r_| _transform_linear_ring(from_proj_, r_, to_proj_, to_factory_) }
|
287
|
+
int_ = from_polygon_.interior_rings.map { |r_| _transform_linear_ring(from_proj_, r_, to_proj_, to_factory_) }
|
320
288
|
to_factory_.polygon(ext_, int_)
|
321
289
|
end
|
322
|
-
|
323
|
-
|
324
290
|
end
|
325
|
-
|
326
|
-
|
327
291
|
end
|
328
|
-
|
329
|
-
|
330
292
|
end
|
331
|
-
|
332
293
|
end
|
Binary file
|
@@ -5,10 +5,7 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module CoordSys
|
10
|
-
|
11
|
-
|
12
9
|
# This module contains tools for accessing spatial reference
|
13
10
|
# databases. These are databases (either local or remote) from which
|
14
11
|
# you can look up coordinate system specifications, typically in
|
@@ -19,42 +16,32 @@ module RGeo
|
|
19
16
|
# spatialreference.org site.
|
20
17
|
|
21
18
|
module SRSDatabase
|
22
|
-
|
23
|
-
|
24
19
|
# Interface specification for spatial reference system databases.
|
25
20
|
# This module exists primarily for the sake of documentation.
|
26
21
|
# Database implementations need not actually include this module,
|
27
22
|
# but at least need to duck-type its methods.
|
28
23
|
|
29
24
|
module Interface
|
30
|
-
|
31
|
-
|
32
25
|
# Retrieve an Entry given an identifier. The identifier is usually
|
33
26
|
# a numeric spatial reference ID (SRID), but could be a string
|
34
27
|
# value for certain database types.
|
35
28
|
|
36
|
-
def get(
|
29
|
+
def get(_ident_)
|
37
30
|
nil
|
38
31
|
end
|
39
32
|
|
40
|
-
|
41
33
|
# Clears any cache utilized by this database.
|
42
34
|
|
43
35
|
def clear_cache
|
44
36
|
nil
|
45
37
|
end
|
46
|
-
|
47
|
-
|
48
38
|
end
|
49
39
|
|
50
|
-
|
51
40
|
# An entry in a spatial reference system database.
|
52
41
|
# Every entry has an identifier, but all the other attributes are
|
53
42
|
# optional and may or may not be present depending on the database.
|
54
43
|
|
55
44
|
class Entry
|
56
|
-
|
57
|
-
|
58
45
|
# Create an entry.
|
59
46
|
# You must provide an identifier, which may be numeric or a
|
60
47
|
# string. The data hash should contain any other attributes,
|
@@ -77,19 +64,19 @@ module RGeo
|
|
77
64
|
# If the authority code is not provided directly, it is taken
|
78
65
|
# from the coord_sys.
|
79
66
|
|
80
|
-
def initialize(ident_, data_={})
|
67
|
+
def initialize(ident_, data_ = {})
|
81
68
|
@identifier = ident_
|
82
69
|
@authority = data_[:authority]
|
83
70
|
@authority_code = data_[:authority_code]
|
84
71
|
@name = data_[:name]
|
85
72
|
@description = data_[:description]
|
86
73
|
@coord_sys = data_[:coord_sys]
|
87
|
-
if @coord_sys.
|
74
|
+
if @coord_sys.is_a?(::String)
|
88
75
|
@coord_sys = CS.create_from_wkt(@coord_sys)
|
89
76
|
end
|
90
77
|
@proj4 = data_[:proj4]
|
91
78
|
if Proj4.supported?
|
92
|
-
if @proj4.
|
79
|
+
if @proj4.is_a?(::String) || @proj4.is_a?(::Hash)
|
93
80
|
@proj4 = Proj4.create(@proj4)
|
94
81
|
end
|
95
82
|
else
|
@@ -102,7 +89,6 @@ module RGeo
|
|
102
89
|
end
|
103
90
|
end
|
104
91
|
|
105
|
-
|
106
92
|
# The database key or identifier.
|
107
93
|
attr_reader :identifier
|
108
94
|
|
@@ -123,13 +109,7 @@ module RGeo
|
|
123
109
|
|
124
110
|
# The Proj4 object.
|
125
111
|
attr_reader :proj4
|
126
|
-
|
127
|
-
|
128
112
|
end
|
129
|
-
|
130
|
-
|
131
113
|
end
|
132
|
-
|
133
114
|
end
|
134
|
-
|
135
115
|
end
|
@@ -5,20 +5,14 @@
|
|
5
5
|
# -----------------------------------------------------------------------------
|
6
6
|
|
7
7
|
module RGeo
|
8
|
-
|
9
8
|
module CoordSys
|
10
|
-
|
11
9
|
module SRSDatabase
|
12
|
-
|
13
|
-
|
14
10
|
# A spatial reference database implementation backed by coordinate
|
15
11
|
# system files installed as part of the proj4 library. For a given
|
16
12
|
# Proj4Data object, you specify a single file (e.g. the epsg data
|
17
13
|
# file), and you can retrieve records by ID number.
|
18
14
|
|
19
15
|
class Proj4Data
|
20
|
-
|
21
|
-
|
22
16
|
# Connect to one of the proj4 data files. You should provide the
|
23
17
|
# file name, optionally the installation directory if it is not
|
24
18
|
# in a typical location, and several additional options.
|
@@ -48,12 +42,12 @@ module RGeo
|
|
48
42
|
# entries. The authority code will be set to the identifier. If
|
49
43
|
# not set, then the authority fields of entries will be blank.
|
50
44
|
|
51
|
-
def initialize(filename_, opts_={})
|
45
|
+
def initialize(filename_, opts_ = {})
|
52
46
|
dir_ = nil
|
53
47
|
if opts_.include?(:dir)
|
54
48
|
dir_ = opts_[:dir]
|
55
49
|
else
|
56
|
-
[
|
50
|
+
["/usr/local/share/proj", "/usr/local/proj/share/proj", "/usr/local/proj4/share/proj", "/opt/local/share/proj", "/opt/proj/share/proj", "/opt/proj4/share/proj", "/opt/share/proj", "/usr/share/proj"].each do |d_|
|
57
51
|
if ::File.directory?(d_) && ::File.readable?(d_)
|
58
52
|
dir_ = d_
|
59
53
|
break
|
@@ -79,7 +73,6 @@ module RGeo
|
|
79
73
|
end
|
80
74
|
end
|
81
75
|
|
82
|
-
|
83
76
|
# Retrieve the Entry for the given ID number.
|
84
77
|
|
85
78
|
def get(ident_)
|
@@ -88,7 +81,7 @@ module RGeo
|
|
88
81
|
result_ = nil
|
89
82
|
if @populate_state == 0
|
90
83
|
data_ = _search_file(ident_)
|
91
|
-
result_ = Entry.new(ident_, :
|
84
|
+
result_ = Entry.new(ident_, authority: @authority, authority_code: @authority ? ident_ : nil, name: data_[1], proj4: data_[2]) if data_
|
92
85
|
@cache[ident_] = result_ if @cache
|
93
86
|
elsif @populate_state == 1
|
94
87
|
_search_file(nil)
|
@@ -98,7 +91,6 @@ module RGeo
|
|
98
91
|
result_
|
99
92
|
end
|
100
93
|
|
101
|
-
|
102
94
|
# Clear the cache if one exists.
|
103
95
|
|
104
96
|
def clear_cache
|
@@ -106,8 +98,7 @@ module RGeo
|
|
106
98
|
@populate_state = 1 if @populate_state == 2
|
107
99
|
end
|
108
100
|
|
109
|
-
|
110
|
-
def _search_file(ident_) # :nodoc:
|
101
|
+
def _search_file(ident_) # :nodoc:
|
111
102
|
::File.open(@path) do |file_|
|
112
103
|
cur_name_ = nil
|
113
104
|
cur_ident_ = nil
|
@@ -115,44 +106,35 @@ module RGeo
|
|
115
106
|
file_.each do |line_|
|
116
107
|
line_.strip!
|
117
108
|
if (comment_delim_ = line_.index('#'))
|
118
|
-
cur_name_ = line_[comment_delim_+1..-1].strip
|
119
|
-
line_ = line_[0..comment_delim_-1].strip
|
109
|
+
cur_name_ = line_[comment_delim_ + 1..-1].strip
|
110
|
+
line_ = line_[0..comment_delim_ - 1].strip
|
120
111
|
end
|
121
112
|
unless cur_ident_
|
122
113
|
if line_ =~ /^<(\w+)>(.*)/
|
123
|
-
cur_ident_ =
|
114
|
+
cur_ident_ = Regexp.last_match(1)
|
124
115
|
cur_text_ = []
|
125
|
-
line_ =
|
116
|
+
line_ = Regexp.last_match(2).strip
|
126
117
|
end
|
127
118
|
end
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
if cur_ident_ == ident_
|
136
|
-
return [ident_, cur_name_, cur_text_]
|
137
|
-
end
|
138
|
-
cur_ident_ = nil
|
139
|
-
cur_name_ = nil
|
140
|
-
cur_text_ = nil
|
141
|
-
else
|
142
|
-
cur_text_ << line_
|
119
|
+
next unless cur_ident_
|
120
|
+
if line_[-2..-1] == "<>"
|
121
|
+
cur_text_ << line_[0..-3].strip
|
122
|
+
cur_text_ = cur_text_.join(" ")
|
123
|
+
if ident_.nil?
|
124
|
+
@cache[ident_] = Entry.new(ident_, authority: @authority, authority_code: @authority ? id_ : nil, name: cur_name_, proj4: cur_text_)
|
143
125
|
end
|
126
|
+
return [ident_, cur_name_, cur_text_] if cur_ident_ == ident_
|
127
|
+
cur_ident_ = nil
|
128
|
+
cur_name_ = nil
|
129
|
+
cur_text_ = nil
|
130
|
+
else
|
131
|
+
cur_text_ << line_
|
144
132
|
end
|
145
133
|
end
|
146
134
|
end
|
147
135
|
nil
|
148
136
|
end
|
149
|
-
|
150
|
-
|
151
137
|
end
|
152
|
-
|
153
|
-
|
154
138
|
end
|
155
|
-
|
156
139
|
end
|
157
|
-
|
158
140
|
end
|