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
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# GEOS implementation additions written in Ruby
|
@@ -9,72 +11,52 @@ module RGeo
|
|
9
11
|
class ZMPointImpl # :nodoc:
|
10
12
|
include ZMGeometryMethods
|
11
13
|
include ZMPointMethods
|
12
|
-
|
13
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
|
14
14
|
end
|
15
15
|
|
16
16
|
class ZMLineStringImpl # :nodoc:
|
17
17
|
include ZMGeometryMethods
|
18
18
|
include ZMLineStringMethods
|
19
|
-
|
20
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
|
21
19
|
end
|
22
20
|
|
23
21
|
class ZMLinearRingImpl # :nodoc:
|
24
22
|
include ZMGeometryMethods
|
25
23
|
include ZMLineStringMethods
|
26
|
-
|
27
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
|
28
24
|
end
|
29
25
|
|
30
26
|
class ZMLineImpl # :nodoc:
|
31
27
|
include ZMGeometryMethods
|
32
28
|
include ZMLineStringMethods
|
33
|
-
|
34
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
|
35
29
|
end
|
36
30
|
|
37
31
|
class ZMPolygonImpl # :nodoc:
|
38
32
|
include ZMGeometryMethods
|
39
33
|
include ZMPolygonMethods
|
40
|
-
|
41
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
|
42
34
|
end
|
43
35
|
|
44
36
|
class ZMGeometryCollectionImpl # :nodoc:
|
45
37
|
include ZMGeometryMethods
|
46
38
|
include ZMGeometryCollectionMethods
|
47
|
-
|
48
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
|
49
39
|
end
|
50
40
|
|
51
41
|
class ZMMultiPointImpl # :nodoc:
|
52
42
|
include ZMGeometryMethods
|
53
43
|
include ZMGeometryCollectionMethods
|
54
|
-
|
55
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
|
56
44
|
end
|
57
45
|
|
58
46
|
class ZMMultiLineStringImpl # :nodoc:
|
59
47
|
include ZMGeometryMethods
|
60
48
|
include ZMGeometryCollectionMethods
|
61
49
|
include ZMMultiLineStringMethods
|
62
|
-
|
63
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
|
64
50
|
end
|
65
51
|
|
66
52
|
class ZMMultiPolygonImpl # :nodoc:
|
67
53
|
include ZMGeometryMethods
|
68
54
|
include ZMGeometryCollectionMethods
|
69
55
|
include ZMMultiPolygonMethods
|
70
|
-
|
71
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
|
72
56
|
end
|
73
57
|
|
74
58
|
class ZMGeometryImpl # :nodoc:
|
75
59
|
include ZMGeometryMethods
|
76
|
-
|
77
|
-
Feature::MixinCollection::GLOBAL.for_type(Feature::Geometry).include_in_class(self, true)
|
78
60
|
end
|
79
61
|
end
|
80
62
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# GEOS implementation additions written in Ruby
|
@@ -9,10 +11,10 @@ module RGeo
|
|
9
11
|
module ZMGeometryMethods # :nodoc:
|
10
12
|
include Feature::Instance
|
11
13
|
|
12
|
-
def initialize(
|
13
|
-
@factory =
|
14
|
-
@zgeometry =
|
15
|
-
@mgeometry =
|
14
|
+
def initialize(factory, zgeometry, mgeometry)
|
15
|
+
@factory = factory
|
16
|
+
@zgeometry = zgeometry
|
17
|
+
@mgeometry = mgeometry
|
16
18
|
end
|
17
19
|
|
18
20
|
def inspect # :nodoc:
|
@@ -52,7 +54,7 @@ module RGeo
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def envelope
|
55
|
-
@factory.
|
57
|
+
@factory.create_feature(nil, @zgeometry.envelope, @mgeometry.envelope)
|
56
58
|
end
|
57
59
|
|
58
60
|
def as_text
|
@@ -72,81 +74,81 @@ module RGeo
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def boundary
|
75
|
-
@factory.
|
77
|
+
@factory.create_feature(nil, @zgeometry.boundary, @mgeometry.boundary)
|
76
78
|
end
|
77
79
|
|
78
|
-
def equals?(
|
79
|
-
@zgeometry.equals?(RGeo::Feature.cast(
|
80
|
+
def equals?(rhs)
|
81
|
+
@zgeometry.equals?(RGeo::Feature.cast(rhs, self).z_geometry)
|
80
82
|
end
|
81
83
|
|
82
|
-
def disjoint?(
|
83
|
-
@zgeometry.disjoint?(RGeo::Feature.cast(
|
84
|
+
def disjoint?(rhs)
|
85
|
+
@zgeometry.disjoint?(RGeo::Feature.cast(rhs, self).z_geometry)
|
84
86
|
end
|
85
87
|
|
86
|
-
def intersects?(
|
87
|
-
@zgeometry.intersects?(RGeo::Feature.cast(
|
88
|
+
def intersects?(rhs)
|
89
|
+
@zgeometry.intersects?(RGeo::Feature.cast(rhs, self).z_geometry)
|
88
90
|
end
|
89
91
|
|
90
|
-
def touches?(
|
91
|
-
@zgeometry.touches?(RGeo::Feature.cast(
|
92
|
+
def touches?(rhs)
|
93
|
+
@zgeometry.touches?(RGeo::Feature.cast(rhs, self).z_geometry)
|
92
94
|
end
|
93
95
|
|
94
|
-
def crosses?(
|
95
|
-
@zgeometry.crosses?(RGeo::Feature.cast(
|
96
|
+
def crosses?(rhs)
|
97
|
+
@zgeometry.crosses?(RGeo::Feature.cast(rhs, self).z_geometry)
|
96
98
|
end
|
97
99
|
|
98
|
-
def within?(
|
99
|
-
@zgeometry.within?(RGeo::Feature.cast(
|
100
|
+
def within?(rhs)
|
101
|
+
@zgeometry.within?(RGeo::Feature.cast(rhs, self).z_geometry)
|
100
102
|
end
|
101
103
|
|
102
|
-
def contains?(
|
103
|
-
@zgeometry.contains?(RGeo::Feature.cast(
|
104
|
+
def contains?(rhs)
|
105
|
+
@zgeometry.contains?(RGeo::Feature.cast(rhs, self).z_geometry)
|
104
106
|
end
|
105
107
|
|
106
|
-
def overlaps?(
|
107
|
-
@zgeometry.overlaps?(RGeo::Feature.cast(
|
108
|
+
def overlaps?(rhs)
|
109
|
+
@zgeometry.overlaps?(RGeo::Feature.cast(rhs, self).z_geometry)
|
108
110
|
end
|
109
111
|
|
110
|
-
def relate?(
|
111
|
-
@zgeometry.relate?(RGeo::Feature.cast(
|
112
|
+
def relate?(rhs, pattern)
|
113
|
+
@zgeometry.relate?(RGeo::Feature.cast(rhs, self).z_geometry, pattern)
|
112
114
|
end
|
113
115
|
alias relate relate? # DEPRECATED
|
114
116
|
|
115
|
-
def distance(
|
116
|
-
@zgeometry.distance(RGeo::Feature.cast(
|
117
|
+
def distance(rhs)
|
118
|
+
@zgeometry.distance(RGeo::Feature.cast(rhs, self).z_geometry)
|
117
119
|
end
|
118
120
|
|
119
121
|
def buffer(distance_)
|
120
|
-
@factory.
|
122
|
+
@factory.create_feature(nil, @zgeometry.buffer(distance_), @mgeometry.buffer(distance_))
|
121
123
|
end
|
122
124
|
|
123
125
|
def convex_hull
|
124
|
-
@factory.
|
126
|
+
@factory.create_feature(nil, @zgeometry.convex_hull, @mgeometry.convex_hull)
|
125
127
|
end
|
126
128
|
|
127
|
-
def intersection(
|
128
|
-
|
129
|
-
@factory.
|
129
|
+
def intersection(rhs)
|
130
|
+
rhs = RGeo::Feature.cast(rhs, self)
|
131
|
+
@factory.create_feature(nil, @zgeometry.intersection(rhs.z_geometry), @mgeometry.intersection(rhs.m_geometry))
|
130
132
|
end
|
131
133
|
|
132
|
-
def union(
|
133
|
-
|
134
|
-
@factory.
|
134
|
+
def union(rhs)
|
135
|
+
rhs = RGeo::Feature.cast(rhs, self)
|
136
|
+
@factory.create_feature(nil, @zgeometry.union(rhs.z_geometry), @mgeometry.union(rhs.m_geometry))
|
135
137
|
end
|
136
138
|
|
137
|
-
def difference(
|
138
|
-
|
139
|
-
@factory.
|
139
|
+
def difference(rhs)
|
140
|
+
rhs = RGeo::Feature.cast(rhs, self)
|
141
|
+
@factory.create_feature(nil, @zgeometry.difference(rhs.z_geometry), @mgeometry.difference(rhs.m_geometry))
|
140
142
|
end
|
141
143
|
|
142
|
-
def sym_difference(
|
143
|
-
|
144
|
-
@factory.
|
144
|
+
def sym_difference(rhs)
|
145
|
+
rhs = RGeo::Feature.cast(rhs, self)
|
146
|
+
@factory.create_feature(nil, @zgeometry.sym_difference(rhs.z_geometry), @mgeometry.sym_difference(rhs.m_geometry))
|
145
147
|
end
|
146
148
|
|
147
|
-
def rep_equals?(
|
148
|
-
|
149
|
-
|
149
|
+
def rep_equals?(rhs)
|
150
|
+
rhs = RGeo::Feature.cast(rhs, self)
|
151
|
+
rhs.is_a?(self.class) && @factory.eql?(rhs.factory) && @zgeometry.rep_equals?(rhs.z_geometry) && @mgeometry.rep_equals?(rhs.m_geometry)
|
150
152
|
end
|
151
153
|
|
152
154
|
alias eql? rep_equals?
|
@@ -156,27 +158,29 @@ module RGeo
|
|
156
158
|
alias + union
|
157
159
|
alias * intersection
|
158
160
|
|
159
|
-
def
|
160
|
-
@factory
|
161
|
-
@zgeometry = obj_.z_geometry
|
162
|
-
@mgeometry = obj_.m_geometry
|
161
|
+
def marshal_dump # :nodoc:
|
162
|
+
[@factory, @factory.marshal_wkb_generator.generate(self)]
|
163
163
|
end
|
164
164
|
|
165
|
-
def
|
166
|
-
[
|
165
|
+
def marshal_load(data) # :nodoc:
|
166
|
+
copy_state_from(data[0].marshal_wkb_parser.parse(data[1]))
|
167
167
|
end
|
168
168
|
|
169
|
-
def
|
170
|
-
|
169
|
+
def encode_with(coder) # :nodoc:
|
170
|
+
coder["factory"] = @factory
|
171
|
+
coder["wkt"] = @factory.psych_wkt_generator.generate(self)
|
171
172
|
end
|
172
173
|
|
173
|
-
def
|
174
|
-
|
175
|
-
coder_["wkt"] = @factory._psych_wkt_generator.generate(self)
|
174
|
+
def init_with(coder) # :nodoc:
|
175
|
+
copy_state_from(coder["factory"].psych_wkt_parser.parse(coder["wkt"]))
|
176
176
|
end
|
177
177
|
|
178
|
-
|
179
|
-
|
178
|
+
private
|
179
|
+
|
180
|
+
def copy_state_from(obj)
|
181
|
+
@factory = obj.factory
|
182
|
+
@zgeometry = obj.z_geometry
|
183
|
+
@mgeometry = obj.m_geometry
|
180
184
|
end
|
181
185
|
end
|
182
186
|
|
@@ -230,8 +234,8 @@ module RGeo
|
|
230
234
|
@zgeometry.num_points
|
231
235
|
end
|
232
236
|
|
233
|
-
def point_n(
|
234
|
-
@factory.
|
237
|
+
def point_n(n)
|
238
|
+
@factory.create_feature(ZMPointImpl, @zgeometry.point_n(n), @mgeometry.point_n(n))
|
235
239
|
end
|
236
240
|
|
237
241
|
def points
|
@@ -239,7 +243,7 @@ module RGeo
|
|
239
243
|
zpoints_ = @zgeometry.points
|
240
244
|
mpoints_ = @mgeometry.points
|
241
245
|
zpoints_.size.times do |i_|
|
242
|
-
result_ << @factory.
|
246
|
+
result_ << @factory.create_feature(ZMPointImpl, zpoints_[i_], mpoints_[i_])
|
243
247
|
end
|
244
248
|
result_
|
245
249
|
end
|
@@ -255,23 +259,23 @@ module RGeo
|
|
255
259
|
end
|
256
260
|
|
257
261
|
def centroid
|
258
|
-
@factory.
|
262
|
+
@factory.create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
259
263
|
end
|
260
264
|
|
261
265
|
def point_on_surface
|
262
|
-
@factory.
|
266
|
+
@factory.create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
263
267
|
end
|
264
268
|
|
265
269
|
def exterior_ring
|
266
|
-
@factory.
|
270
|
+
@factory.create_feature(ZMLineStringImpl, @zgeometry.exterior_ring, @mgeometry.exterior_ring)
|
267
271
|
end
|
268
272
|
|
269
273
|
def num_interior_rings
|
270
274
|
@zgeometry.num_interior_rings
|
271
275
|
end
|
272
276
|
|
273
|
-
def interior_ring_n(
|
274
|
-
@factory.
|
277
|
+
def interior_ring_n(n)
|
278
|
+
@factory.create_feature(ZMLineStringImpl, @zgeometry.interior_ring_n(n), @mgeometry.interior_ring_n(n))
|
275
279
|
end
|
276
280
|
|
277
281
|
def interior_rings
|
@@ -279,7 +283,7 @@ module RGeo
|
|
279
283
|
zrings_ = @zgeometry.interior_rings
|
280
284
|
mrings_ = @mgeometry.interior_rings
|
281
285
|
zrings_.size.times do |i_|
|
282
|
-
result_ << @factory.
|
286
|
+
result_ << @factory.create_feature(ZMLineStringImpl, zrings_[i_], mrings_[i_])
|
283
287
|
end
|
284
288
|
result_
|
285
289
|
end
|
@@ -295,15 +299,15 @@ module RGeo
|
|
295
299
|
end
|
296
300
|
alias size num_geometries
|
297
301
|
|
298
|
-
def geometry_n(
|
299
|
-
@factory.
|
302
|
+
def geometry_n(n)
|
303
|
+
@factory.create_feature(nil, @zgeometry.geometry_n(n), @mgeometry.geometry_n(n))
|
300
304
|
end
|
301
305
|
alias [] geometry_n
|
302
306
|
|
303
307
|
def each
|
304
308
|
if block_given?
|
305
|
-
num_geometries.times do |
|
306
|
-
yield geometry_n(
|
309
|
+
num_geometries.times do |i|
|
310
|
+
yield geometry_n(i)
|
307
311
|
end
|
308
312
|
self
|
309
313
|
else
|
@@ -311,7 +315,7 @@ module RGeo
|
|
311
315
|
end
|
312
316
|
end
|
313
317
|
|
314
|
-
include
|
318
|
+
include Enumerable
|
315
319
|
end
|
316
320
|
|
317
321
|
module ZMMultiLineStringMethods # :nodoc:
|
@@ -334,11 +338,11 @@ module RGeo
|
|
334
338
|
end
|
335
339
|
|
336
340
|
def centroid
|
337
|
-
@factory.
|
341
|
+
@factory.create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
338
342
|
end
|
339
343
|
|
340
344
|
def point_on_surface
|
341
|
-
@factory.
|
345
|
+
@factory.create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
342
346
|
end
|
343
347
|
|
344
348
|
def coordinates
|
data/lib/rgeo/impl_helper.rb
CHANGED
@@ -1,19 +1,9 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Implementation helpers namespace for RGeo
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
require "rgeo/impl_helper/math"
|
15
|
-
require "rgeo/impl_helper/basic_geometry_methods"
|
16
|
-
require "rgeo/impl_helper/basic_geometry_collection_methods"
|
17
|
-
require "rgeo/impl_helper/basic_point_methods"
|
18
|
-
require "rgeo/impl_helper/basic_line_string_methods"
|
19
|
-
require "rgeo/impl_helper/basic_polygon_methods"
|
3
|
+
require_relative "impl_helper/utils"
|
4
|
+
require_relative "impl_helper/math"
|
5
|
+
require_relative "impl_helper/basic_geometry_methods"
|
6
|
+
require_relative "impl_helper/basic_geometry_collection_methods"
|
7
|
+
require_relative "impl_helper/basic_point_methods"
|
8
|
+
require_relative "impl_helper/basic_line_string_methods"
|
9
|
+
require_relative "impl_helper/basic_polygon_methods"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -----------------------------------------------------------------------------
|
2
4
|
#
|
3
5
|
# Common methods for GeometryCollection features
|
@@ -7,41 +9,36 @@
|
|
7
9
|
module RGeo
|
8
10
|
module ImplHelper # :nodoc:
|
9
11
|
module BasicGeometryCollectionMethods # :nodoc:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
attr_reader :elements
|
13
|
+
|
14
|
+
def initialize(factory, elements)
|
15
|
+
self.factory = factory
|
16
|
+
@elements = elements.map do |elem|
|
17
|
+
elem = Feature.cast(elem, factory)
|
18
|
+
raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
|
19
|
+
elem
|
16
20
|
end
|
17
|
-
|
21
|
+
validate_geometry
|
18
22
|
end
|
19
23
|
|
20
24
|
def num_geometries
|
21
25
|
@elements.size
|
22
26
|
end
|
23
27
|
|
24
|
-
def geometry_n(
|
25
|
-
|
28
|
+
def geometry_n(n)
|
29
|
+
n < 0 ? nil : @elements[n]
|
26
30
|
end
|
27
31
|
|
28
|
-
def [](
|
29
|
-
@elements[
|
32
|
+
def [](n)
|
33
|
+
@elements[n]
|
30
34
|
end
|
31
35
|
|
32
|
-
def each(&
|
33
|
-
@elements.each(&
|
36
|
+
def each(&block)
|
37
|
+
@elements.each(&block)
|
34
38
|
end
|
35
39
|
|
36
40
|
def dimension
|
37
|
-
|
38
|
-
@dimension = -1
|
39
|
-
@elements.each do |elem_|
|
40
|
-
dim_ = elem_.dimension
|
41
|
-
@dimension = dim_ if @dimension < dim_
|
42
|
-
end
|
43
|
-
end
|
44
|
-
@dimension
|
41
|
+
@dimension ||= @elements.map(&:dimension).max || -1
|
45
42
|
end
|
46
43
|
|
47
44
|
def geometry_type
|
@@ -52,9 +49,9 @@ module RGeo
|
|
52
49
|
@elements.size == 0
|
53
50
|
end
|
54
51
|
|
55
|
-
def rep_equals?(
|
56
|
-
if
|
57
|
-
|
52
|
+
def rep_equals?(rhs)
|
53
|
+
if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @elements.size == rhs.num_geometries
|
54
|
+
rhs.each_with_index { |p, i| return false unless @elements[i].rep_equals?(p) }
|
58
55
|
else
|
59
56
|
false
|
60
57
|
end
|
@@ -62,30 +59,28 @@ module RGeo
|
|
62
59
|
|
63
60
|
def hash
|
64
61
|
@hash ||= begin
|
65
|
-
|
66
|
-
@elements.inject(
|
62
|
+
hash = [factory, geometry_type].hash
|
63
|
+
@elements.inject(hash) { |h, g| (1_664_525 * h + g.hash).hash }
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
70
|
-
|
71
|
-
super
|
72
|
-
@elements = obj_._elements
|
73
|
-
end
|
67
|
+
private
|
74
68
|
|
75
|
-
def
|
76
|
-
|
69
|
+
def copy_state_from(obj)
|
70
|
+
super
|
71
|
+
@elements = obj.elements
|
77
72
|
end
|
78
73
|
end
|
79
74
|
|
80
|
-
module BasicMultiLineStringMethods
|
81
|
-
def initialize(
|
82
|
-
|
83
|
-
@elements =
|
84
|
-
|
85
|
-
raise Error::InvalidGeometry, "Could not cast #{
|
86
|
-
|
75
|
+
module BasicMultiLineStringMethods # :nodoc:
|
76
|
+
def initialize(factory, elements)
|
77
|
+
self.factory = factory
|
78
|
+
@elements = elements.map do |elem|
|
79
|
+
elem = Feature.cast(elem, factory, Feature::LineString, :keep_subtype)
|
80
|
+
raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
|
81
|
+
elem
|
87
82
|
end
|
88
|
-
|
83
|
+
validate_geometry
|
89
84
|
end
|
90
85
|
|
91
86
|
def geometry_type
|
@@ -97,43 +92,51 @@ module RGeo
|
|
97
92
|
end
|
98
93
|
|
99
94
|
def length
|
100
|
-
@elements.inject(0.0) { |
|
101
|
-
end
|
102
|
-
|
103
|
-
def _add_boundary(hash_, point_) # :nodoc:
|
104
|
-
hval_ = [point_.x, point_.y].hash
|
105
|
-
(hash_[hval_] ||= [point_, 0])[1] += 1
|
95
|
+
@elements.inject(0.0) { |sum, obj| sum + obj.length }
|
106
96
|
end
|
107
97
|
|
108
98
|
def boundary
|
109
|
-
|
110
|
-
@elements.each do |
|
111
|
-
if !
|
112
|
-
|
113
|
-
|
99
|
+
hash = {}
|
100
|
+
@elements.each do |line|
|
101
|
+
if !line.is_empty? && !line.is_closed?
|
102
|
+
add_boundary(hash, line.start_point)
|
103
|
+
add_boundary(hash, line.end_point)
|
114
104
|
end
|
115
105
|
end
|
116
|
-
|
117
|
-
|
118
|
-
|
106
|
+
array = []
|
107
|
+
hash.each do |_hval, data_|
|
108
|
+
array << data_[0] if data_[1].odd?
|
119
109
|
end
|
120
|
-
factory.
|
110
|
+
factory.multipoint([array])
|
121
111
|
end
|
122
112
|
|
123
113
|
def coordinates
|
124
114
|
@elements.map(&:coordinates)
|
125
115
|
end
|
116
|
+
|
117
|
+
def contains?(rhs)
|
118
|
+
return super unless Feature::Point === rhs
|
119
|
+
|
120
|
+
@elements.any? { |line| line.contains?(rhs) }
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def add_boundary(hash, point)
|
126
|
+
hval = [point.x, point.y].hash
|
127
|
+
(hash[hval] ||= [point, 0])[1] += 1
|
128
|
+
end
|
126
129
|
end
|
127
130
|
|
128
131
|
module BasicMultiPointMethods # :nodoc:
|
129
|
-
def initialize(
|
130
|
-
|
131
|
-
@elements =
|
132
|
-
|
133
|
-
raise Error::InvalidGeometry, "Could not cast #{
|
134
|
-
|
132
|
+
def initialize(factory, elements)
|
133
|
+
self.factory = factory
|
134
|
+
@elements = elements.map do |elem|
|
135
|
+
elem = Feature.cast(elem, factory, Feature::Point, :keep_subtype)
|
136
|
+
raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
|
137
|
+
elem
|
135
138
|
end
|
136
|
-
|
139
|
+
validate_geometry
|
137
140
|
end
|
138
141
|
|
139
142
|
def geometry_type
|
@@ -150,14 +153,14 @@ module RGeo
|
|
150
153
|
end
|
151
154
|
|
152
155
|
module BasicMultiPolygonMethods # :nodoc:
|
153
|
-
def initialize(
|
154
|
-
|
155
|
-
@elements =
|
156
|
-
|
157
|
-
raise Error::InvalidGeometry, "Could not cast #{
|
158
|
-
|
156
|
+
def initialize(factory, elements)
|
157
|
+
self.factory = factory
|
158
|
+
@elements = elements.map do |elem|
|
159
|
+
elem = Feature.cast(elem, factory, Feature::Polygon, :keep_subtype)
|
160
|
+
raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
|
161
|
+
elem
|
159
162
|
end
|
160
|
-
|
163
|
+
validate_geometry
|
161
164
|
end
|
162
165
|
|
163
166
|
def geometry_type
|
@@ -165,21 +168,27 @@ module RGeo
|
|
165
168
|
end
|
166
169
|
|
167
170
|
def area
|
168
|
-
@elements.inject(0.0) { |
|
171
|
+
@elements.inject(0.0) { |sum, obj| sum + obj.area }
|
169
172
|
end
|
170
173
|
|
171
174
|
def boundary
|
172
|
-
|
173
|
-
@elements.each do |
|
174
|
-
|
175
|
-
|
175
|
+
array = []
|
176
|
+
@elements.each do |poly|
|
177
|
+
array << poly.exterior_ring unless poly.is_empty?
|
178
|
+
array.concat(poly.interior_rings)
|
176
179
|
end
|
177
|
-
factory.multi_line_string(
|
180
|
+
factory.multi_line_string(array)
|
178
181
|
end
|
179
182
|
|
180
183
|
def coordinates
|
181
184
|
@elements.map(&:coordinates)
|
182
185
|
end
|
186
|
+
|
187
|
+
def contains?(rhs)
|
188
|
+
return super unless Feature::Point === rhs
|
189
|
+
|
190
|
+
@elements.any? { |poly| poly.contains?(rhs) }
|
191
|
+
end
|
183
192
|
end
|
184
193
|
end
|
185
194
|
end
|