rgeo 0.3.13 → 0.3.14
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +8 -0
- data/README.rdoc +4 -4
- data/Version +1 -1
- data/ext/geos_c_impl/extconf.rb +1 -0
- data/ext/geos_c_impl/factory.c +118 -5
- data/ext/geos_c_impl/factory.h +24 -1
- data/ext/geos_c_impl/geometry.c +42 -53
- data/ext/geos_c_impl/geometry_collection.c +137 -54
- data/ext/geos_c_impl/geometry_collection.h +9 -0
- data/ext/geos_c_impl/line_string.c +88 -45
- data/ext/geos_c_impl/point.c +31 -17
- data/ext/geos_c_impl/polygon.c +50 -22
- data/ext/geos_c_impl/polygon.h +9 -0
- data/ext/geos_c_impl/preface.h +10 -0
- data/lib/rgeo/cartesian/factory.rb +9 -1
- data/lib/rgeo/coord_sys/cs/entities.rb +10 -1
- data/lib/rgeo/coord_sys/proj4.rb +1 -1
- data/lib/rgeo/feature/types.rb +29 -5
- data/lib/rgeo/geographic/factory.rb +5 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +3 -47
- data/lib/rgeo/geographic/projected_feature_methods.rb +69 -0
- data/lib/rgeo/geographic/spherical_feature_classes.rb +1 -74
- data/lib/rgeo/geographic/spherical_feature_methods.rb +84 -0
- data/lib/rgeo/geographic/spherical_math.rb +3 -3
- data/lib/rgeo/geos.rb +17 -9
- data/lib/rgeo/geos/{factory.rb → capi_factory.rb} +36 -15
- data/lib/rgeo/geos/{impl_additions.rb → capi_feature_classes.rb} +127 -16
- data/lib/rgeo/geos/ffi_factory.rb +55 -41
- data/lib/rgeo/geos/ffi_feature_classes.rb +168 -0
- data/lib/rgeo/geos/{ffi_classes.rb → ffi_feature_methods.rb} +56 -57
- data/lib/rgeo/geos/interface.rb +5 -5
- data/lib/rgeo/geos/utils.rb +7 -0
- data/lib/rgeo/geos/zm_factory.rb +40 -12
- data/lib/rgeo/geos/zm_feature_classes.rb +165 -0
- data/lib/rgeo/geos/{zm_impl.rb → zm_feature_methods.rb} +33 -52
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +8 -0
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +8 -0
- data/lib/rgeo/impl_helper/basic_point_methods.rb +5 -0
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +8 -0
- data/test/common/factory_tests.rb +8 -2
- data/test/common/geometry_collection_tests.rb +23 -0
- data/test/common/line_string_tests.rb +25 -0
- data/test/common/multi_line_string_tests.rb +7 -0
- data/test/common/multi_point_tests.rb +7 -0
- data/test/common/multi_polygon_tests.rb +7 -0
- data/test/common/point_tests.rb +21 -0
- data/test/common/polygon_tests.rb +15 -0
- data/test/coord_sys/tc_proj4.rb +8 -1
- data/test/geos_capi/tc_misc.rb +1 -1
- data/test/tc_mixins.rb +1 -1
- metadata +9 -7
@@ -0,0 +1,165 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# GEOS implementation additions written in Ruby
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010-2012 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module RGeo
|
38
|
+
|
39
|
+
module Geos
|
40
|
+
|
41
|
+
|
42
|
+
class ZMPointImpl # :nodoc:
|
43
|
+
|
44
|
+
|
45
|
+
include ZMGeometryMethods
|
46
|
+
include ZMPointMethods
|
47
|
+
|
48
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
class ZMLineStringImpl # :nodoc:
|
55
|
+
|
56
|
+
|
57
|
+
include ZMGeometryMethods
|
58
|
+
include ZMLineStringMethods
|
59
|
+
|
60
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
class ZMLinearRingImpl # :nodoc:
|
67
|
+
|
68
|
+
|
69
|
+
include ZMGeometryMethods
|
70
|
+
include ZMLineStringMethods
|
71
|
+
|
72
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
class ZMLineImpl # :nodoc:
|
79
|
+
|
80
|
+
|
81
|
+
include ZMGeometryMethods
|
82
|
+
include ZMLineStringMethods
|
83
|
+
|
84
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
|
85
|
+
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
class ZMPolygonImpl # :nodoc:
|
91
|
+
|
92
|
+
|
93
|
+
include ZMGeometryMethods
|
94
|
+
include ZMPolygonMethods
|
95
|
+
|
96
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
class ZMGeometryCollectionImpl # :nodoc:
|
103
|
+
|
104
|
+
|
105
|
+
include ZMGeometryMethods
|
106
|
+
include ZMGeometryCollectionMethods
|
107
|
+
|
108
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
|
109
|
+
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
class ZMMultiPointImpl # :nodoc:
|
115
|
+
|
116
|
+
|
117
|
+
include ZMGeometryMethods
|
118
|
+
include ZMGeometryCollectionMethods
|
119
|
+
|
120
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
|
121
|
+
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
class ZMMultiLineStringImpl # :nodoc:
|
127
|
+
|
128
|
+
|
129
|
+
include ZMGeometryMethods
|
130
|
+
include ZMGeometryCollectionMethods
|
131
|
+
include ZMMultiLineStringMethods
|
132
|
+
|
133
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
|
134
|
+
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
class ZMMultiPolygonImpl # :nodoc:
|
140
|
+
|
141
|
+
|
142
|
+
include ZMGeometryMethods
|
143
|
+
include ZMGeometryCollectionMethods
|
144
|
+
include ZMMultiPolygonMethods
|
145
|
+
|
146
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
|
147
|
+
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
class ZMGeometryImpl # :nodoc:
|
153
|
+
|
154
|
+
|
155
|
+
include ZMGeometryMethods
|
156
|
+
|
157
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Geometry).include_in_class(self, true)
|
158
|
+
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
@@ -39,7 +39,7 @@ module RGeo
|
|
39
39
|
module Geos
|
40
40
|
|
41
41
|
|
42
|
-
|
42
|
+
module ZMGeometryMethods # :nodoc:
|
43
43
|
|
44
44
|
include Feature::Instance
|
45
45
|
|
@@ -60,6 +60,11 @@ module RGeo
|
|
60
60
|
end
|
61
61
|
|
62
62
|
|
63
|
+
def hash
|
64
|
+
@factory.hash ^ @zgeometry.hash ^ @mgeometry.hash
|
65
|
+
end
|
66
|
+
|
67
|
+
|
63
68
|
def factory
|
64
69
|
@factory
|
65
70
|
end
|
@@ -91,7 +96,7 @@ module RGeo
|
|
91
96
|
|
92
97
|
|
93
98
|
def envelope
|
94
|
-
|
99
|
+
@factory._create_feature(nil, @zgeometry.envelope, @mgeometry.envelope)
|
95
100
|
end
|
96
101
|
|
97
102
|
|
@@ -116,7 +121,7 @@ module RGeo
|
|
116
121
|
|
117
122
|
|
118
123
|
def boundary
|
119
|
-
|
124
|
+
@factory._create_feature(nil, @zgeometry.boundary, @mgeometry.boundary)
|
120
125
|
end
|
121
126
|
|
122
127
|
|
@@ -172,36 +177,36 @@ module RGeo
|
|
172
177
|
|
173
178
|
|
174
179
|
def buffer(distance_)
|
175
|
-
|
180
|
+
@factory._create_feature(nil, @zgeometry.buffer(distance_), @mgeometry.buffer(distance_))
|
176
181
|
end
|
177
182
|
|
178
183
|
|
179
184
|
def convex_hull
|
180
|
-
|
185
|
+
@factory._create_feature(nil, @zgeometry.convex_hull, @mgeometry.convex_hull)
|
181
186
|
end
|
182
187
|
|
183
188
|
|
184
189
|
def intersection(rhs_)
|
185
190
|
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
186
|
-
|
191
|
+
@factory._create_feature(nil, @zgeometry.intersection(rhs_.z_geometry), @mgeometry.intersection(rhs_.m_geometry))
|
187
192
|
end
|
188
193
|
|
189
194
|
|
190
195
|
def union(rhs_)
|
191
196
|
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
192
|
-
|
197
|
+
@factory._create_feature(nil, @zgeometry.union(rhs_.z_geometry), @mgeometry.union(rhs_.m_geometry))
|
193
198
|
end
|
194
199
|
|
195
200
|
|
196
201
|
def difference(rhs_)
|
197
202
|
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
198
|
-
|
203
|
+
@factory._create_feature(nil, @zgeometry.difference(rhs_.z_geometry), @mgeometry.difference(rhs_.m_geometry))
|
199
204
|
end
|
200
205
|
|
201
206
|
|
202
207
|
def sym_difference(rhs_)
|
203
208
|
rhs_ = ::RGeo::Feature.cast(rhs_, self)
|
204
|
-
|
209
|
+
@factory._create_feature(nil, @zgeometry.sym_difference(rhs_.z_geometry), @mgeometry.sym_difference(rhs_.m_geometry))
|
205
210
|
end
|
206
211
|
|
207
212
|
|
@@ -247,7 +252,7 @@ module RGeo
|
|
247
252
|
end
|
248
253
|
|
249
254
|
|
250
|
-
|
255
|
+
module ZMPointMethods # :nodoc:
|
251
256
|
|
252
257
|
|
253
258
|
def x
|
@@ -273,7 +278,7 @@ module RGeo
|
|
273
278
|
end
|
274
279
|
|
275
280
|
|
276
|
-
|
281
|
+
module ZMLineStringMethods # :nodoc:
|
277
282
|
|
278
283
|
|
279
284
|
def length
|
@@ -307,7 +312,7 @@ module RGeo
|
|
307
312
|
|
308
313
|
|
309
314
|
def point_n(n_)
|
310
|
-
|
315
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.point_n(n_), @mgeometry.point_n(n_))
|
311
316
|
end
|
312
317
|
|
313
318
|
|
@@ -316,7 +321,7 @@ module RGeo
|
|
316
321
|
zpoints_ = @zgeometry.points
|
317
322
|
mpoints_ = @mgeometry.points
|
318
323
|
zpoints_.size.times do |i_|
|
319
|
-
result_ <<
|
324
|
+
result_ << @factory._create_feature(ZMPointImpl, zpoints_[i_], mpoints_[i_])
|
320
325
|
end
|
321
326
|
result_
|
322
327
|
end
|
@@ -325,7 +330,7 @@ module RGeo
|
|
325
330
|
end
|
326
331
|
|
327
332
|
|
328
|
-
|
333
|
+
module ZMPolygonMethods # :nodoc:
|
329
334
|
|
330
335
|
|
331
336
|
def area
|
@@ -334,17 +339,17 @@ module RGeo
|
|
334
339
|
|
335
340
|
|
336
341
|
def centroid
|
337
|
-
|
342
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
338
343
|
end
|
339
344
|
|
340
345
|
|
341
346
|
def point_on_surface
|
342
|
-
|
347
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
343
348
|
end
|
344
349
|
|
345
350
|
|
346
351
|
def exterior_ring
|
347
|
-
|
352
|
+
@factory._create_feature(ZMLineStringImpl, @zgeometry.exterior_ring, @mgeometry.exterior_ring)
|
348
353
|
end
|
349
354
|
|
350
355
|
|
@@ -354,7 +359,7 @@ module RGeo
|
|
354
359
|
|
355
360
|
|
356
361
|
def interior_ring_n(n_)
|
357
|
-
|
362
|
+
@factory._create_feature(ZMLineStringImpl, @zgeometry.interior_ring_n(n_), @mgeometry.interior_ring_n(n_))
|
358
363
|
end
|
359
364
|
|
360
365
|
|
@@ -363,7 +368,7 @@ module RGeo
|
|
363
368
|
zrings_ = @zgeometry.interior_rings
|
364
369
|
mrings_ = @mgeometry.interior_rings
|
365
370
|
zrings_.size.times do |i_|
|
366
|
-
result_ <<
|
371
|
+
result_ << @factory._create_feature(ZMLineStringImpl, zrings_[i_], mrings_[i_])
|
367
372
|
end
|
368
373
|
result_
|
369
374
|
end
|
@@ -372,10 +377,7 @@ module RGeo
|
|
372
377
|
end
|
373
378
|
|
374
379
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
include ::Enumerable
|
380
|
+
module ZMGeometryCollectionMethods # :nodoc:
|
379
381
|
|
380
382
|
|
381
383
|
def num_geometries
|
@@ -385,7 +387,7 @@ module RGeo
|
|
385
387
|
|
386
388
|
|
387
389
|
def geometry_n(n_)
|
388
|
-
|
390
|
+
@factory._create_feature(nil, @zgeometry.geometry_n(n_), @mgeometry.geometry_n(n_))
|
389
391
|
end
|
390
392
|
alias_method :[], :geometry_n
|
391
393
|
|
@@ -397,10 +399,13 @@ module RGeo
|
|
397
399
|
end
|
398
400
|
|
399
401
|
|
402
|
+
include ::Enumerable
|
403
|
+
|
404
|
+
|
400
405
|
end
|
401
406
|
|
402
407
|
|
403
|
-
|
408
|
+
module ZMMultiLineStringMethods # :nodoc:
|
404
409
|
|
405
410
|
|
406
411
|
def length
|
@@ -416,7 +421,7 @@ module RGeo
|
|
416
421
|
end
|
417
422
|
|
418
423
|
|
419
|
-
|
424
|
+
module ZMMultiPolygonMethods # :nodoc:
|
420
425
|
|
421
426
|
|
422
427
|
def area
|
@@ -425,36 +430,12 @@ module RGeo
|
|
425
430
|
|
426
431
|
|
427
432
|
def centroid
|
428
|
-
|
433
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
429
434
|
end
|
430
435
|
|
431
436
|
|
432
437
|
def point_on_surface
|
433
|
-
|
434
|
-
end
|
435
|
-
|
436
|
-
|
437
|
-
end
|
438
|
-
|
439
|
-
|
440
|
-
class ZMGeometryImpl # :nodoc:
|
441
|
-
|
442
|
-
TYPE_KLASSES = {
|
443
|
-
Feature::Point => ZMPointImpl,
|
444
|
-
Feature::LineString => ZMLineStringImpl,
|
445
|
-
Feature::Line => ZMLineStringImpl,
|
446
|
-
Feature::LinearRing => ZMLineStringImpl,
|
447
|
-
Feature::Polygon => ZMPolygonImpl,
|
448
|
-
Feature::GeometryCollection => ZMGeometryCollectionImpl,
|
449
|
-
Feature::MultiPoint => ZMGeometryCollectionImpl,
|
450
|
-
Feature::MultiLineString => ZMMultiLineStringImpl,
|
451
|
-
Feature::MultiPolygon => ZMMultiPolygonImpl,
|
452
|
-
}.freeze
|
453
|
-
|
454
|
-
|
455
|
-
def self.create(factory_, zgeometry_, mgeometry_)
|
456
|
-
klass_ = self == ZMGeometryImpl ? TYPE_KLASSES[zgeometry_.geometry_type] : self
|
457
|
-
klass_ && zgeometry_ && mgeometry_ ? klass_.new(factory_, zgeometry_, mgeometry_) : nil
|
438
|
+
@factory._create_feature(ZMPointImpl, @zgeometry.centroid, @mgeometry.centroid)
|
458
439
|
end
|
459
440
|
|
460
441
|
|
@@ -106,6 +106,14 @@ module RGeo
|
|
106
106
|
end
|
107
107
|
|
108
108
|
|
109
|
+
def hash
|
110
|
+
@hash ||= begin
|
111
|
+
hash_ = [factory, geometry_type].hash
|
112
|
+
@elements.inject(hash_){ |h_, g_| (1664525 * h_ + g_.hash).hash }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
109
117
|
def _copy_state_from(obj_) # :nodoc:
|
110
118
|
super
|
111
119
|
@elements = obj_._elements
|
@@ -133,6 +133,14 @@ module RGeo
|
|
133
133
|
end
|
134
134
|
|
135
135
|
|
136
|
+
def hash
|
137
|
+
@hash ||= begin
|
138
|
+
hash_ = [factory, geometry_type].hash
|
139
|
+
@points.inject(hash_){ |h_, p_| (1664525 * h_ + p_.hash).hash }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
|
136
144
|
def _copy_state_from(obj_) # :nodoc:
|
137
145
|
super
|
138
146
|
@points = obj_.points
|