rgeo 2.1.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +160 -0
  3. data/ext/geos_c_impl/analysis.c +78 -0
  4. data/ext/geos_c_impl/analysis.h +42 -0
  5. data/ext/geos_c_impl/errors.c +35 -0
  6. data/ext/geos_c_impl/errors.h +22 -0
  7. data/ext/geos_c_impl/extconf.rb +1 -0
  8. data/ext/geos_c_impl/factory.c +15 -7
  9. data/ext/geos_c_impl/factory.h +5 -1
  10. data/ext/geos_c_impl/geometry.c +9 -8
  11. data/ext/geos_c_impl/geometry_collection.c +1 -1
  12. data/ext/geos_c_impl/line_string.c +2 -2
  13. data/ext/geos_c_impl/main.c +5 -2
  14. data/ext/geos_c_impl/preface.h +3 -0
  15. data/lib/rgeo/cartesian/analysis.rb +22 -0
  16. data/lib/rgeo/cartesian/feature_methods.rb +6 -1
  17. data/lib/rgeo/cartesian.rb +7 -7
  18. data/lib/rgeo/coord_sys.rb +6 -6
  19. data/lib/rgeo/error.rb +4 -0
  20. data/lib/rgeo/feature/curve.rb +12 -2
  21. data/lib/rgeo/feature/geometry.rb +12 -2
  22. data/lib/rgeo/feature/linear_ring.rb +10 -0
  23. data/lib/rgeo/feature/multi_curve.rb +6 -1
  24. data/lib/rgeo/feature.rb +17 -17
  25. data/lib/rgeo/geographic/interface.rb +2 -1
  26. data/lib/rgeo/geographic/projected_feature_methods.rb +12 -2
  27. data/lib/rgeo/geographic/spherical_feature_classes.rb +1 -0
  28. data/lib/rgeo/geographic/spherical_feature_methods.rb +29 -1
  29. data/lib/rgeo/geographic.rb +10 -10
  30. data/lib/rgeo/geos/capi_factory.rb +5 -1
  31. data/lib/rgeo/geos/capi_feature_classes.rb +33 -0
  32. data/lib/rgeo/geos/ffi_feature_methods.rb +34 -5
  33. data/lib/rgeo/geos/interface.rb +18 -4
  34. data/lib/rgeo/geos/zm_feature_methods.rb +30 -5
  35. data/lib/rgeo/geos.rb +11 -11
  36. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +33 -5
  37. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +62 -8
  38. data/lib/rgeo/impl_helper/basic_point_methods.rb +12 -2
  39. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +45 -3
  40. data/lib/rgeo/impl_helper.rb +7 -7
  41. data/lib/rgeo/version.rb +1 -1
  42. data/lib/rgeo/wkrep/wkb_generator.rb +1 -1
  43. data/lib/rgeo/wkrep/wkt_generator.rb +6 -6
  44. data/lib/rgeo/wkrep.rb +4 -4
  45. data/lib/rgeo.rb +9 -9
  46. metadata +21 -11
@@ -90,8 +90,13 @@ module RGeo
90
90
  # Returns a boolean value. Note that this is different from the SFS
91
91
  # specification, which stipulates an integer return value.
92
92
 
93
+ def closed?
94
+ raise Error::UnsupportedOperation, "Method Curve#closed? not defined."
95
+ end
96
+
93
97
  def is_closed?
94
- raise Error::UnsupportedOperation, "Method Curve#is_closed? not defined."
98
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
99
+ closed?
95
100
  end
96
101
 
97
102
  # === SFS 1.1 Description
@@ -105,8 +110,13 @@ module RGeo
105
110
  # Returns a boolean value. Note that this is different from the SFS
106
111
  # specification, which stipulates an integer return value.
107
112
 
113
+ def ring?
114
+ raise Error::UnsupportedOperation, "Method Curve#ring? not defined."
115
+ end
116
+
108
117
  def is_ring?
109
- raise Error::UnsupportedOperation, "Method Curve#is_ring? not defined."
118
+ warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
119
+ ring?
110
120
  end
111
121
  end
112
122
  end
@@ -191,8 +191,13 @@ module RGeo
191
191
  # Returns a boolean value. Note that this is different from the SFS
192
192
  # specification, which stipulates an integer return value.
193
193
 
194
+ def empty?
195
+ raise Error::UnsupportedOperation, "Method Geometry#empty? not defined."
196
+ end
197
+
194
198
  def is_empty?
