rgeo 0.3.13 → 0.3.14

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.
Files changed (51) hide show
  1. data/History.rdoc +8 -0
  2. data/README.rdoc +4 -4
  3. data/Version +1 -1
  4. data/ext/geos_c_impl/extconf.rb +1 -0
  5. data/ext/geos_c_impl/factory.c +118 -5
  6. data/ext/geos_c_impl/factory.h +24 -1
  7. data/ext/geos_c_impl/geometry.c +42 -53
  8. data/ext/geos_c_impl/geometry_collection.c +137 -54
  9. data/ext/geos_c_impl/geometry_collection.h +9 -0
  10. data/ext/geos_c_impl/line_string.c +88 -45
  11. data/ext/geos_c_impl/point.c +31 -17
  12. data/ext/geos_c_impl/polygon.c +50 -22
  13. data/ext/geos_c_impl/polygon.h +9 -0
  14. data/ext/geos_c_impl/preface.h +10 -0
  15. data/lib/rgeo/cartesian/factory.rb +9 -1
  16. data/lib/rgeo/coord_sys/cs/entities.rb +10 -1
  17. data/lib/rgeo/coord_sys/proj4.rb +1 -1
  18. data/lib/rgeo/feature/types.rb +29 -5
  19. data/lib/rgeo/geographic/factory.rb +5 -0
  20. data/lib/rgeo/geographic/projected_feature_classes.rb +3 -47
  21. data/lib/rgeo/geographic/projected_feature_methods.rb +69 -0
  22. data/lib/rgeo/geographic/spherical_feature_classes.rb +1 -74
  23. data/lib/rgeo/geographic/spherical_feature_methods.rb +84 -0
  24. data/lib/rgeo/geographic/spherical_math.rb +3 -3
  25. data/lib/rgeo/geos.rb +17 -9
  26. data/lib/rgeo/geos/{factory.rb → capi_factory.rb} +36 -15
  27. data/lib/rgeo/geos/{impl_additions.rb → capi_feature_classes.rb} +127 -16
  28. data/lib/rgeo/geos/ffi_factory.rb +55 -41
  29. data/lib/rgeo/geos/ffi_feature_classes.rb +168 -0
  30. data/lib/rgeo/geos/{ffi_classes.rb → ffi_feature_methods.rb} +56 -57
  31. data/lib/rgeo/geos/interface.rb +5 -5
  32. data/lib/rgeo/geos/utils.rb +7 -0
  33. data/lib/rgeo/geos/zm_factory.rb +40 -12
  34. data/lib/rgeo/geos/zm_feature_classes.rb +165 -0
  35. data/lib/rgeo/geos/{zm_impl.rb → zm_feature_methods.rb} +33 -52
  36. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +8 -0
  37. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +8 -0
  38. data/lib/rgeo/impl_helper/basic_point_methods.rb +5 -0
  39. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +8 -0
  40. data/test/common/factory_tests.rb +8 -2
  41. data/test/common/geometry_collection_tests.rb +23 -0
  42. data/test/common/line_string_tests.rb +25 -0
  43. data/test/common/multi_line_string_tests.rb +7 -0
  44. data/test/common/multi_point_tests.rb +7 -0
  45. data/test/common/multi_polygon_tests.rb +7 -0
  46. data/test/common/point_tests.rb +21 -0
  47. data/test/common/polygon_tests.rb +15 -0
  48. data/test/coord_sys/tc_proj4.rb +8 -1
  49. data/test/geos_capi/tc_misc.rb +1 -1
  50. data/test/tc_mixins.rb +1 -1
  51. metadata +9 -7
@@ -38,10 +38,12 @@ module RGeo
38
38
  module Geos
39
39
 
40
40
 
41
- class GeometryImpl # :nodoc:
41
+ module CAPIGeometryMethods # :nodoc:
42
+
42
43
 
43
44
  include Feature::Instance
44
45
 
46
+
45
47
  def inspect
46
48
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
47
49
  end
@@ -87,23 +89,132 @@ module RGeo
87
89
  end
88
90
 
89
91
 
90
- class Factory
92
+ module CAPIGeometryCollectionMethods # :nodoc:
91
93
 
94
+ include ::Enumerable
92
95
 
