rgeo 3.0.0.pre.rc.2 → 3.0.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 +10 -1
- data/ext/geos_c_impl/analysis.c +26 -23
- data/ext/geos_c_impl/analysis.h +8 -5
- 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 +15 -8
- data/ext/geos_c_impl/errors.h +4 -1
- data/ext/geos_c_impl/extconf.rb +40 -30
- data/ext/geos_c_impl/factory.c +405 -389
- data/ext/geos_c_impl/factory.h +71 -49
- data/ext/geos_c_impl/geometry.c +485 -408
- data/ext/geos_c_impl/geometry.h +5 -5
- data/ext/geos_c_impl/geometry_collection.c +269 -198
- data/ext/geos_c_impl/geometry_collection.h +6 -7
- data/ext/geos_c_impl/globals.c +99 -21
- data/ext/geos_c_impl/globals.h +3 -2
- data/ext/geos_c_impl/line_string.c +261 -220
- data/ext/geos_c_impl/line_string.h +5 -6
- data/ext/geos_c_impl/main.c +8 -9
- data/ext/geos_c_impl/point.c +62 -65
- data/ext/geos_c_impl/point.h +4 -5
- data/ext/geos_c_impl/polygon.c +121 -90
- data/ext/geos_c_impl/polygon.h +11 -9
- data/ext/geos_c_impl/preface.h +4 -13
- data/ext/geos_c_impl/ruby_more.c +39 -37
- data/ext/geos_c_impl/ruby_more.h +11 -2
- data/lib/rgeo/cartesian/analysis.rb +5 -3
- data/lib/rgeo/cartesian/bounding_box.rb +74 -79
- data/lib/rgeo/cartesian/calculations.rb +20 -26
- data/lib/rgeo/cartesian/factory.rb +52 -89
- data/lib/rgeo/cartesian/feature_methods.rb +0 -5
- data/lib/rgeo/cartesian/interface.rb +6 -5
- data/lib/rgeo/cartesian/planar_graph.rb +10 -16
- data/lib/rgeo/cartesian/sweepline_intersector.rb +1 -3
- data/lib/rgeo/cartesian/valid_op.rb +1 -3
- data/lib/rgeo/coord_sys/cs/entities.rb +299 -99
- data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +85 -37
- data/lib/rgeo/coord_sys.rb +1 -9
- data/lib/rgeo/feature/curve.rb +0 -11
- data/lib/rgeo/feature/factory.rb +26 -36
- data/lib/rgeo/feature/factory_generator.rb +6 -11
- data/lib/rgeo/feature/geometry.rb +41 -40
- data/lib/rgeo/feature/geometry_collection.rb +3 -4
- data/lib/rgeo/feature/line_string.rb +1 -2
- 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 +0 -1
- data/lib/rgeo/feature/point.rb +0 -1
- data/lib/rgeo/feature/polygon.rb +1 -2
- data/lib/rgeo/feature/surface.rb +0 -1
- data/lib/rgeo/feature/types.rb +73 -83
- data/lib/rgeo/geographic/factory.rb +93 -119
- data/lib/rgeo/geographic/interface.rb +62 -116
- data/lib/rgeo/geographic/projected_feature_methods.rb +2 -16
- data/lib/rgeo/geographic/projected_window.rb +36 -22
- data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -3
- data/lib/rgeo/geographic/simple_mercator_projector.rb +24 -21
- data/lib/rgeo/geographic/spherical_feature_methods.rb +8 -8
- data/lib/rgeo/geographic/spherical_math.rb +17 -20
- data/lib/rgeo/geographic.rb +1 -1
- data/lib/rgeo/geos/capi_factory.rb +70 -124
- data/lib/rgeo/geos/capi_feature_classes.rb +0 -29
- data/lib/rgeo/geos/ffi_factory.rb +90 -131
- data/lib/rgeo/geos/ffi_feature_methods.rb +73 -128
- data/lib/rgeo/geos/interface.rb +21 -36
- data/lib/rgeo/geos/utils.rb +3 -3
- data/lib/rgeo/geos/zm_factory.rb +53 -76
- data/lib/rgeo/geos/zm_feature_methods.rb +16 -34
- data/lib/rgeo/geos.rb +2 -5
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +5 -18
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +18 -42
- data/lib/rgeo/impl_helper/basic_point_methods.rb +1 -13
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +16 -25
- data/lib/rgeo/impl_helper/utils.rb +21 -0
- data/lib/rgeo/impl_helper/valid_op.rb +12 -16
- data/lib/rgeo/impl_helper/validity_check.rb +3 -3
- 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 +10 -9
data/lib/rgeo/geos/zm_factory.rb
CHANGED
@@ -9,7 +9,6 @@
|
|
9
9
|
module RGeo
|
10
10
|
module Geos
|
11
11
|
# A factory for Geos that handles both Z and M.
|
12
|
-
|
13
12
|
class ZMFactory
|
14
13
|
include Feature::Factory::Instance
|
15
14
|
include ImplHelper::Utils
|
@@ -41,7 +40,6 @@ module RGeo
|
|
41
40
|
end
|
42
41
|
|
43
42
|
def initialize(opts = {}) # :nodoc:
|
44
|
-
proj4 = opts[:proj4]
|
45
43
|
coord_sys = opts[:coord_sys]
|
46
44
|
srid = opts[:srid]
|
47
45
|
srid ||= coord_sys.authority_code if coord_sys
|
@@ -49,7 +47,7 @@ module RGeo
|
|
49
47
|
buffer_resolution: opts[:buffer_resolution], auto_prepare: opts[:auto_prepare],
|
50
48
|
wkt_generator: opts[:wkt_generator], wkt_parser: opts[:wkt_parser],
|
51
49
|
wkb_generator: opts[:wkb_generator], wkb_parser: opts[:wkb_parser],
|
52
|
-
srid: srid.to_i,
|
50
|
+
srid: srid.to_i, coord_sys: coord_sys
|
53
51
|
}
|
54
52
|
native_interface = opts[:native_interface] || Geos.preferred_native_interface
|
55
53
|
if native_interface == :ffi
|
@@ -61,33 +59,37 @@ module RGeo
|
|
61
59
|
end
|
62
60
|
|
63
61
|
wkt_generator = opts[:wkt_generator]
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
@wkt_generator =
|
63
|
+
case wkt_generator
|
64
|
+
when Hash
|
65
|
+
WKRep::WKTGenerator.new(wkt_generator)
|
66
|
+
else
|
67
|
+
WKRep::WKTGenerator.new(convert_case: :upper)
|
68
|
+
end
|
70
69
|
wkb_generator = opts[:wkb_generator]
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
@wkb_generator =
|
71
|
+
case wkb_generator
|
72
|
+
when Hash
|
73
|
+
WKRep::WKBGenerator.new(wkb_generator)
|
74
|
+
else
|
75
|
+
WKRep::WKBGenerator.new
|
76
|
+
end
|
77
77
|
wkt_parser = opts[:wkt_parser]
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
@wkt_parser =
|
79
|
+
case wkt_parser
|
80
|
+
when Hash
|
81
|
+
WKRep::WKTParser.new(self, wkt_parser)
|
82
|
+
else
|
83
|
+
WKRep::WKTParser.new(self)
|
84
|
+
end
|
84
85
|
wkb_parser = opts[:wkb_parser]
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
@wkb_parser =
|
87
|
+
case wkb_parser
|
88
|
+
when Hash
|
89
|
+
WKRep::WKBParser.new(self, wkb_parser)
|
90
|
+
else
|
91
|
+
WKRep::WKBParser.new(self)
|
92
|
+
end
|
91
93
|
end
|
92
94
|
|
93
95
|
# Marshal support
|
@@ -103,25 +105,15 @@ module RGeo
|
|
103
105
|
"apre" => @zfactory.property(:auto_prepare) == :simple,
|
104
106
|
"nffi" => @zfactory.is_a?(FFIFactory)
|
105
107
|
}
|
106
|
-
proj4 = @zfactory.proj4
|
107
108
|
coord_sys = @zfactory.coord_sys
|
108
|
-
hash["proj4"] = proj4.marshal_dump if proj4
|
109
109
|
hash["cs"] = coord_sys.to_wkt if coord_sys
|
110
110
|
hash
|
111
111
|
end
|
112
112
|
|
113
113
|
def marshal_load(data) # :nodoc:
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
else
|
118
|
-
proj4 = nil
|
119
|
-
end
|
120
|
-
if (coord_sys_data = data["cs"])
|
121
|
-
coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data)
|
122
|
-
else
|
123
|
-
coord_sys = nil
|
124
|
-
end
|
114
|
+
cs_class = CoordSys::CONFIG.default_coord_sys_class
|
115
|
+
coord_sys = data["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
|
116
|
+
|
125
117
|
initialize(
|
126
118
|
native_interface: (data["nffi"] ? :ffi : :capi),
|
127
119
|
has_z_coordinate: data["hasz"],
|
@@ -133,7 +125,6 @@ module RGeo
|
|
133
125
|
wkt_parser: symbolize_hash(data["wktp"]),
|
134
126
|
wkb_parser: symbolize_hash(data["wkbp"]),
|
135
127
|
auto_prepare: (data["apre"] ? :simple : :disabled),
|
136
|
-
proj4: proj4,
|
137
128
|
coord_sys: coord_sys
|
138
129
|
)
|
139
130
|
end
|
@@ -149,31 +140,16 @@ module RGeo
|
|
149
140
|
coder["wkb_parser"] = @wkb_parser.properties
|
150
141
|
coder["auto_prepare"] = @zfactory.property(:auto_prepare).to_s
|
151
142
|
coder["native_interface"] = @zfactory.is_a?(FFIFactory) ? "ffi" : "capi"
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
if (coord_sys = @zfactory.coord_sys)
|
157
|
-
coder["coord_sys"] = coord_sys.to_wkt
|
158
|
-
end
|
143
|
+
|
144
|
+
return unless (coord_sys = @zfactory.coord_sys)
|
145
|
+
|
146
|
+
coder["coord_sys"] = coord_sys.to_wkt
|
159
147
|
end
|
160
148
|
|
161
149
|
def init_with(coder) # :nodoc:
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
proj4 = CoordSys::Proj4.create(proj4_data["proj4"], radians: proj4_data["radians"])
|
166
|
-
else
|
167
|
-
proj4 = CoordSys::Proj4.create(proj4_data.to_s)
|
168
|
-
end
|
169
|
-
else
|
170
|
-
proj4 = nil
|
171
|
-
end
|
172
|
-
if (coord_sys_data = coder["cs"])
|
173
|
-
coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data.to_s)
|
174
|
-
else
|
175
|
-
coord_sys = nil
|
176
|
-
end
|
150
|
+
cs_class = CoordSys::CONFIG.default_coord_sys_class
|
151
|
+
coord_sys = coder["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
|
152
|
+
|
177
153
|
initialize(
|
178
154
|
native_interface: coder["native_interface"] == "ffi" ? :ffi : :capi,
|
179
155
|
has_z_coordinate: coder["has_z_coordinate"],
|
@@ -185,7 +161,6 @@ module RGeo
|
|
185
161
|
wkt_parser: symbolize_hash(coder["wkt_parser"]),
|
186
162
|
wkb_parser: symbolize_hash(coder["wkb_parser"]),
|
187
163
|
auto_prepare: coder["auto_prepare"] == "disabled" ? :disabled : :simple,
|
188
|
-
proj4: proj4,
|
189
164
|
coord_sys: coord_sys
|
190
165
|
)
|
191
166
|
end
|
@@ -217,8 +192,8 @@ module RGeo
|
|
217
192
|
|
218
193
|
# Factory equivalence test.
|
219
194
|
|
220
|
-
def eql?(
|
221
|
-
|
195
|
+
def eql?(other)
|
196
|
+
other.is_a?(ZMFactory) && other.z_factory == @zfactory
|
222
197
|
end
|
223
198
|
alias == eql?
|
224
199
|
|
@@ -252,7 +227,11 @@ module RGeo
|
|
252
227
|
# See RGeo::Feature::Factory#point
|
253
228
|
|
254
229
|
def point(x, y, z = 0, m = 0)
|
255
|
-
create_feature(
|
230
|
+
create_feature(
|
231
|
+
ZMPointImpl,
|
232
|
+
@zfactory.point(x, y, z),
|
233
|
+
@mfactory.point(x, y, m)
|
234
|
+
)
|
256
235
|
end
|
257
236
|
|
258
237
|
# See RGeo::Feature::Factory#line_string
|
@@ -276,7 +255,11 @@ module RGeo
|
|
276
255
|
# See RGeo::Feature::Factory#polygon
|
277
256
|
|
278
257
|
def polygon(outer_ring, inner_rings = nil)
|
279
|
-
create_feature(
|
258
|
+
create_feature(
|
259
|
+
ZMPolygonImpl,
|
260
|
+
@zfactory.polygon(outer_ring, inner_rings),
|
261
|
+
@mfactory.polygon(outer_ring, inner_rings)
|
262
|
+
)
|
280
263
|
end
|
281
264
|
|
282
265
|
# See RGeo::Feature::Factory#collection
|
@@ -303,12 +286,6 @@ module RGeo
|
|
303
286
|
create_feature(ZMMultiPolygonImpl, @zfactory.multi_polygon(elems), @mfactory.multi_polygon(elems))
|
304
287
|
end
|
305
288
|
|
306
|
-
# See RGeo::Feature::Factory#proj4
|
307
|
-
|
308
|
-
def proj4
|
309
|
-
@zfactory.proj4
|
310
|
-
end
|
311
|
-
|
312
289
|
# See RGeo::Feature::Factory#coord_sys
|
313
290
|
|
314
291
|
def coord_sys
|
@@ -328,7 +305,7 @@ module RGeo
|
|
328
305
|
# Optimization if we're just changing factories, but to
|
329
306
|
# another ZM factory.
|
330
307
|
if original.factory != self && ntype == type &&
|
331
|
-
(!project || original.factory.
|
308
|
+
(!project || original.factory.coord_sys == @coord_sys)
|
332
309
|
zresult = original.z_geometry.dup
|
333
310
|
zresult.factory = @zfactory
|
334
311
|
mresult = original.m_geometry.dup
|
@@ -337,7 +314,7 @@ module RGeo
|
|
337
314
|
end
|
338
315
|
# LineString conversion optimization.
|
339
316
|
if (original.factory != self || ntype != type) &&
|
340
|
-
(!project || original.factory.
|
317
|
+
(!project || original.factory.coord_sys == @coord_sys) &&
|
341
318
|
type.subtypeof?(Feature::LineString) && ntype.subtypeof?(Feature::LineString)
|
342
319
|
klass = Factory::IMPL_CLASSES[ntype]
|
343
320
|
zresult = klass._copy_from(@zfactory, original.z_geometry)
|
@@ -26,7 +26,7 @@ module RGeo
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def hash
|
29
|
-
@factory
|
29
|
+
[@factory, @zgeometry, @mgeometry].hash
|
30
30
|
end
|
31
31
|
|
32
32
|
def factory
|
@@ -77,20 +77,10 @@ module RGeo
|
|
77
77
|
@zgeometry.empty?
|
78
78
|
end
|
79
79
|
|
80
|
-
def is_empty?
|
81
|
-
warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
82
|
-
empty?
|
83
|
-
end
|
84
|
-
|
85
80
|
def simple?
|
86
81
|
@zgeometry.simple?
|
87
82
|
end
|
88
83
|
|
89
|
-
def is_simple?
|
90
|
-
warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
91
|
-
simple?
|
92
|
-
end
|
93
|
-
|
94
84
|
def is_3d?
|
95
85
|
true
|
96
86
|
end
|
@@ -169,12 +159,19 @@ module RGeo
|
|
169
159
|
|
170
160
|
def sym_difference(rhs)
|
171
161
|
rhs = RGeo::Feature.cast(rhs, self)
|
172
|
-
@factory.create_feature(
|
162
|
+
@factory.create_feature(
|
163
|
+
nil,
|
164
|
+
@zgeometry.sym_difference(rhs.z_geometry),
|
165
|
+
@mgeometry.sym_difference(rhs.m_geometry)
|
166
|
+
)
|
173
167
|
end
|
174
168
|
|
175
169
|
def rep_equals?(rhs)
|
176
170
|
rhs = RGeo::Feature.cast(rhs, self)
|
177
|
-
rhs.is_a?(self.class) &&
|
171
|
+
rhs.is_a?(self.class) &&
|
172
|
+
@factory.eql?(rhs.factory) &&
|
173
|
+
@zgeometry.rep_equals?(rhs.z_geometry) &&
|
174
|
+
@mgeometry.rep_equals?(rhs.m_geometry)
|
178
175
|
end
|
179
176
|
|
180
177
|
alias eql? rep_equals?
|
@@ -252,26 +249,16 @@ module RGeo
|
|
252
249
|
@zgeometry.closed?
|
253
250
|
end
|
254
251
|
|
255
|
-
def is_closed?
|
256
|
-
warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
257
|
-
closed?
|
258
|
-
end
|
259
|
-
|
260
252
|
def ring?
|
261
253
|
@zgeometry.ring?
|
262
254
|
end
|
263
255
|
|
264
|
-
def is_ring?
|
265
|
-
warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
266
|
-
ring?
|
267
|
-
end
|
268
|
-
|
269
256
|
def num_points
|
270
257
|
@zgeometry.num_points
|
271
258
|
end
|
272
259
|
|
273
|
-
def point_n(
|
274
|
-
@factory.create_feature(ZMPointImpl, @zgeometry.point_n(
|
260
|
+
def point_n(idx)
|
261
|
+
@factory.create_feature(ZMPointImpl, @zgeometry.point_n(idx), @mgeometry.point_n(idx))
|
275
262
|
end
|
276
263
|
|
277
264
|
def points
|
@@ -310,8 +297,8 @@ module RGeo
|
|
310
297
|
@zgeometry.num_interior_rings
|
311
298
|
end
|
312
299
|
|
313
|
-
def interior_ring_n(
|
314
|
-
@factory.create_feature(ZMLineStringImpl, @zgeometry.interior_ring_n(
|
300
|
+
def interior_ring_n(idx)
|
301
|
+
@factory.create_feature(ZMLineStringImpl, @zgeometry.interior_ring_n(idx), @mgeometry.interior_ring_n(idx))
|
315
302
|
end
|
316
303
|
|
317
304
|
def interior_rings
|
@@ -335,8 +322,8 @@ module RGeo
|
|
335
322
|
end
|
336
323
|
alias size num_geometries
|
337
324
|
|
338
|
-
def geometry_n(
|
339
|
-
@factory.create_feature(nil, @zgeometry.geometry_n(
|
325
|
+
def geometry_n(idx)
|
326
|
+
@factory.create_feature(nil, @zgeometry.geometry_n(idx), @mgeometry.geometry_n(idx))
|
340
327
|
end
|
341
328
|
alias [] geometry_n
|
342
329
|
|
@@ -363,11 +350,6 @@ module RGeo
|
|
363
350
|
@zgeometry.closed?
|
364
351
|
end
|
365
352
|
|
366
|
-
def is_closed?
|
367
|
-
warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
368
|
-
closed?
|
369
|
-
end
|
370
|
-
|
371
353
|
def coordinates
|
372
354
|
each.map(&:coordinates)
|
373
355
|
end
|
data/lib/rgeo/geos.rb
CHANGED
@@ -45,12 +45,9 @@ module RGeo
|
|
45
45
|
raise "Problem loading FFI" unless ::FFI::AutoPointer
|
46
46
|
FFI_SUPPORTED = true
|
47
47
|
FFI_SUPPORT_EXCEPTION = nil
|
48
|
-
rescue LoadError =>
|
48
|
+
rescue LoadError, StandardError => e
|
49
49
|
FFI_SUPPORTED = false
|
50
|
-
FFI_SUPPORT_EXCEPTION =
|
51
|
-
rescue StandardError => ex
|
52
|
-
FFI_SUPPORTED = false
|
53
|
-
FFI_SUPPORT_EXCEPTION = ex
|
50
|
+
FFI_SUPPORT_EXCEPTION = e
|
54
51
|
end
|
55
52
|
|
56
53
|
if FFI_SUPPORTED
|
@@ -27,12 +27,12 @@ module RGeo
|
|
27
27
|
@elements.size
|
28
28
|
end
|
29
29
|
|
30
|
-
def geometry_n(
|
31
|
-
|
30
|
+
def geometry_n(idx)
|
31
|
+
idx < 0 ? nil : @elements[idx]
|
32
32
|
end
|
33
33
|
|
34
|
-
def [](
|
35
|
-
@elements[
|
34
|
+
def [](idx)
|
35
|
+
@elements[idx]
|
36
36
|
end
|
37
37
|
|
38
38
|
def each(&block)
|
@@ -55,11 +55,6 @@ module RGeo
|
|
55
55
|
@elements.size == 0
|
56
56
|
end
|
57
57
|
|
58
|
-
def is_empty?
|
59
|
-
warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
60
|
-
empty?
|
61
|
-
end
|
62
|
-
|
63
58
|
def rep_equals?(rhs)
|
64
59
|
if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @elements.size == rhs.num_geometries
|
65
60
|
rhs.each_with_index { |p, i| return false unless @elements[i].rep_equals?(p) }
|
@@ -69,10 +64,7 @@ module RGeo
|
|
69
64
|
end
|
70
65
|
|
71
66
|
def hash
|
72
|
-
@hash ||=
|
73
|
-
hash = [factory, geometry_type].hash
|
74
|
-
@elements.inject(hash) { |h, g| (1_664_525 * h + g.hash).hash }
|
75
|
-
end
|
67
|
+
@hash ||= [factory, geometry_type, *@elements].hash
|
76
68
|
end
|
77
69
|
|
78
70
|
private
|
@@ -102,11 +94,6 @@ module RGeo
|
|
102
94
|
all?(&:closed?)
|
103
95
|
end
|
104
96
|
|
105
|
-
def is_closed?
|
106
|
-
warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
107
|
-
closed?
|
108
|
-
end
|
109
|
-
|
110
97
|
def length
|
111
98
|
@elements.inject(0.0) { |sum, obj| sum + obj.length }
|
112
99
|
end
|
@@ -19,9 +19,7 @@ module RGeo
|
|
19
19
|
# LineStrings in general need to check that there's not one point
|
20
20
|
# GEOS doesn't allow instantiation of single point LineStrings so
|
21
21
|
# we should handle it.
|
22
|
-
if @points.size == 1
|
23
|
-
raise Error::InvalidGeometry, "LineString Cannot Have 1 Point"
|
24
|
-
end
|
22
|
+
raise Error::InvalidGeometry, "LineString Cannot Have 1 Point" if @points.size == 1
|
25
23
|
init_geometry
|
26
24
|
end
|
27
25
|
|
@@ -29,8 +27,8 @@ module RGeo
|
|
29
27
|
@points.size
|
30
28
|
end
|
31
29
|
|
32
|
-
def point_n(
|
33
|
-
|
30
|
+
def point_n(idx)
|
31
|
+
idx < 0 ? nil : @points[idx]
|
34
32
|
end
|
35
33
|
|
36
34
|
def points
|
@@ -49,11 +47,6 @@ module RGeo
|
|
49
47
|
@points.size == 0
|
50
48
|
end
|
51
49
|
|
52
|
-
def is_empty?
|
53
|
-
warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
54
|
-
empty?
|
55
|
-
end
|
56
|
-
|
57
50
|
def boundary
|
58
51
|
array = []
|
59
52
|
array << @points.first << @points.last if !empty? && !closed?
|
@@ -69,26 +62,15 @@ module RGeo
|
|
69
62
|
end
|
70
63
|
|
71
64
|
def closed?
|
72
|
-
|
73
|
-
@closed = @points.size > 2 && @points.first == @points.last
|
74
|
-
end
|
75
|
-
@closed
|
76
|
-
end
|
65
|
+
return @closed if defined?(@closed)
|
77
66
|
|
78
|
-
|
79
|
-
warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
80
|
-
closed?
|
67
|
+
@closed = @points.size > 2 && @points.first == @points.last
|
81
68
|
end
|
82
69
|
|
83
70
|
def ring?
|
84
71
|
closed? && simple?
|
85
72
|
end
|
86
73
|
|
87
|
-
def is_ring?
|
88
|
-
warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
89
|
-
ring?
|
90
|
-
end
|
91
|
-
|
92
74
|
def rep_equals?(rhs)
|
93
75
|
if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @points.size == rhs.num_points
|
94
76
|
rhs.points.each_with_index { |p, i| return false unless @points[i].rep_equals?(p) }
|
@@ -98,10 +80,7 @@ module RGeo
|
|
98
80
|
end
|
99
81
|
|
100
82
|
def hash
|
101
|
-
@hash ||=
|
102
|
-
hash = [factory, geometry_type].hash
|
103
|
-
@points.inject(hash) { |h, p| (1_664_525 * h + p.hash).hash }
|
104
|
-
end
|
83
|
+
@hash ||= [factory, geometry_type, *@points].hash
|
105
84
|
end
|
106
85
|
|
107
86
|
def coordinates
|
@@ -129,15 +108,15 @@ module RGeo
|
|
129
108
|
def point_intersect_segment?(point, start_point, end_point)
|
130
109
|
return false unless point_collinear?(point, start_point, end_point)
|
131
110
|
|
132
|
-
if start_point.x
|
133
|
-
between_coordinate?(point.x, start_point.x, end_point.x)
|
134
|
-
else
|
111
|
+
if start_point.x == end_point.x
|
135
112
|
between_coordinate?(point.y, start_point.y, end_point.y)
|
113
|
+
else
|
114
|
+
between_coordinate?(point.x, start_point.x, end_point.x)
|
136
115
|
end
|
137
116
|
end
|
138
117
|
|
139
|
-
def point_collinear?(
|
140
|
-
(
|
118
|
+
def point_collinear?(pt1, pt2, pt3)
|
119
|
+
(pt2.x - pt1.x) * (pt3.y - pt1.y) == (pt3.x - pt1.x) * (pt2.y - pt1.y)
|
141
120
|
end
|
142
121
|
|
143
122
|
def between_coordinate?(coord, start_coord, end_coord)
|
@@ -155,9 +134,7 @@ module RGeo
|
|
155
134
|
def initialize(factory, start, stop)
|
156
135
|
self.factory = factory
|
157
136
|
cstart = Feature.cast(start, factory, Feature::Point)
|
158
|
-
unless cstart
|
159
|
-
raise Error::InvalidGeometry, "Could not cast start: #{start}"
|
160
|
-
end
|
137
|
+
raise Error::InvalidGeometry, "Could not cast start: #{start}" unless cstart
|
161
138
|
cstop = Feature.cast(stop, factory, Feature::Point)
|
162
139
|
raise Error::InvalidGeometry, "Could not cast end: #{stop}" unless cstop
|
163
140
|
@points = [cstart, cstop]
|
@@ -176,9 +153,7 @@ module RGeo
|
|
176
153
|
module BasicLinearRingMethods # :nodoc:
|
177
154
|
def initialize(factory, points)
|
178
155
|
super
|
179
|
-
|
180
|
-
raise Error::InvalidGeometry, "LinearRings must have 0 or >= 4 points"
|
181
|
-
end
|
156
|
+
raise Error::InvalidGeometry, "LinearRings must have 0 or >= 4 points" if @points.size.between?(1, 3)
|
182
157
|
end
|
183
158
|
|
184
159
|
def geometry_type
|
@@ -194,10 +169,11 @@ module RGeo
|
|
194
169
|
# Close ring if necessary.
|
195
170
|
def init_geometry
|
196
171
|
super
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
172
|
+
|
173
|
+
return if @points.empty?
|
174
|
+
|
175
|
+
@points << @points.first if @points.first != @points.last
|
176
|
+
@points = @points.chunk { |x| x }.map(&:first)
|
201
177
|
end
|
202
178
|
end
|
203
179
|
end
|
@@ -15,9 +15,7 @@ module RGeo
|
|
15
15
|
@y = y.to_f
|
16
16
|
@z = factory.property(:has_z_coordinate) ? extra.shift.to_f : nil
|
17
17
|
@m = factory.property(:has_m_coordinate) ? extra.shift.to_f : nil
|
18
|
-
|
19
|
-
raise ArgumentError, "Too many arguments for point initializer"
|
20
|
-
end
|
18
|
+
raise ArgumentError, "Too many arguments for point initializer" unless extra.empty?
|
21
19
|
init_geometry
|
22
20
|
end
|
23
21
|
|
@@ -49,20 +47,10 @@ module RGeo
|
|
49
47
|
false
|
50
48
|
end
|
51
49
|
|
52
|
-
def is_empty?
|
53
|
-
warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
54
|
-
empty?
|
55
|
-
end
|
56
|
-
|
57
50
|
def simple?
|
58
51
|
true
|
59
52
|
end
|
60
53
|
|
61
|
-
def is_simple?
|
62
|
-
warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
63
|
-
simple?
|
64
|
-
end
|
65
|
-
|
66
54
|
def envelope
|
67
55
|
self
|
68
56
|
end
|
@@ -12,14 +12,10 @@ module RGeo
|
|
12
12
|
def initialize(factory, exterior_ring, interior_rings)
|
13
13
|
self.factory = factory
|
14
14
|
@exterior_ring = Feature.cast(exterior_ring, factory, Feature::LinearRing)
|
15
|
-
unless @exterior_ring
|
16
|
-
raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring}"
|
17
|
-
end
|
15
|
+
raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring}" unless @exterior_ring
|
18
16
|
@interior_rings = (interior_rings || []).map do |elem|
|
19
17
|
elem = Feature.cast(elem, factory, Feature::LinearRing)
|
20
|
-
unless elem
|
21
|
-
raise Error::InvalidGeometry, "Could not cast interior ring #{elem}"
|
22
|
-
end
|
18
|
+
raise Error::InvalidGeometry, "Could not cast interior ring #{elem}" unless elem
|
23
19
|
elem
|
24
20
|
end
|
25
21
|
init_geometry
|
@@ -33,8 +29,8 @@ module RGeo
|
|
33
29
|
@interior_rings.size
|
34
30
|
end
|
35
31
|
|
36
|
-
def interior_ring_n(
|
37
|
-
|
32
|
+
def interior_ring_n(idx)
|
33
|
+
idx < 0 ? nil : @interior_rings[idx]
|
38
34
|
end
|
39
35
|
|
40
36
|
def interior_rings
|
@@ -53,11 +49,6 @@ module RGeo
|
|
53
49
|
@exterior_ring.empty?
|
54
50
|
end
|
55
51
|
|
56
|
-
def is_empty?
|
57
|
-
warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
|
58
|
-
empty?
|
59
|
-
end
|
60
|
-
|
61
52
|
def boundary
|
62
53
|
array = []
|
63
54
|
array << @exterior_ring unless @exterior_ring.empty?
|
@@ -66,18 +57,18 @@ module RGeo
|
|
66
57
|
end
|
67
58
|
|
68
59
|
def rep_equals?(rhs)
|
69
|
-
|
70
|
-
rhs.
|
71
|
-
|
72
|
-
|
73
|
-
|
60
|
+
proper_match = rhs.is_a?(self.class) &&
|
61
|
+
rhs.factory.eql?(@factory) &&
|
62
|
+
@exterior_ring.rep_equals?(rhs.exterior_ring) &&
|
63
|
+
@interior_rings.size == rhs.num_interior_rings
|
64
|
+
|
65
|
+
return false unless proper_match
|
66
|
+
|
67
|
+
rhs.interior_rings.each_with_index { |r, i| return false unless @interior_rings[i].rep_equals?(r) }
|
74
68
|
end
|
75
69
|
|
76
70
|
def hash
|
77
|
-
@hash ||=
|
78
|
-
hash = [geometry_type, @exterior_ring].hash
|
79
|
-
@interior_rings.inject(hash) { |h, r| (1_664_525 * h + r.hash).hash }
|
80
|
-
end
|
71
|
+
@hash ||= [geometry_type, @exterior_ring, *@interior_rings].hash
|
81
72
|
end
|
82
73
|
|
83
74
|
def coordinates
|
@@ -88,7 +79,8 @@ module RGeo
|
|
88
79
|
if Feature::Point === rhs
|
89
80
|
contains_point?(rhs)
|
90
81
|
else
|
91
|
-
raise(
|
82
|
+
raise(
|
83
|
+
Error::UnsupportedOperation,
|
92
84
|
"Method Polygon#contains? is only defined for Point"
|
93
85
|
)
|
94
86
|
end
|
@@ -98,7 +90,7 @@ module RGeo
|
|
98
90
|
|
99
91
|
def contains_point?(point)
|
100
92
|
ring_encloses_point?(@exterior_ring, point) &&
|
101
|
-
|
93
|
+
@interior_rings.none? do |exclusion|
|
102
94
|
ring_encloses_point?(exclusion, point, on_border_return: true)
|
103
95
|
end
|
104
96
|
end
|
@@ -122,7 +114,6 @@ module RGeo
|
|
122
114
|
encloses_point
|
123
115
|
end
|
124
116
|
|
125
|
-
|
126
117
|
def copy_state_from(obj)
|
127
118
|
super
|
128
119
|
@exterior_ring = obj.exterior_ring
|