195
- raise Error::UnsupportedOperation, "Method Geometry#is_empty? not defined."
199
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
200
+ empty?
196
201
  end
197
202
 
198
203
  # === SFS 1.1 Description
@@ -208,8 +213,13 @@ module RGeo
208
213
  # Returns a boolean value. Note that this is different from the SFS
209
214
  # specification, which stipulates an integer return value.
210
215
 
216
+ def simple?
217
+ raise Error::UnsupportedOperation, "Method Geometry#simple? not defined."
218
+ end
219
+
211
220
  def is_simple?
212
- raise Error::UnsupportedOperation, "Method Geometry#is_simple? not defined."
221
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
222
+ simple?
213
223
  end
214
224
 
215
225
  # === SFS 1.1 Description
@@ -23,6 +23,16 @@ module RGeo
23
23
  module LinearRing
24
24
  include LineString
25
25
  extend Type
26
+
27
+ # Returns +true+ if the ring is oriented in a counter clockwise direction
28
+ # otherwise returns +false+.
29
+ #
30
+ # == Notes
31
+ #
32
+ # Not a standard SFS method for linear rings, but added for convenience.
33
+ def ccw?
34
+ raise Error::UnsupportedOperation, "Method LinearRing#ccw? not defined."
35
+ end
26
36
  end
27
37
  end
28
38
  end
@@ -65,8 +65,13 @@ module RGeo
65
65
  # Returns a boolean value. Note that this is different from the SFS
66
66
  # specification, which stipulates an integer return value.
67
67
 
68
+ def closed?
69
+ raise Error::UnsupportedOperation, "Method MultiCurve#closed? not defined."
70
+ end
71
+
68
72
  def is_closed?
69
- raise Error::UnsupportedOperation, "Method MultiCurve#is_closed? not defined."
73
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
74
+ closed?
70
75
  end
71
76
  end
72
77
  end
data/lib/rgeo/feature.rb CHANGED
@@ -24,20 +24,20 @@
24
24
  # itself. The implementation should separately document any such
25
25
  # extensions that it may provide.
26
26
 
27
- require "rgeo/feature/factory"
28
- require "rgeo/feature/types"
29
- require "rgeo/feature/geometry"
30
- require "rgeo/feature/point"
31
- require "rgeo/feature/curve"
32
- require "rgeo/feature/line_string"
33
- require "rgeo/feature/linear_ring"
34
- require "rgeo/feature/line"
35
- require "rgeo/feature/surface"
36
- require "rgeo/feature/polygon"
37
- require "rgeo/feature/geometry_collection"
38
- require "rgeo/feature/multi_point"
39
- require "rgeo/feature/multi_curve"
40
- require "rgeo/feature/multi_line_string"
41
- require "rgeo/feature/multi_surface"
42
- require "rgeo/feature/multi_polygon"
43
- require "rgeo/feature/factory_generator"
27
+ require_relative "feature/factory"
28
+ require_relative "feature/types"
29
+ require_relative "feature/geometry"
30
+ require_relative "feature/point"
31
+ require_relative "feature/curve"
32
+ require_relative "feature/line_string"
33
+ require_relative "feature/linear_ring"
34
+ require_relative "feature/line"
35
+ require_relative "feature/surface"
36
+ require_relative "feature/polygon"
37
+ require_relative "feature/geometry_collection"
38
+ require_relative "feature/multi_point"
39
+ require_relative "feature/multi_curve"
40
+ require_relative "feature/multi_line_string"
41
+ require_relative "feature/multi_surface"
42
+ require_relative "feature/multi_polygon"
43
+ require_relative "feature/factory_generator"
@@ -222,7 +222,8 @@ module RGeo
222
222
  wkt_generator: opts[:wkt_generator],
223
223
  wkb_generator: opts[:wkb_generator],
224
224
  has_z_coordinate: opts[:has_z_coordinate],
225
- has_m_coordinate: opts[:has_m_coordinate])
225
+ has_m_coordinate: opts[:has_m_coordinate],
226
+ uses_lenient_assertions: opts[:uses_lenient_assertions])
226
227
  projector = Geographic::SimpleMercatorProjector.new(factory,
227
228
  buffer_resolution: opts[:buffer_resolution],
228
229
  lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions],
@@ -22,12 +22,22 @@ module RGeo
22
22
  factory.unproject(projection.envelope)
23
23
  end