93
- # :stopdoc:
94
- if defined?(::RGeo::Geos::PointImpl)
95
- IMPL_CLASSES = {
96
- Feature::Point => PointImpl,
97
- Feature::LineString => LineStringImpl,
98
- Feature::LinearRing => LinearRingImpl,
99
- Feature::Line => LineImpl,
100
- Feature::GeometryCollection => GeometryCollectionImpl,
101
- Feature::MultiPoint => MultiPointImpl,
102
- Feature::MultiLineString => MultiLineStringImpl,
103
- Feature::MultiPolygon => MultiPolygonImpl,
104
- }.freeze
105
- end
106
- # :startdoc:
96
+ end
97
+
98
+
99
+ class CAPIGeometryImpl
100
+
101
+
102
+ include CAPIGeometryMethods
103
+
104
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Geometry).include_in_class(self, true)
105
+
106
+
107
+ end
108
+
109
+
110
+ class CAPIPointImpl
111
+
112
+
113
+ include CAPIGeometryMethods
114
+ include CAPIPointMethods
115
+
116
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
117
+
118
+
119
+ end
120
+
121
+
122
+ class CAPILineStringImpl
123
+
124
+
125
+ include CAPIGeometryMethods
126
+ include CAPILineStringMethods
127
+
128
+ Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
129
+
130
+
131
+ end
132
+
133
+
134
+ class CAPILinearRingImpl
135
+
136
+
137
+ include CAPIGeometryMethods
138
+ include CAPILineStringMethods
139
+ include CAPILinearRingMethods
140
+
141
+ Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
142
+
143
+
144
+ end
145
+
146
+
147
+ class CAPILineImpl
148
+
149
+
150
+ include CAPIGeometryMethods
151
+ include CAPILineStringMethods
152
+ include CAPILineMethods
153
+
154
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
155
+
156
+
157
+ end
158
+
159
+
160
+ class CAPIPolygonImpl
161
+
162
+
163
+ include CAPIGeometryMethods
164
+ include CAPIPolygonMethods
165
+
166
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
167
+
168
+
169
+ end
170
+
171
+
172
+ class CAPIGeometryCollectionImpl
173
+
174
+
175
+ include CAPIGeometryMethods
176
+ include CAPIGeometryCollectionMethods
177
+
178
+ Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
179
+
180
+
181
+ end
182
+
183
+
184
+ class CAPIMultiPointImpl
185
+
186
+
187
+ include CAPIGeometryMethods
188
+ include CAPIGeometryCollectionMethods
189
+ include CAPIMultiPointMethods
190
+
191
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
192
+
193
+
194
+ end
195
+
196
+
197
+ class CAPIMultiLineStringImpl
198
+
199
+
200
+ include CAPIGeometryMethods
201
+ include CAPIGeometryCollectionMethods
202
+ include CAPIMultiLineStringMethods
203
+
204
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
205
+
206
+
207
+ end
208
+
209
+
210
+ class CAPIMultiPolygonImpl
211
+
212
+
213
+ include CAPIGeometryMethods
214
+ include CAPIGeometryCollectionMethods
215
+ include CAPIMultiPolygonMethods
216
+
217
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
107
218
 
108
219
 
109
220
  end
@@ -154,11 +154,18 @@ module RGeo
154
154
  def eql?(rhs_)
155
155
  rhs_.is_a?(self.class) && @srid == rhs_.srid &&
156
156
  @has_z == rhs_.property(:has_z_coordinate) &&
157
- @has_m == rhs_.property(:has_m_coordinate)
157
+ @has_m == rhs_.property(:has_m_coordinate) &&
158
+ @buffer_resolution == rhs_.property(:buffer_resolution) &&
159
+ @proj4.eql?(rhs_.proj4)
158
160
  end
159
161
  alias_method :==, :eql?
160
162
 
161
163
 
164
+ def hash
165
+ @hash ||= [@srid, @has_z, @has_m, @buffer_resolution, @proj4].hash
166
+ end
167
+
168
+
162
169
  # Marshal support
163
170
 
164
171
  def marshal_dump # :nodoc:
@@ -304,11 +311,18 @@ module RGeo
304
311
  end
305
312
 
306
313
 
