rgeo 2.3.1 → 3.0.0.pre.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +11 -10
  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 +273 -202
  10. data/ext/geos_c_impl/factory.h +51 -63
  11. data/ext/geos_c_impl/geometry.c +124 -22
  12. data/ext/geos_c_impl/geometry.h +8 -3
  13. data/ext/geos_c_impl/geometry_collection.c +81 -185
  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 +43 -72
  23. data/ext/geos_c_impl/polygon.h +1 -3
  24. data/ext/geos_c_impl/preface.h +12 -0
  25. data/ext/geos_c_impl/ruby_more.c +65 -0
  26. data/ext/geos_c_impl/ruby_more.h +16 -0
  27. data/lib/rgeo/cartesian/calculations.rb +54 -17
  28. data/lib/rgeo/cartesian/factory.rb +6 -14
  29. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  30. data/lib/rgeo/cartesian/feature_methods.rb +67 -20
  31. data/lib/rgeo/cartesian/interface.rb +0 -36
  32. data/lib/rgeo/cartesian/planar_graph.rb +379 -0
  33. data/lib/rgeo/cartesian/sweepline_intersector.rb +149 -0
  34. data/lib/rgeo/cartesian/valid_op.rb +71 -0
  35. data/lib/rgeo/cartesian.rb +3 -0
  36. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +6 -6
  37. data/lib/rgeo/coord_sys.rb +0 -11
  38. data/lib/rgeo/error.rb +15 -0
  39. data/lib/rgeo/feature/factory_generator.rb +0 -3
  40. data/lib/rgeo/feature/geometry.rb +107 -28
  41. data/lib/rgeo/feature/geometry_collection.rb +13 -5
  42. data/lib/rgeo/feature/line_string.rb +3 -3
  43. data/lib/rgeo/feature/multi_surface.rb +3 -3
  44. data/lib/rgeo/feature/point.rb +4 -4
  45. data/lib/rgeo/feature/surface.rb +3 -3
  46. data/lib/rgeo/geographic/factory.rb +6 -7
  47. data/lib/rgeo/geographic/interface.rb +6 -49
  48. data/lib/rgeo/geographic/proj4_projector.rb +0 -2
  49. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  50. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -28
  51. data/lib/rgeo/geographic/simple_mercator_projector.rb +0 -2
  52. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  53. data/lib/rgeo/geographic/spherical_feature_methods.rb +79 -2
  54. data/lib/rgeo/geos/capi_factory.rb +21 -38
  55. data/lib/rgeo/geos/capi_feature_classes.rb +54 -11
  56. data/lib/rgeo/geos/ffi_factory.rb +6 -35
  57. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  58. data/lib/rgeo/geos/ffi_feature_methods.rb +39 -5
  59. data/lib/rgeo/geos/interface.rb +0 -24
  60. data/lib/rgeo/geos/zm_factory.rb +0 -19
  61. data/lib/rgeo/geos/zm_feature_methods.rb +16 -0
  62. data/lib/rgeo/geos.rb +6 -3
  63. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +4 -4
  64. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -1
  65. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +15 -19
  66. data/lib/rgeo/impl_helper/basic_point_methods.rb +1 -1
  67. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +1 -1
  68. data/lib/rgeo/impl_helper/valid_op.rb +354 -0
  69. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  70. data/lib/rgeo/impl_helper.rb +1 -0
  71. data/lib/rgeo/version.rb +1 -1
  72. metadata +45 -9
  73. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  74. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  75. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -54,12 +54,6 @@ module RGeo
54
54
  # Support a Z coordinate. Default is false.
55
55
  # [<tt>:has_m_coordinate</tt>]
56
56
  # Support an M coordinate. Default is false.
57
- # [<tt>:uses_lenient_assertions</tt>]
58
- # If set to true, assertion checking is disabled. This includes
59
- # simplicity checking on LinearRing, and validity checks on
60
- # Polygon and MultiPolygon. This may speed up creation of certain
61
- # objects, at the expense of not doing the proper checking for
62
- # OGC compliance. Default is false.
63
57
  # [<tt>:buffer_resolution</tt>]
64
58
  # The resolution of buffers around geometries created by this
65
59
  # factory. This controls the number of line segments used to
