rgeo 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +11 -0
- data/README.rdoc +3 -3
- data/Spatial_Programming_With_RGeo.rdoc +19 -8
- data/Version +1 -1
- data/ext/geos_c_impl/factory.c +1 -0
- data/ext/geos_c_impl/factory.h +1 -0
- data/ext/geos_c_impl/geometry.c +4 -5
- data/ext/geos_c_impl/geometry_collection.c +15 -0
- data/ext/geos_c_impl/line_string.c +10 -0
- data/ext/geos_c_impl/point.c +2 -0
- data/ext/geos_c_impl/polygon.c +4 -0
- data/lib/rgeo/cartesian/feature_classes.rb +23 -17
- data/lib/rgeo/cartesian/feature_methods.rb +20 -1
- data/lib/rgeo/feature.rb +1 -0
- data/lib/rgeo/feature/curve.rb +1 -2
- data/lib/rgeo/feature/geometry_collection.rb +1 -1
- data/lib/rgeo/feature/line.rb +1 -1
- data/lib/rgeo/feature/line_string.rb +1 -2
- data/lib/rgeo/feature/linear_ring.rb +1 -2
- data/lib/rgeo/feature/mixins.rb +198 -0
- data/lib/rgeo/feature/multi_curve.rb +1 -2
- data/lib/rgeo/feature/multi_line_string.rb +1 -2
- data/lib/rgeo/feature/multi_point.rb +1 -2
- data/lib/rgeo/feature/multi_polygon.rb +1 -2
- data/lib/rgeo/feature/multi_surface.rb +1 -2
- data/lib/rgeo/feature/point.rb +1 -2
- data/lib/rgeo/feature/polygon.rb +1 -3
- data/lib/rgeo/feature/surface.rb +1 -2
- data/lib/rgeo/feature/types.rb +27 -0
- data/lib/rgeo/geographic/projected_feature_classes.rb +31 -4
- data/lib/rgeo/geographic/projected_feature_methods.rb +2 -1
- data/lib/rgeo/geographic/spherical_feature_classes.rb +30 -3
- data/lib/rgeo/geos.rb +22 -0
- data/lib/rgeo/geos/factory.rb +11 -5
- data/lib/rgeo/geos/ffi_classes.rb +655 -0
- data/lib/rgeo/geos/ffi_factory.rb +503 -0
- data/lib/rgeo/geos/impl_additions.rb +1 -1
- data/lib/rgeo/geos/interface.rb +63 -8
- data/lib/rgeo/geos/zm_factory.rb +10 -4
- data/test/common/geometry_collection_tests.rb +1 -3
- data/test/coord_sys/tc_ogc_cs.rb +13 -2
- data/test/coord_sys/tc_proj4_srs_data.rb +1 -1
- data/test/{geos → geos_capi}/tc_factory.rb +2 -2
- data/test/{geos → geos_capi}/tc_geometry_collection.rb +2 -2
- data/test/{geos → geos_capi}/tc_line_string.rb +2 -2
- data/test/{geos → geos_capi}/tc_misc.rb +6 -2
- data/test/{geos → geos_capi}/tc_multi_line_string.rb +2 -2
- data/test/{geos → geos_capi}/tc_multi_point.rb +2 -2
- data/test/{geos → geos_capi}/tc_multi_polygon.rb +2 -2
- data/test/{geos → geos_capi}/tc_parsing_unparsing.rb +2 -2
- data/test/{geos → geos_capi}/tc_point.rb +2 -2
- data/test/{geos → geos_capi}/tc_polygon.rb +2 -2
- data/test/{geos → geos_capi}/tc_zmfactory.rb +2 -2
- data/test/geos_ffi/tc_factory.rb +91 -0
- data/test/geos_ffi/tc_geometry_collection.rb +62 -0
- data/test/geos_ffi/tc_line_string.rb +62 -0
- data/test/geos_ffi/tc_misc.rb +69 -0
- data/test/geos_ffi/tc_multi_line_string.rb +62 -0
- data/test/geos_ffi/tc_multi_point.rb +62 -0
- data/test/geos_ffi/tc_multi_polygon.rb +64 -0
- data/test/geos_ffi/tc_parsing_unparsing.rb +81 -0
- data/test/geos_ffi/tc_point.rb +87 -0
- data/test/geos_ffi/tc_polygon.rb +86 -0
- data/test/geos_ffi/tc_zmfactory.rb +86 -0
- data/test/tc_mixins.rb +188 -0
- data/test/tc_types.rb +77 -0
- metadata +54 -25
@@ -0,0 +1,198 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Mixin tracker
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 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 Feature
|
40
|
+
|
41
|
+
|
42
|
+
# MixinCollection is a mechanism for adding arbitrary methods to
|
43
|
+
# geometry objects.
|
44
|
+
#
|
45
|
+
# Normally, geometry objects respond to the methods defined in the
|
46
|
+
# feature interface for that type of geometry; e.g.
|
47
|
+
# RGeo::Feature::Geometry, RGeo::Feature::Point, etc. Some
|
48
|
+
# implementations include additional methods specific to the
|
49
|
+
# implementation. However, occasionally it is desirable also to
|
50
|
+
# include custom methods allowing objects to function in different
|
51
|
+
# contexts. To do so, provide those methods in a mixin Module, and
|
52
|
+
# add it to an appropriate MixinCollection. A MixinCollection is
|
53
|
+
# simply a collection of mixin Modules, connected to geometry types,
|
54
|
+
# that are included in objects of that type.
|
55
|
+
#
|
56
|
+
# There is a global collection, MixinCollection::GLOBAL, which
|
57
|
+
# manages mixins to be added to all implementations. In addition,
|
58
|
+
# individual implementation factories may provide additional local
|
59
|
+
# MixinCollection objects for mixins specific to objects created
|
60
|
+
# by that factory.
|
61
|
+
#
|
62
|
+
# Each mixin module added to a MixinCollection is connected to a
|
63
|
+
# specific type, which controls to which objects that mixin is added.
|
64
|
+
# For example, a mixin connected to Point is added only to Point
|
65
|
+
# objects. A mixin connected to GeometryCollection is added to
|
66
|
+
# GeometryCollection objects as well as MultiPoint, MultiLineString,
|
67
|
+
# and MultiPolygon, since those are subtypes of GeometryCollection.
|
68
|
+
# To add a mixin to all objects, connect it to the Geometry base type.
|
69
|
+
|
70
|
+
class MixinCollection
|
71
|
+
|
72
|
+
|
73
|
+
# An API point controlling a particular type.
|
74
|
+
|
75
|
+
class TypeData
|
76
|
+
|
77
|
+
|
78
|
+
def initialize(collection_, type_) # :nodoc:
|
79
|
+
@collection = collection_
|
80
|
+
@type = type_
|
81
|
+
@mixins = []
|
82
|
+
@classes = []
|
83
|
+
@rmixins = []
|
84
|
+
@rclasses = []
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# The feature type
|
89
|
+
attr_reader :type
|
90
|
+
|
91
|
+
# The MixinCollection owning this data
|
92
|
+
attr_reader :collection
|
93
|
+
|
94
|
+
|
95
|
+
# Add a mixin to be included in implementations of this type.
|
96
|
+
|
97
|
+
def add(module_)
|
98
|
+
@mixins << module_
|
99
|
+
@classes.each{ |k_| k_.class_eval{ include(module_) } }
|
100
|
+
_radd(module_)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
# A class that implements this type should call this method to
|
105
|
+
# get the appropriate mixins.
|
106
|
+
# If include_ancestry_ is set to true, then mixins connected to
|
107
|
+
# subtypes of this type are also added to the class.
|
108
|
+
|
109
|
+
def include_in_class(klass_, include_ancestry_=false)
|
110
|
+
(include_ancestry_ ? @rmixins : @mixins).each{ |m_| klass_.class_eval{ include(m_) } }
|
111
|
+
(include_ancestry_ ? @rclasses : @classes) << klass_
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
# An object that implements this type should call this method to
|
117
|
+
# get the appropriate mixins.
|
118
|
+
# If include_ancestry_ is set to true, then mixins connected to
|
119
|
+
# subtypes of this type are also added to the object.
|
120
|
+
|
121
|
+
def include_in_object(obj_, include_ancestry_=false)
|
122
|
+
(include_ancestry_ ? @rmixins : @mixins).each{ |m_| obj_.extend(m_) }
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def _radd(module_) # :nodoc:
|
128
|
+
@rmixins << module_
|
129
|
+
@rclasses.each{ |k_| k_.class_eval{ include(module_) } }
|
130
|
+
@type.each_immediate_subtype{ |t_| @collection.for_type(t_)._radd(module_) }
|
131
|
+
self
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
# Create a new empty MixinCollection
|
139
|
+
|
140
|
+
def initialize
|
141
|
+
@types = {}
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
# Returns a TypeData for the given type.
|
146
|
+
#
|
147
|
+
# e.g. to add a module for point types, you can call:
|
148
|
+
# for_type(::RGeo::Feature::Point).add(module)
|
149
|
+
|
150
|
+
def for_type(type_)
|
151
|
+
(@types[type_] ||= TypeData.new(self, type_))
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
# Add a module connected to the given type.
|
156
|
+
#
|
157
|
+
# Shorthand for:
|
158
|
+
# for_type(type_).add(module_)
|
159
|
+
|
160
|
+
def add(type_, module_)
|
161
|
+
for_type(type_).add(module_)
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
# A class that implements this type should call this method to
|
166
|
+
# get the appropriate mixins.
|
167
|
+
#
|
168
|
+
# Shorthand for:
|
169
|
+
# for_type(type_).include_in_class(klass_, include_ancestry_)
|
170
|
+
|
171
|
+
def include_in_class(type_, klass_, include_ancestry_=false)
|
172
|
+
for_type(type_).include_in_class(klass_, include_ancestry_)
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
# An object that implements this type should call this method to
|
177
|
+
# get the appropriate mixins.
|
178
|
+
#
|
179
|
+
# Shorthand for:
|
180
|
+
# for_type(type_).include_in_object(obj_, include_ancestry_)
|
181
|
+
|
182
|
+
def include_in_object(type_, obj_, include_ancestry_=false)
|
183
|
+
for_type(type_).include_in_object(obj_, include_ancestry_)
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
# The global MixinCollection. Mixins added to this collection are
|
188
|
+
# added to all geometry objects for all implementations.
|
189
|
+
|
190
|
+
GLOBAL = MixinCollection.new
|
191
|
+
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
data/lib/rgeo/feature/point.rb
CHANGED
data/lib/rgeo/feature/polygon.rb
CHANGED
data/lib/rgeo/feature/surface.rb
CHANGED
data/lib/rgeo/feature/types.rb
CHANGED
@@ -90,6 +90,21 @@ module RGeo
|
|
90
90
|
end
|
91
91
|
|
92
92
|
|
93
|
+
# Returns the supertype of this type. The supertype of Geometry
|
94
|
+
# is nil.
|
95
|
+
|
96
|
+
def supertype
|
97
|
+
@supertype
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
# Iterates over the known immediate subtypes of this type.
|
102
|
+
|
103
|
+
def each_immediate_subtype(&block_)
|
104
|
+
@subtypes.each(&block_) if @subtypes
|
105
|
+
end
|
106
|
+
|
107
|
+
|
93
108
|
# Returns the OpenGIS type name of this type.
|
94
109
|
|
95
110
|
def type_name
|
@@ -97,6 +112,18 @@ module RGeo
|
|
97
112
|
end
|
98
113
|
|
99
114
|
|
115
|
+
def _add_subtype(type_) # :nodoc:
|
116
|
+
(@subtypes ||= []) << type_
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def self.extended(type_) # :nodoc:
|
121
|
+
supertype_ = type_.included_modules.find{ |m_| m_.kind_of?(self) }
|
122
|
+
type_.instance_variable_set(:@supertype, supertype_)
|
123
|
+
supertype_._add_subtype(type_) if supertype_
|
124
|
+
end
|
125
|
+
|
126
|
+
|
100
127
|
end
|
101
128
|
|
102
129
|
|
@@ -79,6 +79,9 @@ module RGeo
|
|
79
79
|
alias_method :lat, :y
|
80
80
|
|
81
81
|
|
82
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
|
83
|
+
|
84
|
+
|
82
85
|
end
|
83
86
|
|
84
87
|
|
@@ -93,13 +96,16 @@ module RGeo
|
|
93
96
|
include ProjectedLineStringMethods
|
94
97
|
|
95
98
|
|
99
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
|
100
|
+
|
101
|
+
|
96
102
|
end
|
97
103
|
|
98
104
|
|
99
105
|
class ProjectedLinearRingImpl # :nodoc:
|
100
106
|
|
101
107
|
|
102
|
-
include Feature::
|
108
|
+
include Feature::LinearRing
|
103
109
|
include ImplHelper::BasicGeometryMethods
|
104
110
|
include ImplHelper::BasicLineStringMethods
|
105
111
|
include ImplHelper::BasicLinearRingMethods
|
@@ -108,6 +114,9 @@ module RGeo
|
|
108
114
|
include ProjectedLineStringMethods
|
109
115
|
|
110
116
|
|
117
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
|
118
|
+
|
119
|
+
|
111
120
|
end
|
112
121
|
|
113
122
|
|
@@ -123,6 +132,9 @@ module RGeo
|
|
123
132
|
include ProjectedLineStringMethods
|
124
133
|
|
125
134
|
|
135
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
|
136
|
+
|
137
|
+
|
126
138
|
end
|
127
139
|
|
128
140
|
|
@@ -144,6 +156,9 @@ module RGeo
|
|
144
156
|
end
|
145
157
|
|
146
158
|
|
159
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
|
160
|
+
|
161
|
+
|
147
162
|
end
|
148
163
|
|
149
164
|
|
@@ -156,26 +171,32 @@ module RGeo
|
|
156
171
|
include ProjectedGeometryMethods
|
157
172
|
|
158
173
|
|
174
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
|
175
|
+
|
176
|
+
|
159
177
|
end
|
160
178
|
|
161
179
|
|
162
180
|
class ProjectedMultiPointImpl # :nodoc:
|
163
181
|
|
164
182
|
|
165
|
-
include Feature::
|
183
|
+
include Feature::MultiPoint
|
166
184
|
include ImplHelper::BasicGeometryMethods
|
167
185
|
include ImplHelper::BasicGeometryCollectionMethods
|
168
186
|
include ImplHelper::BasicMultiPointMethods
|
169
187
|
include ProjectedGeometryMethods
|
170
188
|
|
171
189
|
|
190
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
|
191
|
+
|
192
|
+
|
172
193
|
end
|
173
194
|
|
174
195
|
|
175
196
|
class ProjectedMultiLineStringImpl # :nodoc:
|
176
197
|
|
177
198
|
|
178
|
-
include Feature::
|
199
|
+
include Feature::MultiLineString
|
179
200
|
include ImplHelper::BasicGeometryMethods
|
180
201
|
include ImplHelper::BasicGeometryCollectionMethods
|
181
202
|
include ImplHelper::BasicMultiLineStringMethods
|
@@ -183,13 +204,16 @@ module RGeo
|
|
183
204
|
include ProjectedNCurveMethods
|
184
205
|
|
185
206
|
|
207
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
|
208
|
+
|
209
|
+
|
186
210
|
end
|
187
211
|
|
188
212
|
|
189
213
|
class ProjectedMultiPolygonImpl # :nodoc:
|
190
214
|
|
191
215
|
|
192
|
-
include Feature::
|
216
|
+
include Feature::MultiPolygon
|
193
217
|
include ImplHelper::BasicGeometryMethods
|
194
218
|
include ImplHelper::BasicGeometryCollectionMethods
|
195
219
|
include ImplHelper::BasicMultiPolygonMethods
|
@@ -205,6 +229,9 @@ module RGeo
|
|
205
229
|
end
|
206
230
|
|
207
231
|
|
232
|
+
Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
|
233
|
+
|
234
|
+
|
208
235
|
end
|
209
236
|
|
210
237
|
|