24
24
 
25
+ def empty?
26
+ projection.empty?
27
+ end
28
+
25
29
  def is_empty?
26
- projection.is_empty?
30
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
31
+ empty?
32
+ end
33
+
34
+ def simple?
35
+ projection.simple?
27
36
  end
28
37
 
29
38
  def is_simple?
30
- projection.is_simple?
39
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
40
+ simple?
31
41
  end
32
42
 
33
43
  def boundary
@@ -47,6 +47,7 @@ module RGeo
47
47
  include ImplHelper::BasicGeometryMethods
48
48
  include ImplHelper::BasicPolygonMethods
49
49
  include SphericalGeometryMethods
50
+ include SphericalPolygonMethods
50
51
  end
51
52
 
52
53
  class SphericalGeometryCollectionImpl # :nodoc:
@@ -97,7 +97,7 @@ module RGeo
97
97
  end
98
98
  end
99
99
 
100
- def is_simple?
100
+ def simple?
101
101
  len = arcs.length
102
102
  return false if arcs.any?(&:degenerate?)
103
103
  return true if len == 1
@@ -120,6 +120,11 @@ module RGeo
120
120
  true
121
121
  end
122
122
 
123
+ def is_simple?
124
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
125
+ simple?
126
+ end
127
+
123
128
  def length
124
129
  arcs.inject(0.0) { |sum, arc| sum + arc.length } * SphericalMath::RADIUS
125
130
  end
@@ -130,5 +135,28 @@ module RGeo
130
135
  inject(0.0) { |sum, geom| sum + geom.length }
131
136
  end
132
137
  end
138
+
139
+ module SphericalPolygonMethods # :nodoc:
140
+ def centroid
141
+ return super unless num_interior_rings == 0
142
+
143
+ centroid_lat = 0.0
144
+ centroid_lng = 0.0
145
+ signed_area = 0.0
146
+
147
+ exterior_ring.points.each_cons(2) do |p0, p1|
148
+ area = (p0.x * p1.y) - (p1.x * p0.y)
149
+ signed_area += area
150
+ centroid_lat += (p0.x + p1.x) * area
151
+ centroid_lng += (p0.y + p1.y) * area
152
+ end
153
+
154
+ signed_area *= 0.5
155
+ centroid_lat /= (6.0 * signed_area)
156
+ centroid_lng /= (6.0 * signed_area)
157
+
158
+ RGeo::Geographic.spherical_factory.point(centroid_lat, centroid_lng)
159
+ end
160
+ end
133
161
  end
134
162
  end
@@ -18,13 +18,13 @@
18
18
  # See the various class methods of Geographic for more information on
19
19
  # the behaviors of the factories they generate.
20
20
 
21
- require "rgeo/geographic/factory"
22
- require "rgeo/geographic/projected_window"
23
- require "rgeo/geographic/interface"
24
- require "rgeo/geographic/spherical_math"
25
- require "rgeo/geographic/spherical_feature_methods"
26
- require "rgeo/geographic/spherical_feature_classes"
27
- require "rgeo/geographic/proj4_projector"
28
- require "rgeo/geographic/simple_mercator_projector"
29
- require "rgeo/geographic/projected_feature_methods"
30
- require "rgeo/geographic/projected_feature_classes"
21
+ require_relative "geographic/factory"
22
+ require_relative "geographic/projected_window"
23
+ require_relative "geographic/interface"
24
+ require_relative "geographic/spherical_math"
25
+ require_relative "geographic/spherical_feature_methods"
26
+ require_relative "geographic/spherical_feature_classes"
27
+ require_relative "geographic/proj4_projector"
28
+ require_relative "geographic/simple_mercator_projector"
29
+ require_relative "geographic/projected_feature_methods"
30
+ require_relative "geographic/projected_feature_classes"
@@ -297,7 +297,11 @@ module RGeo
297
297
  if (wkb_parser_ = _wkb_parser)
298
298
  wkb_parser_.parse(str_)
299
299
  else
300
- _parse_wkb_impl(str_)
300
+ if str_[0] == "\x00" || str_[0] == "\x01"
301
+ _parse_wkb_impl(str_)
302
+ else
303
+ _parse_wkb_impl([str_].pack('H*'))
304
+ end
301
305
  end
302
306
  end
303
307
 
@@ -11,6 +11,16 @@ module RGeo
11
11
  module CAPIGeometryMethods # :nodoc:
12
12
  include Feature::Instance
13
13
 
14
+ def is_empty? # rubocop:disable Naming/PredicateName
15
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
16
+ empty?
17
+ end
18
+
19
+ def is_simple? # rubocop:disable Naming/PredicateName
20
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
21
+ simple?
22
+ end
23
+
14
24
  def inspect
15
25
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
16
26
  end
@@ -50,6 +60,25 @@ module RGeo
50
60
  alias to_s as_text
51
61
  end
52
62
 
63
+ module CAPIMultiLineStringMethods # :nodoc:
64
+ def is_closed? # rubocop:disable Naming/PredicateName
65
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
66
+ closed?
67
+ end
68
+ end
69
+
70
+ module CAPILineStringMethods # :nodoc:
71
+ def is_closed? # rubocop:disable Naming/PredicateName
72
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
73
+ closed?
74
+ end
75
+
76
+ def is_ring? # rubocop:disable Naming/PredicateName
77
+ warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
78
+ ring?
79
+ end
80
+ end
81
+
53
82
  module CAPIGeometryCollectionMethods # :nodoc:
54
83
  include Enumerable
55
84
  end
@@ -72,6 +101,10 @@ module RGeo
72
101
  include CAPIGeometryMethods
73
102
  include CAPILineStringMethods
74
103
  include CAPILinearRingMethods
104
+
105
+ def ccw?
106
+ RGeo::Cartesian::Analysis.ccw?(self)
107
+ end
75
108
  end
76
109
 
77
110
  class CAPILineImpl # :nodoc:
@@ -113,14 +113,24 @@ module RGeo
113
113
  @factory.generate_wkb(self)
114
114
  end
115
115
 
116
- def is_empty?
116
+ def empty?
117
117
  @fg_geom.empty?
118
118
  end
119
119
 
120
- def is_simple?
120
+ def is_empty?
121
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
122
+ empty?
123
+ end
124
+
125
+ def simple?
121
126
  @fg_geom.simple?
122
127
  end
123
128
 
129
+ def is_simple?
130
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
131
+ simple?
132
+ end
133
+
124
134
  def equals?(rhs)
125
135
  return false unless rhs.is_a?(RGeo::Feature::Instance)
126
136
  fg = factory.convert_to_fg_geometry(rhs)
@@ -367,14 +377,24 @@ module RGeo
367
377
  end
368
378
  end
369
379
 
370
- def is_closed?
380
+ def closed?
371
381
  @fg_geom.closed?
372
382
  end
373
383
 
374
- def is_ring?
384
+ def is_closed?
385
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
386
+ closed?
387
+ end
388
+
389
+ def ring?
375
390
  @fg_geom.ring?
376
391
  end
377
392
 
393
+ def is_ring?
394
+ warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
395
+ ring?
396
+ end
397
+
378
398
  def rep_equals?(rhs)
379
399
  rhs.class == self.class && rhs.factory.eql?(@factory) &&
380
400
  Utils.ffi_coord_seqs_equal?(rhs.fg_geom.coord_seq, @fg_geom.coord_seq, @factory._has_3d)
@@ -393,6 +413,10 @@ module RGeo
393
413
  def geometry_type
394
414
  Feature::LinearRing
395
415
  end
416
+
417
+ def ccw?
418
+ RGeo::Cartesian::Analysis.ccw?(self)
419
+ end
396
420
  end
397
421
 
398
422
  module FFILineMethods # :nodoc:
@@ -549,7 +573,7 @@ module RGeo
549
573
  @fg_geom.length
550
574
  end
551
575
 
552
- def is_closed?
576
+ def closed?
553
577
  size = num_geometries
554
578
  size.times do |n|
555
579
  return false unless @fg_geom.get_geometry_n(n).closed?
@@ -557,6 +581,11 @@ module RGeo
557
581
  true
558
582
  end
559
583
 
584
+ def is_closed?
585
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
586
+ closed?
587
+ end
588
+
560
589
  def coordinates
561
590
  each.map(&:coordinates)
562
591
  end
@@ -31,32 +31,47 @@ module RGeo
31
31
  # Returns true if the given feature is a CAPI GEOS feature, or if
32
32
  # the given factory is a CAPI GEOS factory.
33
33
 
34
- def is_capi_geos?(object)
34
+ def capi_geos?(object)
35
35
  CAPI_SUPPORTED &&