@@ -89,11 +83,6 @@ module RGeo
89
83
  # visualization crs". You may alternatively wish to set the srid
90
84
  # to 4326, indicating the WGS84 crs, but note that that value
91
85
  # implies an ellipsoidal datum, not a spherical datum.
92
- # [<tt>:srs_database</tt>]
93
- # Optional. If provided, the object should respond to #get and
94
- # #clear_cache. If both this and an SRID are
95
- # provided, they are used to look up the proj4 and coord_sys
96
- # objects from a spatial reference system database.
97
86
  # [<tt>:wkt_parser</tt>]
98
87
  # Configure the parser for WKT. The value is a hash of
99
88
  # configuration parameters for WKRep::WKTParser.new. Default is
@@ -118,20 +107,12 @@ module RGeo
118
107
  proj4 = opts[:proj4]
119
108
  coord_sys = opts[:coord_sys]
120
109
  srid = opts[:srid]
121
- if (!proj4 || !coord_sys) && srid && (db_ = opts[:srs_database])
122
- entry_ = db_.get(srid.to_i)
123
- if entry_
124
- proj4 ||= entry_.proj4
125
- coord_sys ||= entry_.coord_sys
126
- end
127
- end
128
110
  srid ||= coord_sys.authority_code if coord_sys
129
111
  Geographic::Factory.new("Spherical",
130
112
  has_z_coordinate: opts[:has_z_coordinate],
131
113
  has_m_coordinate: opts[:has_m_coordinate],
132
114
  proj4: proj4 || proj_4055,
133
115
  coord_sys: coord_sys || coord_sys_4055,
134
- uses_lenient_assertions: opts[:uses_lenient_assertions],
135
116
  buffer_resolution: opts[:buffer_resolution],
136
117
  wkt_parser: opts[:wkt_parser],
137
118
  wkb_parser: opts[:wkb_parser],
@@ -207,10 +188,8 @@ module RGeo
207
188
  #
208
189
  # You may also provide options understood by the underlying
209
190
  # projected Cartesian factory. For example, if GEOS is used for the
210
- # projected factory, you may also set the
211
- # <tt>:lenient_multi_polygon_assertions</tt> and
212
- # <tt>:buffer_resolution</tt> options. See RGeo::Geos.factory for
213
- # more details.
191
+ # projected factory, you may also set the <tt>:buffer_resolution</tt>
192
+ # options. See RGeo::Geos.factory for more details.
214
193
 
215
194
  def simple_mercator_factory(opts = {})
216
195
  factory = Geographic::Factory.new("Projected",
@@ -222,12 +201,9 @@ module RGeo
222
201
  wkt_generator: opts[:wkt_generator],
223
202
  wkb_generator: opts[:wkb_generator],
224
203
  has_z_coordinate: opts[:has_z_coordinate],
225
- has_m_coordinate: opts[:has_m_coordinate],
226
- uses_lenient_assertions: opts[:uses_lenient_assertions])
204
+ has_m_coordinate: opts[:has_m_coordinate])
227
205
  projector = Geographic::SimpleMercatorProjector.new(factory,
228
206
  buffer_resolution: opts[:buffer_resolution],
229
- lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions],
230
- uses_lenient_assertions: opts[:uses_lenient_assertions],
231
207
  has_z_coordinate: opts[:has_z_coordinate],
232
208
  has_m_coordinate: opts[:has_m_coordinate])
233
209
  factory.projector = projector
@@ -259,9 +235,7 @@ module RGeo
259
235
  # and let this method construct a projection factory for you (which
260
236
  # it will do using the preferred Cartesian factory generator).
261
237
  # If you choose this second method, you may provide the proj4
262
- # directly via the <tt>:projection_proj4</tt> option, or indirectly
263
- # by providing both an <tt>:srid</tt> and a <tt>:srs_database</tt>
264
- # to use to look up the coordinate system.
238
+ # via the <tt>:projection_proj4</tt> option.
265
239
  #
266
240
  # Following are detailed descriptions of the various options you can
267
241
  # pass to this method.
@@ -304,11 +278,6 @@ module RGeo
304
278
  # The SRID value to use for the main geographic factory. Defaults
305
279
  # to the given geographic coordinate system's authority code, or
306
280
  # to 0 if no geographic coordinate system is known.
