rgeo 2.3.0 → 3.0.0.pre.rc.1

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +1 -0
  4. data/ext/geos_c_impl/analysis.c +8 -6
  5. data/ext/geos_c_impl/analysis.h +1 -3
  6. data/ext/geos_c_impl/errors.c +10 -8
  7. data/ext/geos_c_impl/errors.h +7 -3
  8. data/ext/geos_c_impl/extconf.rb +3 -0
  9. data/ext/geos_c_impl/factory.c +251 -182
  10. data/ext/geos_c_impl/factory.h +43 -62
  11. data/ext/geos_c_impl/geometry.c +56 -24
  12. data/ext/geos_c_impl/geometry.h +8 -3
  13. data/ext/geos_c_impl/geometry_collection.c +41 -148
  14. data/ext/geos_c_impl/geometry_collection.h +1 -14
  15. data/ext/geos_c_impl/globals.c +91 -0
  16. data/ext/geos_c_impl/globals.h +45 -0
  17. data/ext/geos_c_impl/line_string.c +28 -29
  18. data/ext/geos_c_impl/line_string.h +1 -3
  19. data/ext/geos_c_impl/main.c +10 -9
  20. data/ext/geos_c_impl/point.c +9 -8
  21. data/ext/geos_c_impl/point.h +1 -3
  22. data/ext/geos_c_impl/polygon.c +15 -51
  23. data/ext/geos_c_impl/polygon.h +1 -3
  24. data/ext/geos_c_impl/preface.h +8 -0
  25. data/lib/rgeo/cartesian/analysis.rb +2 -2
  26. data/lib/rgeo/cartesian/calculations.rb +54 -17
  27. data/lib/rgeo/cartesian/factory.rb +0 -7
  28. data/lib/rgeo/cartesian/feature_classes.rb +66 -46
  29. data/lib/rgeo/cartesian/feature_methods.rb +56 -20
  30. data/lib/rgeo/cartesian/interface.rb +0 -6
  31. data/lib/rgeo/cartesian/planar_graph.rb +379 -0
  32. data/lib/rgeo/cartesian/sweepline_intersector.rb +149 -0
  33. data/lib/rgeo/cartesian/valid_op.rb +71 -0
  34. data/lib/rgeo/cartesian.rb +3 -0
  35. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +6 -6
  36. data/lib/rgeo/error.rb +15 -0
  37. data/lib/rgeo/feature/curve.rb +12 -2
  38. data/lib/rgeo/feature/geometry.rb +38 -28
  39. data/lib/rgeo/feature/geometry_collection.rb +13 -5
  40. data/lib/rgeo/feature/line_string.rb +3 -3
  41. data/lib/rgeo/feature/multi_curve.rb +6 -1
  42. data/lib/rgeo/feature/multi_surface.rb +3 -3
  43. data/lib/rgeo/feature/point.rb +4 -4
  44. data/lib/rgeo/feature/surface.rb +3 -3
  45. data/lib/rgeo/geographic/factory.rb +0 -7
  46. data/lib/rgeo/geographic/interface.rb +4 -18
  47. data/lib/rgeo/geographic/proj4_projector.rb +0 -2
  48. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  49. data/lib/rgeo/geographic/projected_feature_methods.rb +63 -30
  50. data/lib/rgeo/geographic/simple_mercator_projector.rb +0 -2
  51. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  52. data/lib/rgeo/geographic/spherical_feature_methods.rb +68 -2
  53. data/lib/rgeo/geos/capi_factory.rb +21 -31
  54. data/lib/rgeo/geos/capi_feature_classes.rb +64 -11
  55. data/lib/rgeo/geos/ffi_factory.rb +0 -28
  56. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  57. data/lib/rgeo/geos/ffi_feature_methods.rb +53 -10
  58. data/lib/rgeo/geos/interface.rb +18 -10
  59. data/lib/rgeo/geos/zm_factory.rb +0 -12
  60. data/lib/rgeo/geos/zm_feature_methods.rb +30 -5
  61. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +18 -8
  62. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -1
  63. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +37 -26
  64. data/lib/rgeo/impl_helper/basic_point_methods.rb +13 -3
  65. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +8 -3
  66. data/lib/rgeo/impl_helper/valid_op.rb +354 -0
  67. data/lib/rgeo/impl_helper/validity_check.rb +138 -0
  68. data/lib/rgeo/impl_helper.rb +1 -0
  69. data/lib/rgeo/version.rb +1 -1
  70. data/lib/rgeo/wkrep/wkb_generator.rb +1 -1
  71. data/lib/rgeo/wkrep/wkt_generator.rb +6 -6
  72. metadata +30 -7