36
36
  (CAPIFactory === object || CAPIGeometryMethods === object ||
37
37
  ZMFactory === object && CAPIFactory === object.z_factory ||
38
38
  ZMGeometryMethods === object && CAPIGeometryMethods === object.z_geometry)
39
39
  end
40
40
 
41
+ def is_capi_geos?(object)
42
+ warn "The is_capi_geos? method is deprecated, please use the capi_geos? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
43
+ capi_geos?(object)
44
+ end
45
+
41
46
  # Returns true if the given feature is an FFI GEOS feature, or if
42
47
  # the given factory is an FFI GEOS factory.
43
48
 
44
- def is_ffi_geos?(object)
49
+ def ffi_geos?(object)
45
50
  FFI_SUPPORTED &&
46
51
  (FFIFactory === object || FFIGeometryMethods === object ||
47
52
  ZMFactory === object && FFIFactory === object.z_factory ||
48
53
  ZMGeometryMethods === object && FFIGeometryMethods === object.z_geometry)
49
54
  end
50
55
 
56
+ def is_ffi_geos?(object)
57
+ warn "The is_ffi_geos? method is deprecated, please use the ffi_geos? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
58
+ ffi_geos?(object)
59
+ end
60
+
51
61
  # Returns true if the given feature is a GEOS feature, or if the given
52
62
  # factory is a GEOS factory. Does not distinguish between CAPI and FFI.
53
63
 
54
- def is_geos?(object)
64
+ def geos?(object)
55
65
  CAPI_SUPPORTED && (CAPIFactory === object || CAPIGeometryMethods === object) ||
56
66
  FFI_SUPPORTED && (FFIFactory === object || FFIGeometryMethods === object) ||
57
67
  ZMFactory === object || ZMGeometryMethods === object
58
68
  end
59
69
 
70
+ def is_geos?(object)
71
+ warn "The is_geos? method is deprecated, please use the geos? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
72
+ geos?(object)
73
+ end
74
+
60
75
  # Returns the GEOS library version as a string of the format "x.y.z".
61
76
  # Returns nil if GEOS is not available.
62
77
 
@@ -174,7 +189,6 @@ module RGeo
174
189
  # operation that would benefit from it is called. The latter
175
190
  # never automatically generates a prepared geometry (unless you
176
191
  # generate one explicitly using the <tt>prepare!</tt> method).
177
-
178
192
  def factory(opts = {})
179
193
  if supported?
180
194
  native_interface = opts[:native_interface] || Geos.preferred_native_interface
@@ -65,12 +65,22 @@ module RGeo
65
65
  @factory.instance_variable_get(:@wkb_generator).generate(self)
66
66
  end
67
67
 
68
+ def empty?
69
+ @zgeometry.empty?
70
+ end
71
+
68
72
  def is_empty?
69
- @zgeometry.is_empty?
73
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
74
+ empty?
75
+ end
76
+
77
+ def simple?
78
+ @zgeometry.simple?
70
79
  end
71
80
 
72
81
  def is_simple?
73
- @zgeometry.is_simple?
82
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
83
+ simple?
74
84
  end
75
85
 
76
86
  def boundary
@@ -222,12 +232,22 @@ module RGeo
222
232
  point_n(num_points - 1)
223
233
  end
224
234
 
235
+ def closed?
236
+ @zgeometry.closed?
237
+ end
238
+
225
239
  def is_closed?
226
- @zgeometry.is_closed?
240
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
241
+ closed?
242
+ end
243
+
244
+ def ring?
245
+ @zgeometry.ring?
227
246
  end
228
247
 
229
248
  def is_ring?
230
- @zgeometry.is_ring?
249
+ warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
250
+ ring?
231
251
  end
232
252
 
233
253
  def num_points
@@ -323,8 +343,13 @@ module RGeo
323
343
  @zgeometry.length
324
344
  end
325
345
 
346
+ def closed?
347
+ @zgeometry.closed?
348
+ end
349
+
326
350
  def is_closed?
327
- @zgeometry.is_closed?
351
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
352
+ closed?
328
353
  end
329
354
 
330
355
  def coordinates
data/lib/rgeo/geos.rb CHANGED
@@ -21,24 +21,24 @@
21
21
 
22
22
  module RGeo
23
23
  module Geos
24
- require "rgeo/geos/utils"
25
- require "rgeo/geos/interface"
24
+ require_relative "geos/utils"
25
+ require_relative "geos/interface"
26
26
  begin
