rgeo 1.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +144 -0
- data/ext/geos_c_impl/analysis.c +78 -0
- data/ext/geos_c_impl/analysis.h +42 -0
- data/ext/geos_c_impl/errors.c +35 -0
- data/ext/geos_c_impl/errors.h +22 -0
- data/ext/geos_c_impl/extconf.rb +6 -3
- data/ext/geos_c_impl/factory.c +14 -5
- data/ext/geos_c_impl/factory.h +5 -1
- data/ext/geos_c_impl/geometry.c +20 -2
- data/ext/geos_c_impl/geometry_collection.c +0 -17
- data/ext/geos_c_impl/main.c +5 -2
- data/ext/geos_c_impl/preface.h +3 -0
- data/lib/rgeo.rb +11 -13
- data/lib/rgeo/cartesian.rb +13 -23
- data/lib/rgeo/cartesian/analysis.rb +44 -20
- data/lib/rgeo/cartesian/bounding_box.rb +83 -79
- data/lib/rgeo/cartesian/calculations.rb +40 -38
- data/lib/rgeo/cartesian/factory.rb +134 -169
- data/lib/rgeo/cartesian/feature_classes.rb +2 -18
- data/lib/rgeo/cartesian/feature_methods.rb +37 -39
- data/lib/rgeo/cartesian/interface.rb +11 -9
- data/lib/rgeo/coord_sys.rb +9 -8
- data/lib/rgeo/coord_sys/cs/entities.rb +345 -303
- data/lib/rgeo/coord_sys/cs/factories.rb +30 -28
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +128 -126
- data/lib/rgeo/coord_sys/srs_database/{interface.rb → entry.rb} +26 -32
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +19 -17
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +21 -19
- data/lib/rgeo/error.rb +7 -1
- data/lib/rgeo/feature.rb +40 -51
- data/lib/rgeo/feature/curve.rb +2 -0
- data/lib/rgeo/feature/factory.rb +15 -13
- data/lib/rgeo/feature/factory_generator.rb +7 -5
- data/lib/rgeo/feature/geometry.rb +31 -29
- data/lib/rgeo/feature/geometry_collection.rb +6 -4
- data/lib/rgeo/feature/line.rb +2 -0
- data/lib/rgeo/feature/line_string.rb +3 -1
- data/lib/rgeo/feature/linear_ring.rb +12 -0
- data/lib/rgeo/feature/multi_curve.rb +2 -0
- data/lib/rgeo/feature/multi_line_string.rb +2 -0
- data/lib/rgeo/feature/multi_point.rb +2 -0
- data/lib/rgeo/feature/multi_polygon.rb +2 -0
- data/lib/rgeo/feature/multi_surface.rb +2 -0
- data/lib/rgeo/feature/point.rb +2 -0
- data/lib/rgeo/feature/polygon.rb +3 -1
- data/lib/rgeo/feature/surface.rb +2 -0
- data/lib/rgeo/feature/types.rb +107 -103
- data/lib/rgeo/geographic.rb +27 -37
- data/lib/rgeo/geographic/factory.rb +154 -199
- data/lib/rgeo/geographic/interface.rb +141 -137
- data/lib/rgeo/geographic/proj4_projector.rb +28 -23
- data/lib/rgeo/geographic/projected_feature_classes.rb +2 -18
- data/lib/rgeo/geographic/projected_feature_methods.rb +64 -54
- data/lib/rgeo/geographic/projected_window.rb +4 -2
- data/lib/rgeo/geographic/simple_mercator_projector.rb +41 -39
- data/lib/rgeo/geographic/spherical_feature_classes.rb +3 -18
- data/lib/rgeo/geographic/spherical_feature_methods.rb +90 -67
- data/lib/rgeo/geographic/spherical_math.rb +81 -87
- data/lib/rgeo/geos.rb +40 -53
- data/lib/rgeo/geos/capi_factory.rb +111 -136
- data/lib/rgeo/geos/capi_feature_classes.rb +22 -36
- data/lib/rgeo/geos/ffi_factory.rb +276 -297
- data/lib/rgeo/geos/ffi_feature_classes.rb +2 -20
- data/lib/rgeo/geos/ffi_feature_methods.rb +177 -169
- data/lib/rgeo/geos/interface.rb +25 -23
- data/lib/rgeo/geos/utils.rb +47 -39
- data/lib/rgeo/geos/zm_factory.rb +171 -185
- data/lib/rgeo/geos/zm_feature_classes.rb +2 -20
- data/lib/rgeo/geos/zm_feature_methods.rb +76 -72
- data/lib/rgeo/impl_helper.rb +8 -18
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +84 -75
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +21 -23
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +95 -48
- data/lib/rgeo/impl_helper/basic_point_methods.rb +29 -25
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +68 -27
- data/lib/rgeo/impl_helper/math.rb +2 -0
- data/lib/rgeo/impl_helper/utils.rb +9 -15
- data/lib/rgeo/version.rb +3 -1
- data/lib/rgeo/wkrep.rb +24 -34
- data/lib/rgeo/wkrep/wkb_generator.rb +87 -84
- data/lib/rgeo/wkrep/wkb_parser.rb +93 -93
- data/lib/rgeo/wkrep/wkt_generator.rb +67 -63
- data/lib/rgeo/wkrep/wkt_parser.rb +172 -168
- metadata +30 -36
- data/lib/rgeo/feature/mixins.rb +0 -143
data/lib/rgeo/geos/interface.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# GEOS toplevel interface
|
@@ -29,30 +31,30 @@ module RGeo
|
|
29
31
|
# Returns true if the given feature is a CAPI GEOS feature, or if
|
30
32
|
# the given factory is a CAPI GEOS factory.
|
31
33
|
|
32
|
-
def is_capi_geos?(
|
34
|
+
def is_capi_geos?(object)
|
33
35
|
CAPI_SUPPORTED &&
|
34
|
-
(CAPIFactory ===
|
35
|
-
ZMFactory ===
|
36
|
-
ZMGeometryMethods ===
|
36
|
+
(CAPIFactory === object || CAPIGeometryMethods === object ||
|
37
|
+
ZMFactory === object && CAPIFactory === object.z_factory ||
|
38
|
+
ZMGeometryMethods === object && CAPIGeometryMethods === object.z_geometry)
|
37
39
|
end
|
38
40
|
|
39
41
|
# Returns true if the given feature is an FFI GEOS feature, or if
|
40
42
|
# the given factory is an FFI GEOS factory.
|
41
43
|
|
42
|
-
def is_ffi_geos?(
|
44
|
+
def is_ffi_geos?(object)
|
43
45
|
FFI_SUPPORTED &&
|
44
|
-
(FFIFactory ===
|
45
|
-
ZMFactory ===
|
46
|
-
ZMGeometryMethods ===
|
46
|
+
(FFIFactory === object || FFIGeometryMethods === object ||
|
47
|
+
ZMFactory === object && FFIFactory === object.z_factory ||
|
48
|
+
ZMGeometryMethods === object && FFIGeometryMethods === object.z_geometry)
|
47
49
|
end
|
48
50
|
|
49
51
|
# Returns true if the given feature is a GEOS feature, or if the given
|
50
52
|
# factory is a GEOS factory. Does not distinguish between CAPI and FFI.
|
51
53
|
|
52
|
-
def is_geos?(
|
53
|
-
CAPI_SUPPORTED && (CAPIFactory ===
|
54
|
-
FFI_SUPPORTED && (FFIFactory ===
|
55
|
-
ZMFactory ===
|
54
|
+
def is_geos?(object)
|
55
|
+
CAPI_SUPPORTED && (CAPIFactory === object || CAPIGeometryMethods === object) ||
|
56
|
+
FFI_SUPPORTED && (FFIFactory === object || FFIGeometryMethods === object) ||
|
57
|
+
ZMFactory === object || ZMGeometryMethods === object
|
56
58
|
end
|
57
59
|
|
58
60
|
# Returns the GEOS library version as a string of the format "x.y.z".
|
@@ -126,8 +128,8 @@ module RGeo
|
|
126
128
|
# CoordSys::CS::CoordinateSystem, or as a string in WKT format.
|
127
129
|
# Optional.
|
128
130
|
# [<tt>:srs_database</tt>]
|
129
|
-
# Optional. If provided, the
|
130
|
-
#
|
131
|
+
# Optional. If provided, the object should respond to #get and
|
132
|
+
# #clear_cache. If both this and an SRID are
|
131
133
|
# provided, they are used to look up the proj4 and coord_sys
|
132
134
|
# objects from a spatial reference system database.
|
133
135
|
# [<tt>:has_z_coordinate</tt>]
|
@@ -173,15 +175,15 @@ module RGeo
|
|
173
175
|
# never automatically generates a prepared geometry (unless you
|
174
176
|
# generate one explicitly using the <tt>prepare!</tt> method).
|
175
177
|
|
176
|
-
def factory(
|
178
|
+
def factory(opts = {})
|
177
179
|
if supported?
|
178
|
-
|
179
|
-
if
|
180
|
-
ZMFactory.new(
|
181
|
-
elsif
|
182
|
-
FFIFactory.new(
|
180
|
+
native_interface = opts[:native_interface] || Geos.preferred_native_interface
|
181
|
+
if opts[:has_z_coordinate] && opts[:has_m_coordinate]
|
182
|
+
ZMFactory.new(opts)
|
183
|
+
elsif native_interface == :ffi
|
184
|
+
FFIFactory.new(opts)
|
183
185
|
else
|
184
|
-
CAPIFactory.create(
|
186
|
+
CAPIFactory.create(opts)
|
185
187
|
end
|
186
188
|
end
|
187
189
|
end
|
@@ -194,8 +196,8 @@ module RGeo
|
|
194
196
|
# an SRID and it will automatically fetch the appropriate Proj4
|
195
197
|
# and CoordSys objects.
|
196
198
|
|
197
|
-
def factory_generator(
|
198
|
-
|
199
|
+
def factory_generator(defaults = {})
|
200
|
+
proc { |c| factory(defaults.merge(c)) }
|
199
201
|
end
|
200
202
|
end
|
201
203
|
end
|
data/lib/rgeo/geos/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Various Geos-related internal utilities
|
@@ -8,14 +10,14 @@ module RGeo
|
|
8
10
|
module Geos
|
9
11
|
module Utils # :nodoc:
|
10
12
|
class << self
|
11
|
-
def ffi_coord_seqs_equal?(
|
12
|
-
|
13
|
-
|
14
|
-
if
|
15
|
-
(0...
|
16
|
-
return false unless
|
17
|
-
|
18
|
-
(!
|
13
|
+
def ffi_coord_seqs_equal?(cs1, cs2, check_z)
|
14
|
+
len1 = cs1.length
|
15
|
+
len2 = cs2.length
|
16
|
+
if len1 == len2
|
17
|
+
(0...len1).each do |i|
|
18
|
+
return false unless cs1.get_x(i) == cs2.get_x(i) &&
|
19
|
+
cs1.get_y(i) == cs2.get_y(i) &&
|
20
|
+
(!check_z || cs1.get_z(i) == cs2.get_z(i))
|
19
21
|
end
|
20
22
|
true
|
21
23
|
else
|
@@ -23,53 +25,59 @@ module RGeo
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
def ffi_compute_dimension(
|
27
|
-
|
28
|
-
case
|
28
|
+
def ffi_compute_dimension(geom)
|
29
|
+
result = -1
|
30
|
+
case geom.type_id
|
29
31
|
when ::Geos::GeomTypes::GEOS_POINT
|
30
|
-
|
32
|
+
result = 0
|
31
33
|
when ::Geos::GeomTypes::GEOS_MULTIPOINT
|
32
|
-
|
34
|
+
result = 0 unless geom.empty?
|
33
35
|
when ::Geos::GeomTypes::GEOS_LINESTRING, ::Geos::GeomTypes::GEOS_LINEARRING
|
34
|
-
|
36
|
+
result = 1
|
35
37
|
when ::Geos::GeomTypes::GEOS_MULTILINESTRING
|
36
|
-
|
38
|
+
result = 1 unless geom.empty?
|
37
39
|
when ::Geos::GeomTypes::GEOS_POLYGON
|
38
|
-
|
40
|
+
result = 2
|
39
41
|
when ::Geos::GeomTypes::GEOS_MULTIPOLYGON
|
40
|
-
|
42
|
+
result = 2 unless geom.empty?
|
41
43
|
when ::Geos::GeomTypes::GEOS_GEOMETRYCOLLECTION
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
geom.each do |g|
|
45
|
+
dim = ffi_compute_dimension(g)
|
46
|
+
result = dim if result < dim
|
45
47
|
end
|
46
48
|
end
|
47
|
-
|
49
|
+
result
|
48
50
|
end
|
49
51
|
|
50
|
-
def ffi_coord_seq_hash(
|
51
|
-
(0...
|
52
|
-
[
|
52
|
+
def ffi_coord_seq_hash(cs, hash = 0)
|
53
|
+
(0...cs.length).inject(hash) do |h, i|
|
54
|
+
[hash, cs.get_x(i), cs.get_y(i), cs.get_z(i)].hash
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
def ffi_supports_prepared_level_1
|
59
|
+
FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSPreparedContains_r)
|
60
|
+
end
|
61
|
+
|
62
|
+
def ffi_supports_prepared_level_2
|
63
|
+
FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSPreparedDisjoint_r)
|
64
|
+
end
|
65
|
+
|
66
|
+
def ffi_supports_set_output_dimension
|
67
|
+
FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSWKTWriter_setOutputDimension_r)
|
65
68
|
end
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
def ffi_supports_unary_union
|
71
|
+
FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSUnaryUnion_r)
|
72
|
+
end
|
73
|
+
|
74
|
+
def psych_wkt_generator
|
75
|
+
WKRep::WKTGenerator.new(convert_case: :upper)
|
76
|
+
end
|
77
|
+
|
78
|
+
def marshal_wkb_generator
|
79
|
+
WKRep::WKBGenerator.new
|
80
|
+
end
|
73
81
|
end
|
74
82
|
end
|
75
83
|
end
|
data/lib/rgeo/geos/zm_factory.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# GEOS zm factory implementation
|
@@ -10,6 +12,7 @@ module RGeo
|
|
10
12
|
|
11
13
|
class ZMFactory
|
12
14
|
include Feature::Factory::Instance
|
15
|
+
include ImplHelper::Utils
|
13
16
|
|
14
17
|
# :stopdoc:
|
15
18
|
|
@@ -31,66 +34,66 @@ module RGeo
|
|
31
34
|
# Create a new factory. Returns nil if the GEOS implementation is
|
32
35
|
# not supported.
|
33
36
|
|
34
|
-
def create(
|
35
|
-
return
|
36
|
-
new(
|
37
|
+
def create(opts = {})
|
38
|
+
return unless Geos.supported?
|
39
|
+
new(opts)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
|
-
def initialize(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if (!
|
45
|
-
|
46
|
-
if
|
47
|
-
|
48
|
-
|
43
|
+
def initialize(opts = {}) # :nodoc:
|
44
|
+
proj4 = opts[:proj4]
|
45
|
+
coord_sys = opts[:coord_sys]
|
46
|
+
srid = opts[:srid]
|
47
|
+
if (!proj4 || !coord_sys) && srid && (db = opts[:srs_database])
|
48
|
+
entry = db.get(srid.to_i)
|
49
|
+
if entry
|
50
|
+
proj4 ||= entry.proj4
|
51
|
+
coord_sys ||= entry.coord_sys
|
49
52
|
end
|
50
53
|
end
|
51
|
-
|
52
|
-
|
53
|
-
uses_lenient_multi_polygon_assertions:
|
54
|
-
|
55
|
-
buffer_resolution:
|
56
|
-
wkt_generator:
|
57
|
-
wkb_generator:
|
58
|
-
srid:
|
54
|
+
srid ||= coord_sys.authority_code if coord_sys
|
55
|
+
config = {
|
56
|
+
uses_lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions] ||
|
57
|
+
opts[:uses_lenient_multi_polygon_assertions],
|
58
|
+
buffer_resolution: opts[:buffer_resolution], auto_prepare: opts[:auto_prepare],
|
59
|
+
wkt_generator: opts[:wkt_generator], wkt_parser: opts[:wkt_parser],
|
60
|
+
wkb_generator: opts[:wkb_generator], wkb_parser: opts[:wkb_parser],
|
61
|
+
srid: srid.to_i, proj4: proj4, coord_sys: coord_sys
|
59
62
|
}
|
60
|
-
|
61
|
-
if
|
62
|
-
@zfactory = FFIFactory.new(
|
63
|
-
@mfactory = FFIFactory.new(
|
63
|
+
native_interface = opts[:native_interface] || Geos.preferred_native_interface
|
64
|
+
if native_interface == :ffi
|
65
|
+
@zfactory = FFIFactory.new(config.merge(has_z_coordinate: true))
|
66
|
+
@mfactory = FFIFactory.new(config.merge(has_m_coordinate: true))
|
64
67
|
else
|
65
|
-
@zfactory = CAPIFactory.create(
|
66
|
-
@mfactory = CAPIFactory.create(
|
68
|
+
@zfactory = CAPIFactory.create(config.merge(has_z_coordinate: true))
|
69
|
+
@mfactory = CAPIFactory.create(config.merge(has_m_coordinate: true))
|
67
70
|
end
|
68
71
|
|
69
|
-
|
70
|
-
case
|
71
|
-
when
|
72
|
-
@wkt_generator = WKRep::WKTGenerator.new(
|
72
|
+
wkt_generator = opts[:wkt_generator]
|
73
|
+
case wkt_generator
|
74
|
+
when Hash
|
75
|
+
@wkt_generator = WKRep::WKTGenerator.new(wkt_generator)
|
73
76
|
else
|
74
77
|
@wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
|
75
78
|
end
|
76
|
-
|
77
|
-
case
|
78
|
-
when
|
79
|
-
@wkb_generator = WKRep::WKBGenerator.new(
|
79
|
+
wkb_generator = opts[:wkb_generator]
|
80
|
+
case wkb_generator
|
81
|
+
when Hash
|
82
|
+
@wkb_generator = WKRep::WKBGenerator.new(wkb_generator)
|
80
83
|
else
|
81
84
|
@wkb_generator = WKRep::WKBGenerator.new
|
82
85
|
end
|
83
|
-
|
84
|
-
case
|
85
|
-
when
|
86
|
-
@wkt_parser = WKRep::WKTParser.new(self,
|
86
|
+
wkt_parser = opts[:wkt_parser]
|
87
|
+
case wkt_parser
|
88
|
+
when Hash
|
89
|
+
@wkt_parser = WKRep::WKTParser.new(self, wkt_parser)
|
87
90
|
else
|
88
91
|
@wkt_parser = WKRep::WKTParser.new(self)
|
89
92
|
end
|
90
|
-
|
91
|
-
case
|
92
|
-
when
|
93
|
-
@wkb_parser = WKRep::WKBParser.new(self,
|
93
|
+
wkb_parser = opts[:wkb_parser]
|
94
|
+
case wkb_parser
|
95
|
+
when Hash
|
96
|
+
@wkb_parser = WKRep::WKBParser.new(self, wkb_parser)
|
94
97
|
else
|
95
98
|
@wkb_parser = WKRep::WKBParser.new(self)
|
96
99
|
end
|
@@ -99,104 +102,104 @@ module RGeo
|
|
99
102
|
# Marshal support
|
100
103
|
|
101
104
|
def marshal_dump # :nodoc:
|
102
|
-
|
105
|
+
hash = {
|
103
106
|
"srid" => @zfactory.srid,
|
104
107
|
"bufr" => @zfactory.buffer_resolution,
|
105
|
-
"wktg" => @wkt_generator.
|
106
|
-
"wkbg" => @wkb_generator.
|
107
|
-
"wktp" => @wkt_parser.
|
108
|
-
"wkbp" => @wkb_parser.
|
108
|
+
"wktg" => @wkt_generator.properties,
|
109
|
+
"wkbg" => @wkb_generator.properties,
|
110
|
+
"wktp" => @wkt_parser.properties,
|
111
|
+
"wkbp" => @wkb_parser.properties,
|
109
112
|
"lmpa" => @zfactory.lenient_multi_polygon_assertions?,
|
110
113
|
"apre" => @zfactory.property(:auto_prepare) == :simple,
|
111
114
|
"nffi" => @zfactory.is_a?(FFIFactory)
|
112
115
|
}
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
proj4 = @zfactory.proj4
|
117
|
+
coord_sys = @zfactory.coord_sys
|
118
|
+
hash["proj4"] = proj4.marshal_dump if proj4
|
119
|
+
hash["cs"] = coord_sys.to_wkt if coord_sys
|
120
|
+
hash
|
118
121
|
end
|
119
122
|
|
120
|
-
def marshal_load(
|
121
|
-
if (
|
122
|
-
|
123
|
-
|
123
|
+
def marshal_load(data) # :nodoc:
|
124
|
+
if (proj4_data = data["proj4"]) && CoordSys.check!(:proj4)
|
125
|
+
proj4 = CoordSys::Proj4.allocate
|
126
|
+
proj4.marshal_load(proj4_data)
|
124
127
|
else
|
125
|
-
|
128
|
+
proj4 = nil
|
126
129
|
end
|
127
|
-
if (
|
128
|
-
|
130
|
+
if (coord_sys_data = data["cs"])
|
131
|
+
coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data)
|
129
132
|
else
|
130
|
-
|
133
|
+
coord_sys = nil
|
131
134
|
end
|
132
135
|
initialize(
|
133
|
-
native_interface: (
|
134
|
-
has_z_coordinate:
|
135
|
-
has_m_coordinate:
|
136
|
-
srid:
|
137
|
-
buffer_resolution:
|
138
|
-
wkt_generator:
|
139
|
-
wkb_generator:
|
140
|
-
wkt_parser:
|
141
|
-
wkb_parser:
|
142
|
-
uses_lenient_multi_polygon_assertions:
|
143
|
-
auto_prepare: (
|
144
|
-
proj4:
|
145
|
-
coord_sys:
|
136
|
+
native_interface: (data["nffi"] ? :ffi : :capi),
|
137
|
+
has_z_coordinate: data["hasz"],
|
138
|
+
has_m_coordinate: data["hasm"],
|
139
|
+
srid: data["srid"],
|
140
|
+
buffer_resolution: data["bufr"],
|
141
|
+
wkt_generator: symbolize_hash(data["wktg"]),
|
142
|
+
wkb_generator: symbolize_hash(data["wkbg"]),
|
143
|
+
wkt_parser: symbolize_hash(data["wktp"]),
|
144
|
+
wkb_parser: symbolize_hash(data["wkbp"]),
|
145
|
+
uses_lenient_multi_polygon_assertions: data["lmpa"],
|
146
|
+
auto_prepare: (data["apre"] ? :simple : :disabled),
|
147
|
+
proj4: proj4,
|
148
|
+
coord_sys: coord_sys
|
146
149
|
)
|
147
150
|
end
|
148
151
|
|
149
152
|
# Psych support
|
150
153
|
|
151
|
-
def encode_with(
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
if (
|
162
|
-
|
163
|
-
|
154
|
+
def encode_with(coder) # :nodoc:
|
155
|
+
coder["srid"] = @zfactory.srid
|
156
|
+
coder["buffer_resolution"] = @zfactory.buffer_resolution
|
157
|
+
coder["lenient_multi_polygon_assertions"] = @zfactory.lenient_multi_polygon_assertions?
|
158
|
+
coder["wkt_generator"] = @wkt_generator.properties
|
159
|
+
coder["wkb_generator"] = @wkb_generator.properties
|
160
|
+
coder["wkt_parser"] = @wkt_parser.properties
|
161
|
+
coder["wkb_parser"] = @wkb_parser.properties
|
162
|
+
coder["auto_prepare"] = @zfactory.property(:auto_prepare).to_s
|
163
|
+
coder["native_interface"] = @zfactory.is_a?(FFIFactory) ? "ffi" : "capi"
|
164
|
+
if (proj4 = @zfactory.proj4)
|
165
|
+
str = proj4.original_str || proj4.canonical_str
|
166
|
+
coder["proj4"] = proj4.radians? ? { "proj4" => str, "radians" => true } : str
|
164
167
|
end
|
165
|
-
if (
|
166
|
-
|
168
|
+
if (coord_sys = @zfactory.coord_sys)
|
169
|
+
coder["coord_sys"] = coord_sys.to_wkt
|
167
170
|
end
|
168
171
|
end
|
169
172
|
|
170
|
-
def init_with(
|
171
|
-
if (
|
173
|
+
def init_with(coder) # :nodoc:
|
174
|
+
if (proj4_data = coder["proj4"])
|
172
175
|
CoordSys.check!(:proj4)
|
173
|
-
if
|
174
|
-
|
176
|
+
if proj4_data.is_a?(Hash)
|
177
|
+
proj4 = CoordSys::Proj4.create(proj4_data["proj4"], radians: proj4_data["radians"])
|
175
178
|
else
|
176
|
-
|
179
|
+
proj4 = CoordSys::Proj4.create(proj4_data.to_s)
|
177
180
|
end
|
178
181
|
else
|
179
|
-
|
182
|
+
proj4 = nil
|
180
183
|
end
|
181
|
-
if (
|
182
|
-
|
184
|
+
if (coord_sys_data = coder["cs"])
|
185
|
+
coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data.to_s)
|
183
186
|
else
|
184
|
-
|
187
|
+
coord_sys = nil
|
185
188
|
end
|
186
189
|
initialize(
|
187
|
-
native_interface:
|
188
|
-
has_z_coordinate:
|
189
|
-
has_m_coordinate:
|
190
|
-
srid:
|
191
|
-
buffer_resolution:
|
192
|
-
wkt_generator:
|
193
|
-
wkb_generator:
|
194
|
-
wkt_parser:
|
195
|
-
wkb_parser:
|
196
|
-
auto_prepare:
|
197
|
-
uses_lenient_multi_polygon_assertions:
|
198
|
-
proj4:
|
199
|
-
coord_sys:
|
190
|
+
native_interface: coder["native_interface"] == "ffi" ? :ffi : :capi,
|
191
|
+
has_z_coordinate: coder["has_z_coordinate"],
|
192
|
+
has_m_coordinate: coder["has_m_coordinate"],
|
193
|
+
srid: coder["srid"],
|
194
|
+
buffer_resolution: coder["buffer_resolution"],
|
195
|
+
wkt_generator: symbolize_hash(coder["wkt_generator"]),
|
196
|
+
wkb_generator: symbolize_hash(coder["wkb_generator"]),
|
197
|
+
wkt_parser: symbolize_hash(coder["wkt_parser"]),
|
198
|
+
wkb_parser: symbolize_hash(coder["wkb_parser"]),
|
199
|
+
auto_prepare: coder["auto_prepare"] == "disabled" ? :disabled : :simple,
|
200
|
+
uses_lenient_multi_polygon_assertions: coder["lenient_multi_polygon_assertions"],
|
201
|
+
proj4: proj4,
|
202
|
+
coord_sys: coord_sys
|
200
203
|
)
|
201
204
|
end
|
202
205
|
|
@@ -233,8 +236,8 @@ module RGeo
|
|
233
236
|
|
234
237
|
# Factory equivalence test.
|
235
238
|
|
236
|
-
def eql?(
|
237
|
-
|
239
|
+
def eql?(rhs)
|
240
|
+
rhs.is_a?(ZMFactory) && rhs.z_factory == @zfactory
|
238
241
|
end
|
239
242
|
alias == eql?
|
240
243
|
|
@@ -246,8 +249,8 @@ module RGeo
|
|
246
249
|
|
247
250
|
# See RGeo::Feature::Factory#property
|
248
251
|
|
249
|
-
def property(
|
250
|
-
case
|
252
|
+
def property(name)
|
253
|
+
case name
|
251
254
|
when :has_z_coordinate, :has_m_coordinate, :is_cartesian
|
252
255
|
true
|
253
256
|
end
|
@@ -255,68 +258,68 @@ module RGeo
|
|
255
258
|
|
256
259
|
# See RGeo::Feature::Factory#parse_wkt
|
257
260
|
|
258
|
-
def parse_wkt(
|
259
|
-
@wkt_parser.parse(
|
261
|
+
def parse_wkt(str)
|
262
|
+
@wkt_parser.parse(str)
|
260
263
|
end
|
261
264
|
|
262
265
|
# See RGeo::Feature::Factory#parse_wkb
|
263
266
|
|
264
|
-
def parse_wkb(
|
265
|
-
@wkb_parser.parse(
|
267
|
+
def parse_wkb(str)
|
268
|
+
@wkb_parser.parse(str)
|
266
269
|
end
|
267
270
|
|
268
271
|
# See RGeo::Feature::Factory#point
|
269
272
|
|
270
|
-
def point(
|
271
|
-
|
273
|
+
def point(x, y, z = 0, m = 0)
|
274
|
+
create_feature(ZMPointImpl, @zfactory.point(x, y, z), @mfactory.point(x, y, m))
|
272
275
|
end
|
273
276
|
|
274
277
|
# See RGeo::Feature::Factory#line_string
|
275
278
|
|
276
|
-
def line_string(
|
277
|
-
|
279
|
+
def line_string(points)
|
280
|
+
create_feature(ZMLineStringImpl, @zfactory.line_string(points), @mfactory.line_string(points))
|
278
281
|
end
|
279
282
|
|
280
283
|
# See RGeo::Feature::Factory#line
|
281
284
|
|
282
|
-
def line(
|
283
|
-
|
285
|
+
def line(start, stop)
|
286
|
+
create_feature(ZMLineImpl, @zfactory.line(start, stop), @mfactory.line(start, stop))
|
284
287
|
end
|
285
288
|
|
286
289
|
# See RGeo::Feature::Factory#linear_ring
|
287
290
|
|
288
|
-
def linear_ring(
|
289
|
-
|
291
|
+
def linear_ring(points)
|
292
|
+
create_feature(ZMLinearRingImpl, @zfactory.linear_ring(points), @mfactory.linear_ring(points))
|
290
293
|
end
|
291
294
|
|
292
295
|
# See RGeo::Feature::Factory#polygon
|
293
296
|
|
294
|
-
def polygon(
|
295
|
-
|
297
|
+
def polygon(outer_ring, inner_rings = nil)
|
298
|
+
create_feature(ZMPolygonImpl, @zfactory.polygon(outer_ring, inner_rings), @mfactory.polygon(outer_ring, inner_rings))
|
296
299
|
end
|
297
300
|
|
298
301
|
# See RGeo::Feature::Factory#collection
|
299
302
|
|
300
|
-
def collection(
|
301
|
-
|
303
|
+
def collection(elems)
|
304
|
+
create_feature(ZMGeometryCollectionImpl, @zfactory.collection(elems), @mfactory.collection(elems))
|
302
305
|
end
|
303
306
|
|
304
307
|
# See RGeo::Feature::Factory#multi_point
|
305
308
|
|
306
|
-
def multi_point(
|
307
|
-
|
309
|
+
def multi_point(elems)
|
310
|
+
create_feature(ZMMultiPointImpl, @zfactory.multi_point(elems), @mfactory.multi_point(elems))
|
308
311
|
end
|
309
312
|
|
310
313
|
# See RGeo::Feature::Factory#multi_line_string
|
311
314
|
|
312
|
-
def multi_line_string(
|
313
|
-
|
315
|
+
def multi_line_string(elems)
|
316
|
+
create_feature(ZMMultiLineStringImpl, @zfactory.multi_line_string(elems), @mfactory.multi_line_string(elems))
|
314
317
|
end
|
315
318
|
|
316
319
|
# See RGeo::Feature::Factory#multi_polygon
|
317
320
|
|
318
|
-
def multi_polygon(
|
319
|
-
|
321
|
+
def multi_polygon(elems)
|
322
|
+
create_feature(ZMMultiPolygonImpl, @zfactory.multi_polygon(elems), @mfactory.multi_polygon(elems))
|
320
323
|
end
|
321
324
|
|
322
325
|
# See RGeo::Feature::Factory#proj4
|
@@ -333,73 +336,56 @@ module RGeo
|
|
333
336
|
|
334
337
|
# See RGeo::Feature::Factory#override_cast
|
335
338
|
|
336
|
-
def override_cast(
|
337
|
-
return
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
case original_
|
339
|
+
def override_cast(original, ntype, flags)
|
340
|
+
return unless Geos.supported?
|
341
|
+
keep_subtype = flags[:keep_subtype]
|
342
|
+
project = flags[:project]
|
343
|
+
type = original.geometry_type
|
344
|
+
ntype = type if keep_subtype && type.include?(ntype)
|
345
|
+
case original
|
344
346
|
when ZMGeometryMethods
|
345
347
|
# Optimization if we're just changing factories, but to
|
346
348
|
# another ZM factory.
|
347
|
-
if
|
348
|
-
(!
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
return
|
349
|
+
if original.factory != self && ntype == type &&
|
350
|
+
(!project || original.factory.proj4 == @proj4)
|
351
|
+
zresult = original.z_geometry.dup
|
352
|
+
zresult.factory = @zfactory
|
353
|
+
mresult = original.m_geometry.dup
|
354
|
+
mresult.factory = @mfactory
|
355
|
+
return original.class.create(self, zresult, mresult)
|
354
356
|
end
|
355
357
|
# LineString conversion optimization.
|
356
|
-
if (
|
357
|
-
(!
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
return ZMLineStringImpl.create(self,
|
358
|
+
if (original.factory != self || ntype != type) &&
|
359
|
+
(!project || original.factory.proj4 == @proj4) &&
|
360
|
+
type.subtypeof?(Feature::LineString) && ntype.subtypeof?(Feature::LineString)
|
361
|
+
klass = Factory::IMPL_CLASSES[ntype]
|
362
|
+
zresult = klass._copy_from(@zfactory, original.z_geometry)
|
363
|
+
mresult = klass._copy_from(@mfactory, original.m_geometry)
|
364
|
+
return ZMLineStringImpl.create(self, zresult, mresult)
|
363
365
|
end
|
364
366
|
end
|
365
367
|
false
|
366
368
|
end
|
367
369
|
|
368
|
-
def
|
369
|
-
|
370
|
-
|
370
|
+
def create_feature(klass, zgeometry, mgeometry) # :nodoc:
|
371
|
+
klass ||= TYPE_KLASSES[zgeometry.geometry_type] || ZMGeometryImpl
|
372
|
+
zgeometry && mgeometry ? klass.new(self, zgeometry, mgeometry) : nil
|
371
373
|
end
|
372
374
|
|
373
|
-
def
|
374
|
-
|
375
|
-
@marshal_wkb_generator = RGeo::WKRep::WKBGenerator.new(
|
376
|
-
type_format: :wkb12)
|
377
|
-
end
|
378
|
-
@marshal_wkb_generator
|
375
|
+
def marshal_wkb_generator
|
376
|
+
@marshal_wkb_generator ||= RGeo::WKRep::WKBGenerator.new(typeformat: :wkb12)
|
379
377
|
end
|
380
378
|
|
381
|
-
def
|
382
|
-
|
383
|
-
@marshal_wkb_parser = RGeo::WKRep::WKBParser.new(self,
|
384
|
-
support_wkb12: true)
|
385
|
-
end
|
386
|
-
@marshal_wkb_parser
|
379
|
+
def marshal_wkb_parser
|
380
|
+
@marshal_wkb_parser ||= RGeo::WKRep::WKBParser.new(self, support_wkb12: true)
|
387
381
|
end
|
388
382
|
|
389
|
-
def
|
390
|
-
|
391
|
-
@psych_wkt_generator = RGeo::WKRep::WKTGenerator.new(
|
392
|
-
tag_format: :wkt12)
|
393
|
-
end
|
394
|
-
@psych_wkt_generator
|
383
|
+
def psych_wkt_generator
|
384
|
+
@psych_wkt_generator ||= RGeo::WKRep::WKTGenerator.new(tag_format: :wkt12)
|
395
385
|
end
|
396
386
|
|
397
|
-
def
|
398
|
-
|
399
|
-
@psych_wkt_parser = RGeo::WKRep::WKTParser.new(self,
|
400
|
-
support_wkt12: true, support_ewkt: true)
|
401
|
-
end
|
402
|
-
@psych_wkt_parser
|
387
|
+
def psych_wkt_parser
|
388
|
+
@psych_wkt_parser ||= RGeo::WKRep::WKTParser.new(self, support_wkt12: true, support_ewkt: true)
|
403
389
|
end
|
404
390
|
end
|
405
391
|
end
|