@@ -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
 
@@ -101,13 +116,6 @@ module RGeo
101
116
  # Specifies which native interface to use. Possible values are
102
117
  # <tt>:capi</tt> and <tt>:ffi</tt>. The default is the value
103
118
  # of the preferred_native_interface.
104
- # [<tt>:uses_lenient_multi_polygon_assertions</tt>]
105
- # If set to true, assertion checking on MultiPolygon is disabled.
106
- # This may speed up creation of MultiPolygon objects, at the
107
- # expense of not doing the proper checking for OGC MultiPolygon
108
- # compliance. See RGeo::Feature::MultiPolygon for details on
109
- # the MultiPolygon assertions. Default is false. Also called
110
- # <tt>:lenient_multi_polygon_assertions</tt>.
111
119
  # [<tt>:buffer_resolution</tt>]
112
120
  # The resolution of buffers around geometries created by this
113
121
  # factory. This controls the number of line segments used to
@@ -53,8 +53,6 @@ module RGeo
53
53
  end
54
54
  srid ||= coord_sys.authority_code if coord_sys
55
55
  config = {
56
- uses_lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions] ||
57
- opts[:uses_lenient_multi_polygon_assertions],
58
56
  buffer_resolution: opts[:buffer_resolution], auto_prepare: opts[:auto_prepare],
59
57
  wkt_generator: opts[:wkt_generator], wkt_parser: opts[:wkt_parser],
60
58
  wkb_generator: opts[:wkb_generator], wkb_parser: opts[:wkb_parser],
@@ -109,7 +107,6 @@ module RGeo
109
107
  "wkbg" => @wkb_generator.properties,
110
108
  "wktp" => @wkt_parser.properties,
111
109
  "wkbp" => @wkb_parser.properties,
112
- "lmpa" => @zfactory.lenient_multi_polygon_assertions?,
113
110
  "apre" => @zfactory.property(:auto_prepare) == :simple,
114
111
  "nffi" => @zfactory.is_a?(FFIFactory)
115
112
  }
@@ -142,7 +139,6 @@ module RGeo
142
139
  wkb_generator: symbolize_hash(data["wkbg"]),
143
140
  wkt_parser: symbolize_hash(data["wktp"]),
144
141
  wkb_parser: symbolize_hash(data["wkbp"]),
145
- uses_lenient_multi_polygon_assertions: data["lmpa"],
146
142
  auto_prepare: (data["apre"] ? :simple : :disabled),
147
143
  proj4: proj4,
148
144
  coord_sys: coord_sys
@@ -154,7 +150,6 @@ module RGeo
154
150
  def encode_with(coder) # :nodoc:
155
151
  coder["srid"] = @zfactory.srid
156
152
  coder["buffer_resolution"] = @zfactory.buffer_resolution
157
- coder["lenient_multi_polygon_assertions"] = @zfactory.lenient_multi_polygon_assertions?
158
153
  coder["wkt_generator"] = @wkt_generator.properties
159
154
  coder["wkb_generator"] = @wkb_generator.properties
160
155
  coder["wkt_parser"] = @wkt_parser.properties
@@ -197,7 +192,6 @@ module RGeo
197
192
  wkt_parser: symbolize_hash(coder["wkt_parser"]),
198
193
  wkb_parser: symbolize_hash(coder["wkb_parser"]),
199
194
  auto_prepare: coder["auto_prepare"] == "disabled" ? :disabled : :simple,
200
- uses_lenient_multi_polygon_assertions: coder["lenient_multi_polygon_assertions"],
201
195
  proj4: proj4,
202
196
  coord_sys: coord_sys
203
197
  )
@@ -216,12 +210,6 @@ module RGeo
216
210
  @zfactory.buffer_resolution
217
211
  end
218
212
 
219
- # Returns true if this factory is lenient with MultiPolygon assertions
220
-
221
- def lenient_multi_polygon_assertions?
222
- @zfactory.lenient_multi_polygon_assertions?
223
- end
224
-
225
213
  # Returns the z-only factory corresponding to this factory.