314
+ # Create a feature that wraps the given ffi-geos geometry object
315
+
316
+ def wrap_fg_geom(fg_geom_)
317
+ _wrap_fg_geom(fg_geom_, nil)
318
+ end
319
+
320
+
307
321
  # See ::RGeo::Feature::Factory#parse_wkt
308
322
 
309
323
  def parse_wkt(str_)
310
324
  if @wkt_reader
311
- wrap_fg_geom(@wkt_reader.read(str_))
325
+ _wrap_fg_geom(@wkt_reader.read(str_), nil)
312
326
  else
313
327
  @wkt_parser.parse(str_)
314
328
  end
@@ -319,50 +333,13 @@ module RGeo
319
333
 
320
334
  def parse_wkb(str_)
321
335
  if @wkb_reader
322
- wrap_fg_geom(@wkb_reader.read(str_))
336
+ _wrap_fg_geom(@wkb_reader.read(str_), nil)
323
337
  else
324
338
  @wkb_parser.parse(str_)
325
339
  end
326
340
  end
327
341
 
328
342
 
329
- def wrap_fg_geom(fg_geom_, klass_=nil) # :nodoc:
330
- klasses_ = nil
331
- unless klass_.kind_of?(::Class)
332
- is_collection_ = false
333
- case fg_geom_.type_id
334
- when ::Geos::GeomTypes::GEOS_POINT
335
- inferred_klass_ = FFIPointImpl
336
- when ::Geos::GeomTypes::GEOS_MULTIPOINT
337
- inferred_klass_ = FFIMultiPointImpl
338
- is_collection_ = true
339
- when ::Geos::GeomTypes::GEOS_LINESTRING
340
- inferred_klass_ = FFILineStringImpl
341
- when ::Geos::GeomTypes::GEOS_LINEARRING
342
- inferred_klass_ = FFILinearRingImpl
343
- when ::Geos::GeomTypes::GEOS_MULTILINESTRING
344
- inferred_klass_ = FFIMultiLineStringImpl
345
- is_collection_ = true
346
- when ::Geos::GeomTypes::GEOS_POLYGON
347
- inferred_klass_ = FFIPolygonImpl
348
- when ::Geos::GeomTypes::GEOS_MULTIPOLYGON
349
- inferred_klass_ = FFIMultiPolygonImpl
350
- is_collection_ = true
351
- when ::Geos::GeomTypes::GEOS_GEOMETRYCOLLECTION
352
- inferred_klass_ = FFIGeometryCollectionImpl
353
- is_collection_ = true
354
- else
355
- inferred_klass_ = FFIGeometryImpl
356
- end
357
- if is_collection_ && klass_.is_a?(::Array)
358
- klasses_ = klass_
359
- end
360
- klass_ = inferred_klass_
361
- end
362
- klass_.new(self, fg_geom_, klasses_)
363
- end
364
-
365
-
366
343
  # See ::RGeo::Feature::Factory#point
367
344
 
368
345
  def point(x_, y_, z_=0)
@@ -448,7 +425,7 @@ module RGeo
448
425
  klasses_ = []
449
426
  fg_geoms_ = []
450
427
  elems_.each do |elem_|
451
- k_ = elem_._klasses if elem_.is_a?(FFIGeometryImpl)
428
+ k_ = elem_._klasses if elem_.factory.is_a?(FFIFactory)
452
429
  elem_ = ::RGeo::Feature.cast(elem_, self, :force_new, :keep_subtype)
453
430
  if elem_
454
431
  klasses_ << (k_ || elem_.class)
@@ -549,6 +526,43 @@ module RGeo
549
526
  attr_reader :_auto_prepare # :nodoc:
550
527
 
551
528
 
