rgeo 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/History.rdoc +11 -0
  2. data/README.rdoc +3 -3
  3. data/Spatial_Programming_With_RGeo.rdoc +19 -8
  4. data/Version +1 -1
  5. data/ext/geos_c_impl/factory.c +1 -0
  6. data/ext/geos_c_impl/factory.h +1 -0
  7. data/ext/geos_c_impl/geometry.c +4 -5
  8. data/ext/geos_c_impl/geometry_collection.c +15 -0
  9. data/ext/geos_c_impl/line_string.c +10 -0
  10. data/ext/geos_c_impl/point.c +2 -0
  11. data/ext/geos_c_impl/polygon.c +4 -0
  12. data/lib/rgeo/cartesian/feature_classes.rb +23 -17
  13. data/lib/rgeo/cartesian/feature_methods.rb +20 -1
  14. data/lib/rgeo/feature.rb +1 -0
  15. data/lib/rgeo/feature/curve.rb +1 -2
  16. data/lib/rgeo/feature/geometry_collection.rb +1 -1
  17. data/lib/rgeo/feature/line.rb +1 -1
  18. data/lib/rgeo/feature/line_string.rb +1 -2
  19. data/lib/rgeo/feature/linear_ring.rb +1 -2
  20. data/lib/rgeo/feature/mixins.rb +198 -0
  21. data/lib/rgeo/feature/multi_curve.rb +1 -2
  22. data/lib/rgeo/feature/multi_line_string.rb +1 -2
  23. data/lib/rgeo/feature/multi_point.rb +1 -2
  24. data/lib/rgeo/feature/multi_polygon.rb +1 -2
  25. data/lib/rgeo/feature/multi_surface.rb +1 -2
  26. data/lib/rgeo/feature/point.rb +1 -2
  27. data/lib/rgeo/feature/polygon.rb +1 -3
  28. data/lib/rgeo/feature/surface.rb +1 -2
  29. data/lib/rgeo/feature/types.rb +27 -0
  30. data/lib/rgeo/geographic/projected_feature_classes.rb +31 -4
  31. data/lib/rgeo/geographic/projected_feature_methods.rb +2 -1
  32. data/lib/rgeo/geographic/spherical_feature_classes.rb +30 -3
  33. data/lib/rgeo/geos.rb +22 -0
  34. data/lib/rgeo/geos/factory.rb +11 -5
  35. data/lib/rgeo/geos/ffi_classes.rb +655 -0
  36. data/lib/rgeo/geos/ffi_factory.rb +503 -0
  37. data/lib/rgeo/geos/impl_additions.rb +1 -1
  38. data/lib/rgeo/geos/interface.rb +63 -8
  39. data/lib/rgeo/geos/zm_factory.rb +10 -4
  40. data/test/common/geometry_collection_tests.rb +1 -3
  41. data/test/coord_sys/tc_ogc_cs.rb +13 -2
  42. data/test/coord_sys/tc_proj4_srs_data.rb +1 -1
  43. data/test/{geos → geos_capi}/tc_factory.rb +2 -2
  44. data/test/{geos → geos_capi}/tc_geometry_collection.rb +2 -2
  45. data/test/{geos → geos_capi}/tc_line_string.rb +2 -2
  46. data/test/{geos → geos_capi}/tc_misc.rb +6 -2
  47. data/test/{geos → geos_capi}/tc_multi_line_string.rb +2 -2
  48. data/test/{geos → geos_capi}/tc_multi_point.rb +2 -2
  49. data/test/{geos → geos_capi}/tc_multi_polygon.rb +2 -2
  50. data/test/{geos → geos_capi}/tc_parsing_unparsing.rb +2 -2
  51. data/test/{geos → geos_capi}/tc_point.rb +2 -2
  52. data/test/{geos → geos_capi}/tc_polygon.rb +2 -2
  53. data/test/{geos → geos_capi}/tc_zmfactory.rb +2 -2
  54. data/test/geos_ffi/tc_factory.rb +91 -0
  55. data/test/geos_ffi/tc_geometry_collection.rb +62 -0
  56. data/test/geos_ffi/tc_line_string.rb +62 -0
  57. data/test/geos_ffi/tc_misc.rb +69 -0
  58. data/test/geos_ffi/tc_multi_line_string.rb +62 -0
  59. data/test/geos_ffi/tc_multi_point.rb +62 -0
  60. data/test/geos_ffi/tc_multi_polygon.rb +64 -0
  61. data/test/geos_ffi/tc_parsing_unparsing.rb +81 -0
  62. data/test/geos_ffi/tc_point.rb +87 -0
  63. data/test/geos_ffi/tc_polygon.rb +86 -0
  64. data/test/geos_ffi/tc_zmfactory.rb +86 -0
  65. data/test/tc_mixins.rb +188 -0
  66. data/test/tc_types.rb +77 -0
  67. metadata +54 -25
@@ -54,9 +54,8 @@ module RGeo
54
54
 
55
55
  module LineString
56
56
 
57
- extend Type
58
-
59
57
  include Curve
58
+ extend Type
60
59
 
61
60
 
62
61
  # === SFS 1.1 Description
@@ -53,9 +53,8 @@ module RGeo
53
53
 
54
54
  module LinearRing
55
55
 
56
- extend Type
57
-
58
56
  include LineString
57
+ extend Type
59
58
 
60
59
 
61
60
  end
@@ -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
@@ -71,9 +71,8 @@ module RGeo
71
71
 
72
72
  module MultiCurve
73
73
 
74
- extend Type
75
-
76
74
  include GeometryCollection
75
+ extend Type
77
76
 
78
77
 
79
78
  # === SFS 1.1 Description
@@ -53,9 +53,8 @@ module RGeo
53
53
 
54
54
  module MultiLineString
55
55
 
56
- extend Type
57
-
58
56
  include MultiCurve
57
+ extend Type
59
58
 
60
59
 
61
60
  end
@@ -60,9 +60,8 @@ module RGeo
60
60
 
61
61
  module MultiPoint
62
62
 
63
- extend Type
64
-
65
63
  include GeometryCollection
64
+ extend Type
66
65
 
67
66
 
68
67
  end
@@ -84,9 +84,8 @@ module RGeo
84
84
 
85
85
  module MultiPolygon
86
86
 
87
- extend Type
88
-
89
87
  include MultiSurface
88
+ extend Type
90
89
 
91
90
 
92
91
  end
@@ -62,9 +62,8 @@ module RGeo
62
62
 
63
63
  module MultiSurface
64
64
 
65
- extend Type
66
-
67
65
  include GeometryCollection
66
+ extend Type
68
67
 
69
68
 
70
69
  # === SFS 1.1 Description
@@ -59,9 +59,8 @@ module RGeo
59
59
 
60
60
  module Point
61
61
 
62
- extend Type
63
-
64
62
  include Geometry
63
+ extend Type
65
64
 
66
65
 
67
66
  # === SFS 1.1 Description
@@ -79,10 +79,8 @@ module RGeo
79
79
 
80
80
  module Polygon
81
81
 
82
- extend Type
83
-
84
82
  include Surface
85
- include ::Enumerable
83
+ extend Type
86
84
 
87
85
 
88
86
  # === SFS 1.1 Description
@@ -68,9 +68,8 @@ module RGeo
68
68
 
69
69
  module Surface
70
70
 
71
- extend Type
72
-
73
71
  include Geometry
72
+ extend Type
74
73
 
75
74
 
76
75
  # === SFS 1.1 Description
@@ -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::Line
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::GeometryCollection
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::GeometryCollection
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::GeometryCollection
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