226
214
 
227
215
  def z_factory
@@ -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
@@ -20,7 +20,7 @@ module RGeo
20
20
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
21
21
  elem
22
22
  end
23
- validate_geometry
23
+ init_geometry
24
24
  end
25
25
 
26
26
  def num_geometries
@@ -51,10 +51,15 @@ module RGeo
51
51
  Feature::GeometryCollection
52
52
  end
53
53
 
54
- def is_empty?
54
+ def empty?
55
55
  @elements.size == 0
56
56
  end
57
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
+
58
63
  def rep_equals?(rhs)
59
64
  if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @elements.size == rhs.num_geometries
60
65
  rhs.each_with_index { |p, i| return false unless @elements[i].rep_equals?(p) }
@@ -86,15 +91,20 @@ module RGeo
86
91
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
87
92
  elem
88
93
  end
89
- validate_geometry
94
+ init_geometry
90
95
  end
91
96
 
92
97
  def geometry_type
93
98
  Feature::MultiLineString
94
99
  end
95
100
 
101
+ def closed?
102
+ all?(&:closed?)
103
+ end
104
+
96
105
  def is_closed?
97
- 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?
98
108
  end
99
109
 
100
110
  def length
@@ -104,7 +114,7 @@ module RGeo
104
114
  def boundary
105
115
  hash = {}
106
116
  @elements.each do |line|
107
- if !line.is_empty? && !line.is_closed?
117
+ if !line.empty? && !line.closed?
108
118
  add_boundary(hash, line.start_point)
109
119
  add_boundary(hash, line.end_point)
110
120
  end
@@ -142,7 +152,7 @@ module RGeo
142
152
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
143
153
  elem
144
154
  end
145
- validate_geometry
155
+ init_geometry
146
156
  end
147
157
 
148
158
  def geometry_type
@@ -166,7 +176,7 @@ module RGeo
166
176
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
167
177
  elem
168
178
  end
169
- validate_geometry
179
+ init_geometry
170
180
  end
171
181
 
172
182
  def geometry_type
@@ -180,7 +190,7 @@ module RGeo
180
190
  def boundary
181
191
  array = []
182
192
  @elements.each do |poly|
183
- array << poly.exterior_ring unless poly.is_empty?
193
+ array << poly.exterior_ring unless poly.empty?
184
194
  array.concat(poly.interior_rings)
185
195
  end
186
196
  factory.multi_line_string(array)
@@ -52,7 +52,7 @@ module RGeo
52
52
  @factory = obj.factory
53
53
  end
54
54
 
55
- def validate_geometry
55
+ def init_geometry
56
56
  end
57
57
  end
58
58
  end
@@ -16,7 +16,13 @@ module RGeo
16
16
  raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
17
17
  elem
18
18
  end
19
- validate_geometry
19
+ # LineStrings in general need to check that there's not one point
20
+ # GEOS doesn't allow instantiation of single point LineStrings so
21
+ # we should handle it.
22
+ if @points.size == 1
23
+ raise Error::InvalidGeometry, "LineString Cannot Have 1 Point"
24
+ end
25
+ init_geometry
20
26
  end
21
27
 
22
28
  def num_points
@@ -39,13 +45,18 @@ module RGeo
39
45
  Feature::LineString
40
46
  end
41
47
 
42
- def is_empty?
48
+ def empty?
43
49
  @points.size == 0
44
50
  end
45
51
 
52
+ def is_empty?
53
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
54
+ empty?
55
+ end
56
+
46
57
  def boundary
47
58
  array = []
48
- array << @points.first << @points.last if !is_empty? && !is_closed?
59
+ array << @points.first << @points.last if !empty? && !closed?
49
60
  factory.multipoint([array])
50
61
  end
51
62
 
@@ -57,15 +68,25 @@ module RGeo
57
68
  @points.last
58
69
  end
59
70
 
60
- def is_closed?
61
- unless defined?(@is_closed)
62
- @is_closed = @points.size > 2 && @points.first == @points.last
71
+ def closed?
72
+ unless defined?(@closed)
73
+ @closed = @points.size > 2 && @points.first == @points.last
63
74
  end