27
- require "rgeo/geos/geos_c_impl"
27
+ require_relative "geos/geos_c_impl"
28
28
  rescue LoadError
29
29
  # continue
30
30
  end
31
31
  CAPI_SUPPORTED = RGeo::Geos.const_defined?(:CAPIGeometryMethods)
32
32
  if CAPI_SUPPORTED
33
- require "rgeo/geos/capi_feature_classes"
34
- require "rgeo/geos/capi_factory"
33
+ require_relative "geos/capi_feature_classes"
34
+ require_relative "geos/capi_factory"
35
35
  end
36
- require "rgeo/geos/ffi_feature_methods"
37
- require "rgeo/geos/ffi_feature_classes"
38
- require "rgeo/geos/ffi_factory"
39
- require "rgeo/geos/zm_feature_methods"
40
- require "rgeo/geos/zm_feature_classes"
41
- require "rgeo/geos/zm_factory"
36
+ require_relative "geos/ffi_feature_methods"
37
+ require_relative "geos/ffi_feature_classes"
38
+ require_relative "geos/ffi_factory"
39
+ require_relative "geos/zm_feature_methods"
40
+ require_relative "geos/zm_feature_classes"
41
+ require_relative "geos/zm_factory"
42
42
 
43
43
  # Determine ffi support.
44
44
  begin
@@ -9,6 +9,8 @@
9
9
  module RGeo
10
10
  module ImplHelper # :nodoc:
11
11
  module BasicGeometryCollectionMethods # :nodoc:
12
+ include Enumerable
13
+
12
14
  attr_reader :elements
13
15
 
14
16
  def initialize(factory, elements)
@@ -37,6 +39,10 @@ module RGeo
37
39
  @elements.each(&block)
38
40
  end
39
41
 
42
+ def geometries
43
+ @elements
44
+ end
45
+
40
46
  def dimension
41
47
  @dimension ||= @elements.map(&:dimension).max || -1
42
48
  end
@@ -45,10 +51,15 @@ module RGeo
45
51
  Feature::GeometryCollection
46
52
  end
47
53
 
48
- def is_empty?
54
+ def empty?
49
55
  @elements.size == 0
50
56
  end
51
57
 
58
+ def is_empty?
59
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
60
+ empty?
61
+ end
62
+
52
63
  def rep_equals?(rhs)
53
64
  if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @elements.size == rhs.num_geometries
54
65
  rhs.each_with_index { |p, i| return false unless @elements[i].rep_equals?(p) }
@@ -87,8 +98,13 @@ module RGeo
87
98
  Feature::MultiLineString
88
99
  end
89
100
 
101
+ def closed?
102
+ all?(&:closed?)
103
+ end
104
+
90
105
  def is_closed?
91
- all?(&:is_closed?)
106
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
107
+ closed?
92
108
  end
93
109
 
94
110
  def length
@@ -98,7 +114,7 @@ module RGeo
98
114
  def boundary
99
115
  hash = {}
100
116
  @elements.each do |line|
101
- if !line.is_empty? && !line.is_closed?
117
+ if !line.empty? && !line.closed?
102
118
  add_boundary(hash, line.start_point)
103
119
  add_boundary(hash, line.end_point)
104
120
  end
@@ -114,6 +130,12 @@ module RGeo
114
130
  @elements.map(&:coordinates)
115
131
  end
116
132
 
133
+ def contains?(rhs)
134
+ return super unless Feature::Point === rhs
135
+
136
+ @elements.any? { |line| line.contains?(rhs) }
137
+ end
138
+
117
139
  private
118
140
 
119
141
  def add_boundary(hash, point)
@@ -168,15 +190,21 @@ module RGeo
168
190
  def boundary
169
191
  array = []
170
192
  @elements.each do |poly|
171
- array << poly.exterior_ring unless poly.is_empty?
193
+ array << poly.exterior_ring unless poly.empty?
172
194
  array.concat(poly.interior_rings)
173
195
  end
174
- factory.multilinestring(array)
196
+ factory.multi_line_string(array)
175
197
  end
176
198
 
177
199
  def coordinates
178
200
  @elements.map(&:coordinates)
179
201
  end
202
+
203
+ def contains?(rhs)
204
+ return super unless Feature::Point === rhs
205
+
206
+ @elements.any? { |poly| poly.contains?(rhs) }
207
+ end
180
208
  end
181
209
  end
182
210
  end