307
- # [<tt>:srs_database</tt>]
308
- # Optional. If provided, the object should respond to #get and
309
- # #clear_cache. If both this and an SRID are
310
- # provided, they are used to look up the proj4 and coord_sys
311
- # objects from a spatial reference system database.
312
281
  # [<tt>:has_z_coordinate</tt>]
313
282
  # Support a Z coordinate. Default is false.
314
283
  # Note: this is ignored if a <tt>:projection_factory</tt> is
@@ -342,13 +311,11 @@ module RGeo
342
311
  # If a <tt>:projection_factory</tt> is _not_ provided, you may also
343
312
  # provide options for configuring the projected Cartesian factory.
344
313
  # For example, if GEOS is used for the projected factory, you may
345
- # also set the <tt>:lenient_multi_polygon_assertions</tt> and
346
- # <tt>:buffer_resolution</tt> options. See RGeo::Geos.factory for
347
- # more details.
314
+ # also set the <tt>:buffer_resolution</tt> option. See RGeo::Geos.factory
315
+ # for more details.
348
316
 
349
317
  def projected_factory(opts = {})
350
318
  CoordSys.check!(:proj4)
351
- db_ = opts[:srs_database]
352
319
  if (projection_factory = opts[:projection_factory])
353
320
  # Get the projection coordinate systems from the given factory
354
321
  projection_proj4 = projection_factory.proj4
@@ -363,14 +330,6 @@ module RGeo
363
330
  proj4 = opts[:proj4]
364
331
  coord_sys = opts[:coord_sys]
365
332
  srid = opts[:srid]
366
- # Lookup srid from srs database if needed
367
- if (!proj4 || !coord_sys) && srid && db_
368
- entry_ = db_.get(srid.to_i)
369
- if entry_
370
- proj4 ||= entry_.proj4
371
- coord_sys ||= entry_.coord_sys
372
- end
373
- end
374
333
  # Fall back to getting the values from the projection.
375
334
  proj4 ||= projection_proj4.get_geographic || _proj_4326
376
335
  coord_sys ||= projection_coord_sys.geographic_coordinate_system if projection_coord_sys
@@ -447,8 +406,6 @@ module RGeo
447
406
  srid: projection_srid,
448
407
  coord_sys: projection_coord_sys,
449
408
  buffer_resolution: opts[:buffer_resolution],
450
- lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions],
451
- uses_lenient_assertions: opts[:uses_lenient_assertions],
452
409
  has_z_coordinate: opts[:has_z_coordinate],
453
410
  has_m_coordinate: opts[:has_m_coordinate],
454
411
  wkt_parser: opts[:wkt_parser], wkt_generator: opts[:wkt_generator],
@@ -48,8 +48,6 @@ module RGeo
48
48
  proj4: proj4,
49
49
  coord_sys: opts[:coord_sys], srid: opts[:srid],
50
50
  buffer_resolution: opts[:buffer_resolution],
51
- lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions],
52
- uses_lenient_assertions: opts[:uses_lenient_assertions],
53
51
  has_z_coordinate: opts[:has_z_coordinate],
54
52
  has_m_coordinate: opts[:has_m_coordinate],
55
53
  wkt_parser: opts[:wkt_parser], wkt_generator: opts[:wkt_generator],
@@ -8,16 +8,18 @@
8
8
 
9
9
  module RGeo
10
10
  module Geographic
11
- class ProjectedPointImpl # :nodoc:
11
+ class ProjectedPointImpl
12
12
  include Feature::Point
13
+ include ImplHelper::ValidityCheck
13
14
  include ImplHelper::BasicGeometryMethods
14
15
  include ImplHelper::BasicPointMethods
15
16
  include ProjectedGeometryMethods
16
17
  include ProjectedPointMethods
17
18
  end
18
19
 
19
- class ProjectedLineStringImpl # :nodoc:
20
+ class ProjectedLineStringImpl
20
21
  include Feature::LineString
22
+ include ImplHelper::ValidityCheck
21
23
  include ImplHelper::BasicGeometryMethods
22
24
  include ImplHelper::BasicLineStringMethods
23
25
  include ProjectedGeometryMethods
@@ -25,18 +27,21 @@ module RGeo
25
27
  include ProjectedLineStringMethods