64
- @is_closed
75
+ @closed
76
+ end
77
+
78
+ def is_closed?
79
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
80
+ closed?
81
+ end
82
+
83
+ def ring?
84
+ closed? && simple?
65
85
  end
66
86
 
67
87
  def is_ring?
68
- is_closed? && is_simple?
88
+ warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
89
+ ring?
69
90
  end
70
91
 
71
92
  def rep_equals?(rhs)
@@ -128,12 +149,6 @@ module RGeo
128
149
  super
129
150
  @points = obj.points
130
151
  end
131
-
132
- def validate_geometry
133
- if @points.size == 1
134
- raise Error::InvalidGeometry, "LineString cannot have 1 point"
135
- end
136
- end
137
152
  end
138
153
 
139
154
  module BasicLineMethods # :nodoc:
@@ -146,7 +161,7 @@ module RGeo
146
161
  cstop = Feature.cast(stop, factory, Feature::Point)
147
162
  raise Error::InvalidGeometry, "Could not cast end: #{stop}" unless cstop
148
163
  @points = [cstart, cstop]
149
- validate_geometry
164
+ init_geometry
150
165
  end
151
166
 
152
167
  def geometry_type
@@ -156,18 +171,16 @@ module RGeo
156
171
  def coordinates
157
172
  @points.map(&:coordinates)
158
173
  end
174
+ end
159
175
 
160
- private
161
-
162
- def validate_geometry
176
+ module BasicLinearRingMethods # :nodoc:
177
+ def initialize(factory, points)
163
178
  super
164
- if @points.size > 2
165
- raise Error::InvalidGeometry, "Line must have 0 or 2 points"
179
+ unless @points.size >= 4 || @points.size == 0
180
+ raise Error::InvalidGeometry, "LinearRings must have 0 or >= 4 points"
166
181
  end
167
182
  end
168
- end
169
183
 
170
- module BasicLinearRingMethods # :nodoc:
171
184
  def geometry_type
172
185
  Feature::LinearRing
173
186
  end
@@ -178,14 +191,12 @@ module RGeo
178
191
 
179
192
  private
180
193
 
181
- def validate_geometry
194
+ # Close ring if necessary.
195
+ def init_geometry
182
196
  super
183
197
  if @points.size > 0
184
198
  @points << @points.first if @points.first != @points.last
185
199
  @points = @points.chunk { |x| x }.map(&:first)
186
- if !@factory.property(:uses_lenient_assertions) && !is_ring?
187
- raise Error::InvalidGeometry, "LinearRing failed ring test"
188
- end
189
200
  end
190
201
  end
191
202
  end
@@ -18,7 +18,7 @@ module RGeo
18
18
  if extra.size > 0
19
19
  raise ArgumentError, "Too many arguments for point initializer"
20
20
  end
21
- validate_geometry
21
+ init_geometry
22
22
  end
23
23
 
24
24
  def x
@@ -45,14 +45,24 @@ module RGeo
45
45
  Feature::Point
46
46
  end
47
47
 
48
- def is_empty?
48
+ def empty?
49
49
  false
50
50
  end
51
51
 
52
- def is_simple?
52
+ def is_empty?
53
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
54
+ empty?
55
+ end
56
+
57
+ def simple?
53
58
  true
54
59
  end
55
60
 
61
+ def is_simple?
62
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
63
+ simple?
64
+ end
65
+
56
66
  def envelope
57
67
  self
58
68
  end
@@ -22,7 +22,7 @@ module RGeo
22
22
  end
23
23
  elem
24
24
  end
25
- validate_geometry
25
+ init_geometry
26
26
  end
27
27
 
28
28
  def exterior_ring
@@ -49,13 +49,18 @@ module RGeo
49
49
  Feature::Polygon
50
50
  end
51
51
 
52
+ def empty?
53
+ @exterior_ring.empty?
54
+ end
55
+
52
56
  def is_empty?
53
- @exterior_ring.is_empty?
57
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
58
+ empty?
54
59
  end
55
60
 
56
61
  def boundary
57
62
  array = []
58
- array << @exterior_ring unless @exterior_ring.is_empty?
63
+ array << @exterior_ring unless @exterior_ring.empty?
59
64
  array.concat(@interior_rings)
60
65
  factory.multi_line_string(array)
61
66
  end