rgeo 2.3.1 → 3.0.1
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.
- checksums.yaml +4 -4
- data/.yardopts +6 -0
- data/README.md +23 -14
- data/ext/geos_c_impl/analysis.c +30 -25
- data/ext/geos_c_impl/analysis.h +8 -7
- data/ext/geos_c_impl/coordinates.c +27 -21
- data/ext/geos_c_impl/coordinates.h +5 -2
- data/ext/geos_c_impl/errors.c +19 -10
- data/ext/geos_c_impl/errors.h +11 -4
- data/ext/geos_c_impl/extconf.rb +42 -28
- data/ext/geos_c_impl/factory.c +540 -451
- data/ext/geos_c_impl/factory.h +105 -95
- data/ext/geos_c_impl/geometry.c +593 -387
- data/ext/geos_c_impl/geometry.h +10 -5
- data/ext/geos_c_impl/geometry_collection.c +306 -339
- data/ext/geos_c_impl/geometry_collection.h +6 -20
- data/ext/geos_c_impl/globals.c +169 -0
- data/ext/geos_c_impl/globals.h +46 -0
- data/ext/geos_c_impl/line_string.c +271 -231
- data/ext/geos_c_impl/line_string.h +5 -8
- data/ext/geos_c_impl/main.c +16 -16
- data/ext/geos_c_impl/point.c +65 -67
- data/ext/geos_c_impl/point.h +4 -7
- data/ext/geos_c_impl/polygon.c +137 -135
- data/ext/geos_c_impl/polygon.h +11 -11
- data/ext/geos_c_impl/preface.h +16 -10
- data/ext/geos_c_impl/ruby_more.c +67 -0
- data/ext/geos_c_impl/ruby_more.h +25 -0
- data/lib/rgeo/cartesian/analysis.rb +5 -3
- data/lib/rgeo/cartesian/bounding_box.rb +74 -79
- data/lib/rgeo/cartesian/calculations.rb +64 -33
- data/lib/rgeo/cartesian/factory.rb +57 -102
- data/lib/rgeo/cartesian/feature_classes.rb +68 -46
- data/lib/rgeo/cartesian/feature_methods.rb +67 -25
- data/lib/rgeo/cartesian/interface.rb +6 -41
- data/lib/rgeo/cartesian/planar_graph.rb +373 -0
- data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
- data/lib/rgeo/cartesian/valid_op.rb +69 -0
- data/lib/rgeo/cartesian.rb +3 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +303 -99
- data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
- data/lib/rgeo/coord_sys.rb +1 -20
- data/lib/rgeo/error.rb +15 -0
- data/lib/rgeo/feature/curve.rb +0 -11
- data/lib/rgeo/feature/factory.rb +26 -36
- data/lib/rgeo/feature/factory_generator.rb +6 -14
- data/lib/rgeo/feature/geometry.rb +146 -66
- data/lib/rgeo/feature/geometry_collection.rb +16 -9
- data/lib/rgeo/feature/line_string.rb +4 -5
- data/lib/rgeo/feature/linear_ring.rb +0 -1
- data/lib/rgeo/feature/multi_curve.rb +0 -6
- data/lib/rgeo/feature/multi_surface.rb +3 -4
- data/lib/rgeo/feature/point.rb +4 -5
- data/lib/rgeo/feature/polygon.rb +1 -2
- data/lib/rgeo/feature/surface.rb +3 -4
- data/lib/rgeo/feature/types.rb +69 -85
- data/lib/rgeo/geographic/factory.rb +98 -125
- data/lib/rgeo/geographic/interface.rb +69 -166
- data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
- data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
- data/lib/rgeo/geographic/projected_window.rb +36 -22
- data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
- data/lib/rgeo/geographic/simple_mercator_projector.rb +26 -25
- data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
- data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
- data/lib/rgeo/geographic/spherical_math.rb +17 -20
- data/lib/rgeo/geographic.rb +1 -1
- data/lib/rgeo/geos/capi_factory.rb +87 -158
- data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
- data/lib/rgeo/geos/ffi_factory.rb +105 -173
- data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
- data/lib/rgeo/geos/ffi_feature_methods.rb +105 -127
- data/lib/rgeo/geos/interface.rb +20 -59
- data/lib/rgeo/geos/utils.rb +5 -5
- data/lib/rgeo/geos/zm_factory.rb +53 -95
- data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
- data/lib/rgeo/geos.rb +8 -8
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
- data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
- data/lib/rgeo/impl_helper/utils.rb +21 -0
- data/lib/rgeo/impl_helper/valid_op.rb +350 -0
- data/lib/rgeo/impl_helper/validity_check.rb +139 -0
- data/lib/rgeo/impl_helper.rb +1 -0
- data/lib/rgeo/version.rb +1 -1
- data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
- data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
- data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
- data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
- data/lib/rgeo.rb +1 -3
- metadata +50 -13
- data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
data/lib/rgeo/feature/surface.rb
CHANGED
@@ -34,7 +34,6 @@ module RGeo
|
|
34
34
|
# class method (or === operator) defined in the Type module.
|
35
35
|
#
|
36
36
|
# Some implementations may support higher dimensional points.
|
37
|
-
|
38
37
|
module Surface
|
39
38
|
include Geometry
|
40
39
|
extend Type
|
@@ -49,7 +48,7 @@ module RGeo
|
|
49
48
|
# Returns a floating-point scalar value.
|
50
49
|
|
51
50
|
def area
|
52
|
-
raise Error::UnsupportedOperation, "Method
|
51
|
+
raise Error::UnsupportedOperation, "Method #{self.class.name}#area not defined."
|
53
52
|
end
|
54
53
|
|
55
54
|
# === SFS 1.1 Description
|
@@ -62,7 +61,7 @@ module RGeo
|
|
62
61
|
# Returns an object that supports the Point interface.
|
63
62
|
|
64
63
|
def centroid
|
65
|
-
raise Error::UnsupportedOperation, "Method
|
64
|
+
raise Error::UnsupportedOperation, "Method #{self.class.name}#centroid not defined."
|
66
65
|
end
|
67
66
|
|
68
67
|
# === SFS 1.1 Description
|
@@ -74,7 +73,7 @@ module RGeo
|
|
74
73
|
# Returns an object that supports the Point interface.
|
75
74
|
|
76
75
|
def point_on_surface
|
77
|
-
raise Error::UnsupportedOperation, "Method
|
76
|
+
raise Error::UnsupportedOperation, "Method #{self.class.name}#point_on_surface not defined."
|
78
77
|
end
|
79
78
|
end
|
80
79
|
end
|
data/lib/rgeo/feature/types.rb
CHANGED
@@ -11,7 +11,6 @@ module RGeo
|
|
11
11
|
# All geometry implementations MUST include this submodule.
|
12
12
|
# This serves as a marker that may be used to test an object for
|
13
13
|
# feature-ness.
|
14
|
-
|
15
14
|
module Instance
|
16
15
|
end
|
17
16
|
|
@@ -49,7 +48,6 @@ module RGeo
|
|
49
48
|
# a particular object is a feature type:
|
50
49
|
#
|
51
50
|
# RGeo::Feature::Type === object.geometry_type # true
|
52
|
-
|
53
51
|
module Type
|
54
52
|
# Returns true if the given object is this type or a subtype
|
55
53
|
# thereof, or if it is a feature object whose geometry_type is
|
@@ -192,92 +190,78 @@ module RGeo
|
|
192
190
|
# Types are the same
|
193
191
|
if nfactory == factory
|
194
192
|
force_new ? obj.dup : obj
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
nfactory.multi_line_string(obj.map { |g| cast(g, nfactory, opts) })
|
226
|
-
elsif type == MultiPolygon
|
227
|
-
nfactory.multi_polygon(obj.map { |g| cast(g, nfactory, opts) })
|
228
|
-
elsif type == GeometryCollection
|
229
|
-
nfactory.collection(obj.map { |g| cast(g, nfactory, opts) })
|
230
|
-
end
|
193
|
+
elsif type == Point
|
194
|
+
z = factory.property(:has_z_coordinate) ? obj.z : nil
|
195
|
+
coords = if project && (cs = factory.coord_sys) && (ncs = nfactory.coord_sys)
|
196
|
+
cs.transform_coords(ncs, obj.x, obj.y, z)
|
197
|
+
else
|
198
|
+
[obj.x, obj.y]
|
199
|
+
end
|
200
|
+
coords << (z || 0.0) if nfactory.property(:has_z_coordinate) && coords.size < 3
|
201
|
+
m = factory.property(:has_m_coordinate) ? obj.m : nil
|
202
|
+
coords << (m || 0.0) if nfactory.property(:has_m_coordinate)
|
203
|
+
nfactory.point(*coords)
|
204
|
+
elsif type == Line
|
205
|
+
nfactory.line(cast(obj.start_point, nfactory, opts), cast(obj.end_point, nfactory, opts))
|
206
|
+
elsif type == LinearRing
|
207
|
+
nfactory.linear_ring(obj.points.map { |p| cast(p, nfactory, opts) })
|
208
|
+
elsif type == LineString
|
209
|
+
nfactory.line_string(obj.points.map { |p| cast(p, nfactory, opts) })
|
210
|
+
elsif type == Polygon
|
211
|
+
nfactory.polygon(
|
212
|
+
cast(obj.exterior_ring, nfactory, opts),
|
213
|
+
obj.interior_rings.map { |r| cast(r, nfactory, opts) }
|
214
|
+
)
|
215
|
+
elsif type == MultiPoint
|
216
|
+
nfactory.multi_point(obj.map { |g| cast(g, nfactory, opts) })
|
217
|
+
elsif type == MultiLineString
|
218
|
+
nfactory.multi_line_string(obj.map { |g| cast(g, nfactory, opts) })
|
219
|
+
elsif type == MultiPolygon
|
220
|
+
nfactory.multi_polygon(obj.map { |g| cast(g, nfactory, opts) })
|
221
|
+
elsif type == GeometryCollection
|
222
|
+
nfactory.collection(obj.map { |g| cast(g, nfactory, opts) })
|
231
223
|
end
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
elsif
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
nfactory.multi_polygon([cast(obj, nfactory, opts)])
|
269
|
-
elsif type == GeometryCollection
|
270
|
-
nfactory.multi_polygon(obj.map { |p| cast(p, nfactory, opts) })
|
271
|
-
end
|
272
|
-
elsif ntype == GeometryCollection
|
273
|
-
if type == MultiPoint || type == MultiLineString || type == MultiPolygon
|
274
|
-
nfactory.collection(obj.map { |p| cast(p, nfactory, opts) })
|
275
|
-
else
|
276
|
-
nfactory.collection([cast(obj, nfactory, opts)])
|
277
|
-
end
|
224
|
+
# Types are different
|
225
|
+
elsif ntype == Point && [MultiPoint, GeometryCollection].include?(type) ||
|
226
|
+
[Line, LineString, LinearRing].include?(ntype) && [MultiLineString, GeometryCollection].include?(type) ||
|
227
|
+
ntype == Polygon && [MultiPolygon, GeometryCollection].include?(type)
|
228
|
+
cast(obj.geometry_n(0), nfactory, ntype, opts) if obj.num_geometries == 1
|
229
|
+
elsif ntype == Point
|
230
|
+
raise(Error::InvalidGeometry, "Cannot cast to Point")
|
231
|
+
elsif ntype == Line
|
232
|
+
if type == LineString && obj.num_points == 2
|
233
|
+
nfactory.line(cast(obj.point_n(0), nfactory, opts), cast(obj.point_n(1), nfactory, opts))
|
234
|
+
end
|
235
|
+
elsif ntype == LinearRing
|
236
|
+
nfactory.linear_ring(obj.points.map { |p| cast(p, nfactory, opts) }) if type == LineString
|
237
|
+
elsif ntype == LineString
|
238
|
+
nfactory.line_string(obj.points.map { |p| cast(p, nfactory, opts) }) if [Line, LinearRing].include?(type)
|
239
|
+
elsif ntype == MultiPoint
|
240
|
+
if type == Point
|
241
|
+
nfactory.multi_point([cast(obj, nfactory, opts)])
|
242
|
+
elsif type == GeometryCollection
|
243
|
+
nfactory.multi_point(obj.map { |p| cast(p, nfactory, opts) })
|
244
|
+
end
|
245
|
+
elsif ntype == MultiLineString
|
246
|
+
if [Line, LinearRing, LineString].include?(type)
|
247
|
+
nfactory.multi_line_string([cast(obj, nfactory, opts)])
|
248
|
+
elsif type == GeometryCollection
|
249
|
+
nfactory.multi_line_string(obj.map { |p| cast(p, nfactory, opts) })
|
250
|
+
end
|
251
|
+
elsif ntype == MultiPolygon
|
252
|
+
if type == Polygon
|
253
|
+
nfactory.multi_polygon([cast(obj, nfactory, opts)])
|
254
|
+
elsif type == GeometryCollection
|
255
|
+
nfactory.multi_polygon(obj.map { |p| cast(p, nfactory, opts) })
|
256
|
+
end
|
257
|
+
elsif ntype == GeometryCollection
|
258
|
+
if [MultiPoint, MultiLineString, MultiPolygon].include?(type)
|
259
|
+
nfactory.collection(obj.map { |p| cast(p, nfactory, opts) })
|
278
260
|
else
|
279
|
-
|
261
|
+
nfactory.collection([cast(obj, nfactory, opts)])
|
280
262
|
end
|
263
|
+
else
|
264
|
+
raise(RGeo::Error::InvalidGeometry, "Undefined type cast from #{type.name} to #{ntype.name}")
|
281
265
|
end
|
282
266
|
end
|
283
267
|
end
|
@@ -11,13 +11,20 @@ module RGeo
|
|
11
11
|
# This class implements the various factories for geography features.
|
12
12
|
# See methods of the RGeo::Geographic module for the API for creating
|
13
13
|
# geography factories.
|
14
|
-
|
15
14
|
class Factory
|
16
15
|
include Feature::Factory::Instance
|
17
16
|
include ImplHelper::Utils
|
18
17
|
|
19
18
|
attr_writer :projector
|
20
19
|
|
20
|
+
attr_reader :coordinate_dimension, :spatial_dimension
|
21
|
+
|
22
|
+
# Returns the srid reported by this factory.
|
23
|
+
attr_reader :srid
|
24
|
+
|
25
|
+
# See RGeo::Feature::Factory#coord_sys
|
26
|
+
attr_reader :coord_sys
|
27
|
+
|
21
28
|
def initialize(impl_prefix, opts = {}) # :nodoc:
|
22
29
|
@impl_prefix = impl_prefix
|
23
30
|
@point_class = Geographic.const_get("#{impl_prefix}PointImpl")
|
@@ -31,67 +38,69 @@ module RGeo
|
|
31
38
|
@multi_polygon_class = Geographic.const_get("#{impl_prefix}MultiPolygonImpl")
|
32
39
|
@support_z = opts[:has_z_coordinate] ? true : false
|
33
40
|
@support_m = opts[:has_m_coordinate] ? true : false
|
34
|
-
@
|
35
|
-
@
|
36
|
-
if @
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@coord_sys =
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
@lenient_assertions = opts[:uses_lenient_assertions] ? true : false
|
41
|
+
@coordinate_dimension = 2
|
42
|
+
@coordinate_dimension += 1 if @support_z
|
43
|
+
@coordinate_dimension += 1 if @support_m
|
44
|
+
@spatial_dimension = @support_z ? 3 : 2
|
45
|
+
|
46
|
+
srid = opts.fetch(:srid, 4326).to_i
|
47
|
+
coord_sys_info = ImplHelper::Utils.setup_coord_sys(srid, opts[:coord_sys], opts[:coord_sys_class])
|
48
|
+
@coord_sys = coord_sys_info[:coord_sys]
|
49
|
+
@srid = coord_sys_info[:srid]
|
50
|
+
|
46
51
|
@buffer_resolution = opts[:buffer_resolution].to_i
|
47
52
|
@buffer_resolution = 1 if @buffer_resolution < 1
|
48
53
|
|
49
54
|
wkt_generator = opts[:wkt_generator]
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
@wkt_generator =
|
56
|
+
case wkt_generator
|
57
|
+
when Hash
|
58
|
+
WKRep::WKTGenerator.new(wkt_generator)
|
59
|
+
else
|
60
|
+
WKRep::WKTGenerator.new(convert_case: :upper)
|
61
|
+
end
|
56
62
|
wkb_generator = opts[:wkb_generator]
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
@wkb_generator =
|
64
|
+
case wkb_generator
|
65
|
+
when Hash
|
66
|
+
WKRep::WKBGenerator.new(wkb_generator)
|
67
|
+
else
|
68
|
+
WKRep::WKBGenerator.new
|
69
|
+
end
|
63
70
|
wkt_parser = opts[:wkt_parser]
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
71
|
+
@wkt_parser =
|
72
|
+
case wkt_parser
|
73
|
+
when Hash
|
74
|
+
WKRep::WKTParser.new(self, wkt_parser)
|
75
|
+
else
|
76
|
+
WKRep::WKTParser.new(self)
|
77
|
+
end
|
70
78
|
wkb_parser = opts[:wkb_parser]
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
79
|
+
@wkb_parser =
|
80
|
+
case wkb_parser
|
81
|
+
when Hash
|
82
|
+
WKRep::WKBParser.new(self, wkb_parser)
|
83
|
+
else
|
84
|
+
WKRep::WKBParser.new(self)
|
85
|
+
end
|
77
86
|
@projector = nil
|
78
87
|
end
|
79
88
|
|
80
89
|
# Equivalence test.
|
81
90
|
|
82
|
-
def eql?(
|
83
|
-
|
84
|
-
@impl_prefix ==
|
85
|
-
@support_z ==
|
86
|
-
@support_m ==
|
87
|
-
@
|
91
|
+
def eql?(other)
|
92
|
+
other.is_a?(Geographic::Factory) &&
|
93
|
+
@impl_prefix == other.instance_variable_get(:@impl_prefix) &&
|
94
|
+
@support_z == other.instance_variable_get(:@support_z) &&
|
95
|
+
@support_m == other.instance_variable_get(:@support_m) &&
|
96
|
+
@coord_sys == other.instance_variable_get(:@coord_sys)
|
88
97
|
end
|
89
98
|
alias == eql?
|
90
99
|
|
91
100
|
# Standard hash code
|
92
101
|
|
93
102
|
def hash
|
94
|
-
@hash ||= [@impl_prefix, @support_z, @support_m, @
|
103
|
+
@hash ||= [@impl_prefix, @support_z, @support_m, @coord_sys].hash
|
95
104
|
end
|
96
105
|
|
97
106
|
# Marshal support
|
@@ -106,10 +115,8 @@ module RGeo
|
|
106
115
|
"wkbg" => @wkb_generator.properties,
|
107
116
|
"wktp" => @wkt_parser.properties,
|
108
117
|
"wkbp" => @wkb_parser.properties,
|
109
|
-
"lena" => @lenient_assertions,
|
110
118
|
"bufr" => @buffer_resolution
|
111
119
|
}
|
112
|
-
hash_["proj4"] = @proj4.marshal_dump if @proj4
|
113
120
|
hash_["cs"] = @coord_sys.to_wkt if @coord_sys
|
114
121
|
if @projector
|
115
122
|
hash_["prjc"] = @projector.class.name.sub(/.*::/, "")
|
@@ -119,18 +126,11 @@ module RGeo
|
|
119
126
|
end
|
120
127
|
|
121
128
|
def marshal_load(data_) # :nodoc:
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
128
|
-
if (coord_sys_data = data_["cs"])
|
129
|
-
coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data)
|
130
|
-
else
|
131
|
-
coord_sys = nil
|
132
|
-
end
|
133
|
-
initialize(data_["pref"],
|
129
|
+
cs_class = CoordSys::CONFIG.default_coord_sys_class
|
130
|
+
coord_sys = data_["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
|
131
|
+
|
132
|
+
initialize(
|
133
|
+
data_["pref"],
|
134
134
|
has_z_coordinate: data_["hasz"],
|
135
135
|
has_m_coordinate: data_["hasm"],
|
136
136
|
srid: data_["srid"],
|
@@ -138,19 +138,21 @@ module RGeo
|
|
138
138
|
wkb_generator: symbolize_hash(data_["wkbg"]),
|
139
139
|
wkt_parser: symbolize_hash(data_["wktp"]),
|
140
140
|
wkb_parser: symbolize_hash(data_["wkbp"]),
|
141
|
-
uses_lenient_assertions: data_["lena"],
|
142
141
|
buffer_resolution: data_["bufr"],
|
143
|
-
proj4: proj4,
|
144
142
|
coord_sys: coord_sys
|
145
143
|
)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
144
|
+
proj_klass = data_["prjc"]
|
145
|
+
proj_factory = data_["prjf"]
|
146
|
+
|
147
|
+
return unless proj_klass && proj_factory
|
148
|
+
|
149
|
+
klass_ = RGeo::Geographic.const_get(proj_klass)
|
150
|
+
|
151
|
+
return unless klass_
|
152
|
+
|
153
|
+
projector = klass_.allocate
|
154
|
+
projector.set_factories(self, proj_factory)
|
155
|
+
@projector = projector
|
154
156
|
end
|
155
157
|
|
156
158
|
# Psych support
|
@@ -164,36 +166,21 @@ module RGeo
|
|
164
166
|
coder["wkb_generator"] = @wkb_generator.properties
|
165
167
|
coder["wkt_parser"] = @wkt_parser.properties
|
166
168
|
coder["wkb_parser"] = @wkb_parser.properties
|
167
|
-
coder["lenient_assertions"] = @lenient_assertions
|
168
169
|
coder["buffer_resolution"] = @buffer_resolution
|
169
|
-
if @proj4
|
170
|
-
str = @proj4.original_str || @proj4.canonical_str
|
171
|
-
coder["proj4"] = @proj4.radians? ? { "proj4" => str, "radians" => true } : str
|
172
|
-
end
|
173
170
|
coder["coord_sys"] = @coord_sys.to_wkt if @coord_sys
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
171
|
+
|
172
|
+
return unless @projector
|
173
|
+
|
174
|
+
coder["projectorclass"] = @projector.class.name.sub(/.*::/, "")
|
175
|
+
coder["projection_factory"] = @projector.projection_factory
|
178
176
|
end
|
179
177
|
|
180
178
|
def init_with(coder) # :nodoc:
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
proj4 = CoordSys::Proj4.create(proj4_data.to_s)
|
187
|
-
end
|
188
|
-
else
|
189
|
-
proj4 = nil
|
190
|
-
end
|
191
|
-
if (coord_sys_data = coder["cs"])
|
192
|
-
coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data.to_s)
|
193
|
-
else
|
194
|
-
coord_sys = nil
|
195
|
-
end
|
196
|
-
initialize(coder["impl_prefix"],
|
179
|
+
cs_class = CoordSys::CONFIG.default_coord_sys_class
|
180
|
+
coord_sys = coder["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
|
181
|
+
|
182
|
+
initialize(
|
183
|
+
coder["impl_prefix"],
|
197
184
|
has_z_coordinate: coder["has_z_coordinate"],
|
198
185
|
has_m_coordinate: coder["has_m_coordinate"],
|
199
186
|
srid: coder["srid"],
|
@@ -201,24 +188,22 @@ module RGeo
|
|
201
188
|
wkb_generator: symbolize_hash(coder["wkb_generator"]),
|
202
189
|
wkt_parser: symbolize_hash(coder["wkt_parser"]),
|
203
190
|
wkb_parser: symbolize_hash(coder["wkb_parser"]),
|
204
|
-
uses_lenient_assertions: coder["lenient_assertions"],
|
205
191
|
buffer_resolution: coder["buffer_resolution"],
|
206
|
-
proj4: proj4,
|
207
192
|
coord_sys: coord_sys
|
208
193
|
)
|
209
|
-
|
210
|
-
|
211
|
-
if klass_
|
212
|
-
projector = klass_.allocate
|
213
|
-
projector.set_factories(self, proj_factory)
|
214
|
-
@projector = projector
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
194
|
+
proj_klass = coder["projectorclass"]
|
195
|
+
proj_factory = coder["projection_factory"]
|
218
196
|
|
219
|
-
|
197
|
+
return unless proj_klass && proj_factory
|
220
198
|
|
221
|
-
|
199
|
+
klass_ = RGeo::Geographic.const_get(proj_klass)
|
200
|
+
|
201
|
+
return unless klass_
|
202
|
+
|
203
|
+
projector = klass_.allocate
|
204
|
+
projector.set_factories(self, proj_factory)
|
205
|
+
@projector = projector
|
206
|
+
end
|
222
207
|
|
223
208
|
# Returns true if this factory supports a projection.
|
224
209
|
|
@@ -241,9 +226,7 @@ module RGeo
|
|
241
226
|
|
242
227
|
def project(geometry)
|
243
228
|
return unless @projector && geometry
|
244
|
-
unless geometry.factory == self
|
245
|
-
raise Error::InvalidGeometry, "Wrong geometry type"
|
246
|
-
end
|
229
|
+
raise Error::InvalidGeometry, "Wrong geometry type" unless geometry.factory == self
|
247
230
|
@projector.project(geometry)
|
248
231
|
end
|
249
232
|
|
@@ -254,9 +237,11 @@ module RGeo
|
|
254
237
|
|
255
238
|
def unproject(geometry)
|
256
239
|
return unless geometry
|
240
|
+
|
257
241
|
unless @projector && @projector.projection_factory == geometry.factory
|
258
242
|
raise Error::InvalidGeometry, "You can unproject only features that are in the projected coordinate space."
|
259
243
|
end
|
244
|
+
|
260
245
|
@projector.unproject(geometry)
|
261
246
|
end
|
262
247
|
|
@@ -277,12 +262,10 @@ module RGeo
|
|
277
262
|
# projection limits are not known.
|
278
263
|
|
279
264
|
def projection_limits_window
|
280
|
-
if @
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
@projection_limits_window
|
285
|
-
end
|
265
|
+
return @projection_limits_window if defined?(@projection_limits_window)
|
266
|
+
return unless @projector
|
267
|
+
|
268
|
+
@projection_limits_window = @projector.limits_window
|
286
269
|
end
|
287
270
|
|
288
271
|
# See RGeo::Feature::Factory#property
|
@@ -293,8 +276,6 @@ module RGeo
|
|
293
276
|
@support_z
|
294
277
|
when :has_m_coordinate
|
295
278
|
@support_m
|
296
|
-
when :uses_lenient_assertions
|
297
|
-
@lenient_assertions
|
298
279
|
when :buffer_resolution
|
299
280
|
@buffer_resolution
|
300
281
|
when :is_geographic
|
@@ -368,14 +349,6 @@ module RGeo
|
|
368
349
|
@multi_polygon_class.new(self, elems)
|
369
350
|
end
|
370
351
|
|
371
|
-
# See RGeo::Feature::Factory#proj4
|
372
|
-
|
373
|
-
attr_reader :proj4
|
374
|
-
|
375
|
-
# See RGeo::Feature::Factory#coord_sys
|
376
|
-
|
377
|
-
attr_reader :coord_sys
|
378
|
-
|
379
352
|
def generate_wkt(obj)
|
380
353
|
@wkt_generator.generate(obj)
|
381
354
|
end
|