26
28
  end
27
29
 
28
- class ProjectedLinearRingImpl # :nodoc:
30
+ class ProjectedLinearRingImpl
29
31
  include Feature::LinearRing
32
+ include ImplHelper::ValidityCheck
30
33
  include ImplHelper::BasicGeometryMethods
31
34
  include ImplHelper::BasicLineStringMethods
32
35
  include ImplHelper::BasicLinearRingMethods
33
36
  include ProjectedGeometryMethods
34
37
  include ProjectedNCurveMethods
35
38
  include ProjectedLineStringMethods
39
+ include ProjectedLinearRingMethods
36
40
  end
37
41
 
38
- class ProjectedLineImpl # :nodoc:
42
+ class ProjectedLineImpl
39
43
  include Feature::Line
44
+ include ImplHelper::ValidityCheck
40
45
  include ImplHelper::BasicGeometryMethods
41
46
  include ImplHelper::BasicLineStringMethods
42
47
  include ImplHelper::BasicLineMethods
@@ -45,8 +50,9 @@ module RGeo
45
50
  include ProjectedLineStringMethods
46
51
  end
47
52
 
48
- class ProjectedPolygonImpl # :nodoc:
53
+ class ProjectedPolygonImpl
49
54
  include Feature::Polygon
55
+ include ImplHelper::ValidityCheck
50
56
  include ImplHelper::BasicGeometryMethods
51
57
  include ImplHelper::BasicPolygonMethods
52
58
  include ProjectedGeometryMethods
@@ -54,23 +60,26 @@ module RGeo
54
60
  include ProjectedPolygonMethods
55
61
  end
56
62
 
57
- class ProjectedGeometryCollectionImpl # :nodoc:
63
+ class ProjectedGeometryCollectionImpl
58
64
  include Feature::GeometryCollection
65
+ include ImplHelper::ValidityCheck
59
66
  include ImplHelper::BasicGeometryMethods
60
67
  include ImplHelper::BasicGeometryCollectionMethods
61
68
  include ProjectedGeometryMethods
62
69
  end
63
70
 
64
- class ProjectedMultiPointImpl # :nodoc:
71
+ class ProjectedMultiPointImpl
65
72
  include Feature::MultiPoint
73
+ include ImplHelper::ValidityCheck
66
74
  include ImplHelper::BasicGeometryMethods
67
75
  include ImplHelper::BasicGeometryCollectionMethods
68
76
  include ImplHelper::BasicMultiPointMethods
69
77
  include ProjectedGeometryMethods
70
78
  end
71
79
 
72
- class ProjectedMultiLineStringImpl # :nodoc:
80
+ class ProjectedMultiLineStringImpl
73
81
  include Feature::MultiLineString
82
+ include ImplHelper::ValidityCheck
74
83
  include ImplHelper::BasicGeometryMethods
75
84
  include ImplHelper::BasicGeometryCollectionMethods
76
85
  include ImplHelper::BasicMultiLineStringMethods
@@ -78,8 +87,9 @@ module RGeo
78
87
  include ProjectedNCurveMethods
79
88
  end
80
89
 
81
- class ProjectedMultiPolygonImpl # :nodoc:
90
+ class ProjectedMultiPolygonImpl
82
91
  include Feature::MultiPolygon
92
+ include ImplHelper::ValidityCheck
83
93
  include ImplHelper::BasicGeometryMethods
84
94
  include ImplHelper::BasicGeometryCollectionMethods
85
95
  include ImplHelper::BasicMultiPolygonMethods
@@ -87,5 +97,7 @@ module RGeo
87
97
  include ProjectedNSurfaceMethods
88
98
  include ProjectedMultiPolygonMethods
89
99
  end
100
+
101
+ ImplHelper::ValidityCheck.override_classes
90
102
  end
91
103
  end
@@ -19,7 +19,23 @@ module RGeo
19
19
  end
20
20
 
21
21
  def envelope
22
- factory.unproject(projection.envelope)
22
+ factory.unproject(projection.unsafe_envelope)
23
+ end
24
+
25
+ def coordinate_dimension
26
+ factory.coordinate_dimension
27
+ end
28
+
29
+ def spatial_dimension
30
+ factory.spatial_dimension
31
+ end
32
+
33
+ def is_3d?
34
+ factory.property(:has_z_coordinate)
35
+ end
36
+
37
+ def measured?
38
+ factory.property(:has_m_coordinate)
23
39
  end