529
+ def _wrap_fg_geom(fg_geom_, klass_) # :nodoc:
530
+ klasses_ = nil
531
+ unless klass_.kind_of?(::Class)
532
+ is_collection_ = false
533
+ case fg_geom_.type_id
534
+ when ::Geos::GeomTypes::GEOS_POINT
535
+ inferred_klass_ = FFIPointImpl
536
+ when ::Geos::GeomTypes::GEOS_MULTIPOINT
537
+ inferred_klass_ = FFIMultiPointImpl
538
+ is_collection_ = true
539
+ when ::Geos::GeomTypes::GEOS_LINESTRING
540
+ inferred_klass_ = FFILineStringImpl
541
+ when ::Geos::GeomTypes::GEOS_LINEARRING
542
+ inferred_klass_ = FFILinearRingImpl
543
+ when ::Geos::GeomTypes::GEOS_MULTILINESTRING
544
+ inferred_klass_ = FFIMultiLineStringImpl
545
+ is_collection_ = true
546
+ when ::Geos::GeomTypes::GEOS_POLYGON
547
+ inferred_klass_ = FFIPolygonImpl
548
+ when ::Geos::GeomTypes::GEOS_MULTIPOLYGON
549
+ inferred_klass_ = FFIMultiPolygonImpl
550
+ is_collection_ = true
551
+ when ::Geos::GeomTypes::GEOS_GEOMETRYCOLLECTION
552
+ inferred_klass_ = FFIGeometryCollectionImpl
553
+ is_collection_ = true
554
+ else
555
+ inferred_klass_ = FFIGeometryImpl
556
+ end
557
+ if is_collection_ && klass_.is_a?(::Array)
558
+ klasses_ = klass_
559
+ end
560
+ klass_ = inferred_klass_
561
+ end
562
+ klass_.new(self, fg_geom_, klasses_)
563
+ end
564
+
565
+
552
566
  def _convert_to_fg_geometry(obj_, type_=nil) # :nodoc:
553
567
  if type_.nil? && obj_.factory == self
554
568
  obj_
@@ -0,0 +1,168 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # FFI-GEOS geometry implementation
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 FFIGeometryImpl # :nodoc:
43
+
44
+
45
+ include FFIGeometryMethods
46
+
47
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Geometry).include_in_class(self, true)
48
+
49
+
50
+ end
51
+
52
+
53
+ class FFIPointImpl # :nodoc:
54
+
55
+
56
+ include FFIGeometryMethods
57
+ include FFIPointMethods
58
+
59
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
60
+
61
+
62
+ end
63
+
64
+
65
+ class FFILineStringImpl # :nodoc:
66
+
67
+
68
+ include FFIGeometryMethods
69
+ include FFILineStringMethods
70
+
71
+ Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
72
+
73
+
74
+ end
75
+
76
+
77
+ class FFILinearRingImpl # :nodoc:
78
+
79
+
80
+ include FFIGeometryMethods
81
+ include FFILineStringMethods
82
+ include FFILinearRingMethods
83
+
84
+ Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
85
+
86
+
87
+ end
88
+
89
+
90
+ class FFILineImpl # :nodoc:
91
+
92
+
93
+ include FFIGeometryMethods
94
+ include FFILineStringMethods
95
+ include FFILineMethods
96
+
97
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
98
+
99
+
100
+ end
101
+
102
+
103
+ class FFIPolygonImpl # :nodoc:
104
+
105
+
106
+ include FFIGeometryMethods
107
+ include FFIPolygonMethods
108
+
109
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
110
+
111
+
112
+ end
113
+
114
+
115
+ class FFIGeometryCollectionImpl # :nodoc:
116
+
117
+
118
+ include FFIGeometryMethods
119
+ include FFIGeometryCollectionMethods
120
+
121
+ Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
122
+
123
+
124
+ end
125
+
126
+
127
+ class FFIMultiPointImpl # :nodoc:
128
+
129
+
130
+ include FFIGeometryMethods
131
+ include FFIGeometryCollectionMethods
132
+ include FFIMultiPointMethods
133
+
134
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
135
+
136
+
137
+ end
138
+
139
+
140
+ class FFIMultiLineStringImpl # :nodoc:
141
+
142
+
143
+ include FFIGeometryMethods
144
+ include FFIGeometryCollectionMethods
145
+ include FFIMultiLineStringMethods
146
+
147
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
148
+
149
+
150
+ end
151
+
152
+
153
+ class FFIMultiPolygonImpl # :nodoc:
154
+
155
+
156
+ include FFIGeometryMethods
157
+ include FFIGeometryCollectionMethods
158
+ include FFIMultiPolygonMethods
159
+
160
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
161
+
162
+
163
+ end
164
+
165
+
166
+ end
167
+
168
+ end