24
40
 
25
41
  def empty?
@@ -40,8 +56,21 @@ module RGeo
40
56
  simple?
41
57
  end
42
58
 
59
+ def valid?
60
+ projection.valid?
61
+ end
62
+
63
+ def invalid_reason
64
+ projection.invalid_reason
65
+ end
66
+
67
+ # (see RGeo::ImplHelper::ValidityCheck#make_valid)
68
+ def make_valid
69
+ factory.unproject projection.make_valid
70
+ end
71
+
43
72
  def boundary
44
- boundary = projection.boundary
73
+ boundary = projection.unsafe_boundary
45
74
  boundary ? factory.unproject(boundary) : nil
46
75
  end
47
76
 
@@ -50,79 +79,79 @@ module RGeo
50
79
  end
51
80
 
52
81
  def disjoint?(rhs)
53
- projection.disjoint?(Feature.cast(rhs, factory).projection)
82
+ projection.unsafe_disjoint?(Feature.cast(rhs, factory).projection)
54
83
  end
55
84
 
56
85
  def intersects?(rhs)
57
- projection.intersects?(Feature.cast(rhs, factory).projection)
86
+ projection.unsafe_intersects?(Feature.cast(rhs, factory).projection)
58
87
  end
59
88
 
60
89
  def touches?(rhs)
61
- projection.touches?(Feature.cast(rhs, factory).projection)
90
+ projection.unsafe_touches?(Feature.cast(rhs, factory).projection)
62
91
  end
63
92
 
64
93
  def crosses?(rhs)
65
- projection.crosses?(Feature.cast(rhs, factory).projection)
94
+ projection.unsafe_crosses?(Feature.cast(rhs, factory).projection)
66
95
  end
67
96
 
68
97
  def within?(rhs)
69
- projection.within?(Feature.cast(rhs, factory).projection)
98
+ projection.unsafe_within?(Feature.cast(rhs, factory).projection)
70
99
  end
71
100
 
72
101
  def contains?(rhs)
73
- projection.contains?(Feature.cast(rhs, factory).projection)
102
+ projection.unsafe_contains?(Feature.cast(rhs, factory).projection)
74
103
  end
75
104
 
76
105
  def overlaps?(rhs)
77
- projection.overlaps?(Feature.cast(rhs, factory).projection)
106
+ projection.unsafe_overlaps?(Feature.cast(rhs, factory).projection)
78
107
  end
79
108
 
80
109
  def relate(rhs, pattern_)
81
- projection.relate(Feature.cast(rhs, factory).projection, pattern_)
110
+ projection.unsafe_relate(Feature.cast(rhs, factory).projection, pattern_)
82
111
  end
83
112
 
84
113
  def distance(rhs)
85
- projection.distance(Feature.cast(rhs, factory).projection)
114
+ projection.unsafe_distance(Feature.cast(rhs, factory).projection)
86
115
  end
87
116
 
88
117
  def buffer(distance)
89
- factory.unproject(projection.buffer(distance))
118
+ factory.unproject(projection.unsafe_buffer(distance))
90
119
  end
91
120
 
92
121
  def buffer_with_style(distance, end_cap_style, join_style, mitre_limit)
93
- factory.unproject(projection.buffer_with_style(distance, end_cap_style, join_style, mitre_limit))
122
+ factory.unproject(projection.unsafe_buffer_with_style(distance, end_cap_style, join_style, mitre_limit))
94
123
  end
95
124
 
96
125
  def simplify(tolerance)
97
- factory.unproject(projection.simplify(tolerance))
126
+ factory.unproject(projection.unsafe_simplify(tolerance))
98
127
  end
99
128
 
100
129
  def simplify_preserve_topology(tolerance)
101
- factory.unproject(projection.simplify_preserve_topology(tolerance))
130
+ factory.unproject(projection.unsafe_simplify_preserve_topology(tolerance))
102
131
  end
103
132
 
104
133
  def convex_hull
105
- factory.unproject(projection.convex_hull)
134
+ factory.unproject(projection.unsafe_convex_hull)
106
135
  end
107
136
 
108
137
  def intersection(rhs)
109
- factory.unproject(projection.intersection(Feature.cast(rhs, factory).projection))
138
+ factory.unproject(projection.unsafe_intersection(Feature.cast(rhs, factory).projection))
110
139
  end
111
140
 
112
141
  def union(rhs)
113
- factory.unproject(projection.union(Feature.cast(rhs, factory).projection))
142
+ factory.unproject(projection.unsafe_union(Feature.cast(rhs, factory).projection))
114
143
  end
115
144
 
116
145
  def difference(rhs)
117
- factory.unproject(projection.difference(Feature.cast(rhs, factory).projection))
146
+ factory.unproject(projection.unsafe_difference(Feature.cast(rhs, factory).projection))
118
147
  end
119
148
 
120
149
  def sym_difference(rhs)
121
- factory.unproject(projection.sym_difference(Feature.cast(rhs, factory).projection))
150
+ factory.unproject(projection.unsafe_sym_difference(Feature.cast(rhs, factory).projection))
122
151
  end
123
152
 
124
153
  def point_on_surface
125
- factory.unproject(projection.point_on_surface)
154
+ factory.unproject(projection.unsafe_point_on_surface)
126
155
  end
127
156
  end
128
157
 
@@ -154,7 +183,8 @@ module RGeo
154
183
 
155
184
  private
156
185
 
157
- def validate_geometry
186
+ # Ensure coordinates fall within a valid range.
187
+ def init_geometry
158
188
  @y = 85.0511287 if @y > 85.0511287
159
189
  @y = -85.0511287 if @y < -85.0511287
160
190
  super
@@ -163,33 +193,41 @@ module RGeo
163
193
 
164
194
  module ProjectedNCurveMethods # :nodoc:
165
195
  def length
166
- projection.length
196
+ projection.unsafe_length
167
197
  end
168
198
  end
169
199
 
170
200
  module ProjectedLineStringMethods # :nodoc:
171
201
  private
172
202
 
173
- def validate_geometry
203
+ # Ensure coordinates fall within a valid range.
204
+ def init_geometry
174
205
  @points = @points.map(&:canonical_point)
175
206
  super
176
207
  end
177
208
  end
178
209
 
210
+ module ProjectedLinearRingMethods # :nodoc:
211
+ def simple?
212
+ projection.valid?
213
+ end
214
+ end
215
+
179
216
  module ProjectedNSurfaceMethods # :nodoc:
180
217
  def area
181
- projection.area
218
+ projection.unsafe_area
182
219
  end
183
220
 
184
221
  def centroid
185
- factory.unproject(projection.centroid)
222
+ factory.unproject(projection.unsafe_centroid)
186
223
  end
187
224
  end
188
225
 
189
226
  module ProjectedPolygonMethods # :nodoc:
190
227
  private
191
228
 
192
- def validate_geometry
229
+ # Ensure projection is available.
230
+ def init_geometry
193
231
  super
194
232
  unless projection
195
233
  raise Error::InvalidGeometry, "Polygon failed assertions"
@@ -200,7 +238,8 @@ module RGeo
200
238
  module ProjectedMultiPolygonMethods # :nodoc:
201
239
  private
202
240
 
203
- def validate_geometry
241
+ # Ensure projection is available.
242
+ def init_geometry
204
243
  super
205
244
  unless projection
206
245
  raise Error::InvalidGeometry, "MultiPolygon failed assertions"
@@ -17,8 +17,6 @@ module RGeo
17
17
  proj4: SimpleMercatorProjector._proj4_3857,
18
18
  coord_sys: SimpleMercatorProjector._coordsys_3857,
19
19
  buffer_resolution: opts[:buffer_resolution],
20
- lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions],
21
- uses_lenient_assertions: opts[:uses_lenient_assertions],
22
20
  has_z_coordinate: opts[:has_z_coordinate],
23
21
  has_m_coordinate: opts[:has_m_coordinate])
24
22
  end
@@ -8,78 +8,98 @@
8
8
 
9
9
  module RGeo
10
10
  module Geographic
11
- class SphericalPointImpl # :nodoc:
11
+ class SphericalPointImpl
12
12
  include Feature::Point
13
+ include ImplHelper::ValidityCheck
13
14
  include ImplHelper::BasicGeometryMethods
14
15
  include ImplHelper::BasicPointMethods
16
+ include ImplHelper::ValidOp
15
17
  include SphericalGeometryMethods
16
18
  include SphericalPointMethods
17
19
  end
18
20
 
19
- class SphericalLineStringImpl # :nodoc:
21
+ class SphericalLineStringImpl
20
22
  include Feature::LineString
23
+ include ImplHelper::ValidityCheck
21
24
  include ImplHelper::BasicGeometryMethods
22
25
  include ImplHelper::BasicLineStringMethods
26
+ include ImplHelper::ValidOp
23
27
  include SphericalGeometryMethods
24
28
  include SphericalLineStringMethods
25
29
  end
26
30
 
27
- class SphericalLineImpl # :nodoc:
31
+ class SphericalLineImpl
28
32
  include Feature::Line
33
+ include ImplHelper::ValidityCheck
29
34
  include ImplHelper::BasicGeometryMethods
30
35
  include ImplHelper::BasicLineStringMethods
31
36
  include ImplHelper::BasicLineMethods
37
+ include ImplHelper::ValidOp
32
38
  include SphericalGeometryMethods
33
39
  include SphericalLineStringMethods
34
40
  end
35
41
 
36
- class SphericalLinearRingImpl # :nodoc:
42
+ class SphericalLinearRingImpl
37
43
  include Feature::LinearRing
44
+ include ImplHelper::ValidityCheck
38
45
  include ImplHelper::BasicGeometryMethods
39
46
  include ImplHelper::BasicLineStringMethods
40
47
  include ImplHelper::BasicLinearRingMethods
48
+ include ImplHelper::ValidOp
41
49
  include SphericalGeometryMethods
42
50
  include SphericalLineStringMethods
43
51
  end
44
52
 
45
- class SphericalPolygonImpl # :nodoc:
53
+ class SphericalPolygonImpl
46
54
  include Feature::Polygon
55
+ include ImplHelper::ValidityCheck
47
56
  include ImplHelper::BasicGeometryMethods
48
57
  include ImplHelper::BasicPolygonMethods
58
+ include ImplHelper::ValidOp
49
59
  include SphericalGeometryMethods
50
60
  include SphericalPolygonMethods
51
61
  end
52
62
 
53
- class SphericalGeometryCollectionImpl # :nodoc:
63
+ class SphericalGeometryCollectionImpl
54
64
  include Feature::GeometryCollection
65
+ include ImplHelper::ValidityCheck
55
66
  include ImplHelper::BasicGeometryMethods
56
67
  include ImplHelper::BasicGeometryCollectionMethods
68
+ include ImplHelper::ValidOp
57
69
  include SphericalGeometryMethods
58
70
  end
59
71
 
60
- class SphericalMultiPointImpl # :nodoc:
72
+ class SphericalMultiPointImpl
61
73
  include Feature::MultiPoint
74
+ include ImplHelper::ValidityCheck
62
75
  include ImplHelper::BasicGeometryMethods
63
76
  include ImplHelper::BasicGeometryCollectionMethods
64
77
  include ImplHelper::BasicMultiPointMethods
78
+ include ImplHelper::ValidOp
65
79
  include SphericalGeometryMethods
66
80
  end
67
81
 
68
- class SphericalMultiLineStringImpl # :nodoc:
82
+ class SphericalMultiLineStringImpl
69
83
  include Feature::MultiLineString
84
+ include ImplHelper::ValidityCheck
70
85
  include ImplHelper::BasicGeometryMethods
71
86
  include ImplHelper::BasicGeometryCollectionMethods
72
87
  include ImplHelper::BasicMultiLineStringMethods
88
+ include ImplHelper::ValidOp
73
89
  include SphericalGeometryMethods
74
90
  include SphericalMultiLineStringMethods
75
91
  end
76
92
 
77
- class SphericalMultiPolygonImpl # :nodoc:
93
+ class SphericalMultiPolygonImpl
78
94
  include Feature::MultiPolygon
95
+ include ImplHelper::ValidityCheck
79
96
  include ImplHelper::BasicGeometryMethods
80
97
  include ImplHelper::BasicGeometryCollectionMethods
81
98
  include ImplHelper::BasicMultiPolygonMethods
99
+ include ImplHelper::ValidOp
82
100
  include SphericalGeometryMethods
83
101
  end
102
+
103
+ ImplHelper::ValidityCheck.override_classes
84
104
  end
85
105
  end
@@ -12,6 +12,22 @@ module RGeo
12
12
  def srid
13
13
  factory.srid
14
14
  end
15
+
16
+ def coordinate_dimension
17
+ factory.coordinate_dimension
18
+ end
19
+
20
+ def spatial_dimension
21
+ factory.spatial_dimension
22
+ end
23
+
24
+ def is_3d?
25
+ factory.property(:has_z_coordinate)
26
+ end
27
+
28
+ def measured?
29
+ factory.property(:has_m_coordinate)
30
+ end
15
31
  end
16
32
 
17
33
  module SphericalPointMethods # :nodoc:
@@ -79,7 +95,8 @@ module RGeo
79
95
 
80
96
  private
81
97
 
82
- def validate_geometry
98
+ # Ensure coordinates fall within a valid range.
99
+ def init_geometry
83
100
  if @x < -180.0 || @x > 180.0
84
101
  @x = @x % 360.0
85
102
  @x -= 360.0 if @x > 180.0
@@ -128,6 +145,66 @@ module RGeo
128
145
  def length
129
146
  arcs.inject(0.0) { |sum, arc| sum + arc.length } * SphericalMath::RADIUS
130
147
  end
148
+
149
+ def intersects?(rhs)
150
+ case rhs
151
+ when Feature::LineString
152
+ intersects_line_string?(rhs)
153
+ else
154
+ super
155
+ end
156
+ end
157
+
158
+ def crosses?(rhs)
159
+ case rhs
160
+ when Feature::LineString
161
+ crosses_line_string?(rhs)
162
+ else
163
+ super
164
+ end
165
+ end
166
+
167
+ private
168
+
169
+ # TODO: replace with better algorithm (https://github.com/rgeo/rgeo/issues/274)
170
+ # Very simple algorithm to determine if 2 LineStrings intersect.
171
+ # Uses a nested for loop to look at each arc in the LineStrings and
172
+ # check if each arc intersects.
173
+ #
174
+ # @param [RGeo::Geographic::SphericalLineStringImpl] rhs
175
+ #
176
+ # @return [Boolean]
177
+ def intersects_line_string?(rhs)
178
+ arcs.each do |arc|
179
+ rhs.arcs.each do |rhs_arc|
180
+ return true if arc.intersects_arc?(rhs_arc)
181
+ end
182
+ end
183
+
184
+ false
185
+ end
186
+
187
+ # TODO: replace with better algorithm (https://github.com/rgeo/rgeo/issues/274)
188
+ # Very simple algorithm to determine if 2 LineStrings cross.
189
+ # Uses a nested for loop to look at each arc in the LineStrings and
190
+ # check if each arc crosses.
191
+ #
192
+ # @param [RGeo::Geographic::SphericalLineStringImpl] rhs
193
+ #
194
+ # @return [Boolean]
195
+ def crosses_line_string?(rhs)
196
+ arcs.each do |arc|
197
+ rhs.arcs.each do |rhs_arc|
198
+ next unless arc.intersects_arc?(rhs_arc)
199
+
200
+ # check that endpoints aren't the intersection point
201
+ is_endpoint = arc.contains_point?(rhs_arc.s) || arc.contains_point?(rhs_arc.e) || rhs_arc.contains_point?(arc.s) || rhs_arc.contains_point?(arc.e)
202
+ return true unless is_endpoint
203
+ end
204
+ end
205
+
206
+ false
207
+ end
131
208
  end
132
209
 
133
210
  module SphericalMultiLineStringMethods # :nodoc:
@@ -155,7 +232,7 @@ module RGeo
155
232
  centroid_lat /= (6.0 * signed_area)
156
233
  centroid_lng /= (6.0 * signed_area)
157
234
 
158
- RGeo::Geographic.spherical_factory.point(centroid_lat, centroid_lng)
235
+ factory.point(centroid_lat, centroid_lng)
159
236
  end
160
237
  end
161
238
  end