Module: RGeo::ImplHelper::ValidityCheck
- Included in:
- Cartesian::GeometryCollectionImpl, Cartesian::LineImpl, Cartesian::LineStringImpl, Cartesian::LinearRingImpl, Cartesian::MultiLineStringImpl, Cartesian::MultiPointImpl, Cartesian::MultiPolygonImpl, Cartesian::PointImpl, Cartesian::PolygonImpl, Geographic::ProjectedGeometryCollectionImpl, Geographic::ProjectedLineImpl, Geographic::ProjectedLineStringImpl, Geographic::ProjectedLinearRingImpl, Geographic::ProjectedMultiLineStringImpl, Geographic::ProjectedMultiPointImpl, Geographic::ProjectedMultiPolygonImpl, Geographic::ProjectedPointImpl, Geographic::ProjectedPolygonImpl, Geographic::SphericalGeometryCollectionImpl, Geographic::SphericalLineImpl, Geographic::SphericalLineStringImpl, Geographic::SphericalLinearRingImpl, Geographic::SphericalMultiLineStringImpl, Geographic::SphericalMultiPointImpl, Geographic::SphericalMultiPolygonImpl, Geographic::SphericalPointImpl, Geographic::SphericalPolygonImpl, Geos::CAPIGeometryCollectionImpl, Geos::CAPIGeometryImpl, Geos::CAPILineImpl, Geos::CAPILineStringImpl, Geos::CAPILinearRingImpl, Geos::CAPIMultiLineStringImpl, Geos::CAPIMultiPointImpl, Geos::CAPIMultiPolygonImpl, Geos::CAPIPointImpl, Geos::CAPIPolygonImpl, Geos::FFIGeometryCollectionImpl, Geos::FFIGeometryImpl, Geos::FFILineImpl, Geos::FFILineStringImpl, Geos::FFILinearRingImpl, Geos::FFIMultiLineStringImpl, Geos::FFIMultiPointImpl, Geos::FFIMultiPolygonImpl, Geos::FFIPointImpl, Geos::FFIPolygonImpl
- Defined in:
- lib/rgeo/impl_helper/validity_check.rb
Overview
This helper enforces valid geometry computation, avoiding results such as a 0 area for a bowtie shaped polygon. Implementations that are part of RGeo core should all include this.
You can play around validity checks if needed:
-
#check_validity! is the method that will raise if your geometry is not valid. Its message will be the same as #invalid_reason.
-
#make_valid is the method you can call to get a valid copy of the current geometry.
-
finally, you can bypass any checked method by prepending ‘unsafe_` to it. At your own risk.
Class Method Summary collapse
-
.included(klass) ⇒ Object
:nodoc:.
-
.override_classes ⇒ Object
Note for contributors: this should be called after all methods are loaded for a given feature classe.
Instance Method Summary collapse
-
#check_validity! ⇒ Object
Raises #invalid_reason if the polygon is not valid, does nothing otherwise.
-
#invalid_reason ⇒ Object
Tell why the geometry is not valid, ‘nil` means it is valid.
-
#make_valid ⇒ Object
Try and make the geometry valid, this may change its shape.
Class Method Details
.included(klass) ⇒ Object
:nodoc:
59 60 61 |
# File 'lib/rgeo/impl_helper/validity_check.rb', line 59 def included(klass) # :nodoc: classes << klass end |
.override_classes ⇒ Object
Note for contributors: this should be called after all methods are loaded for a given feature classe. No worries though, this is tested.
52 53 54 55 56 57 |
# File 'lib/rgeo/impl_helper/validity_check.rb', line 52 def override_classes # :nodoc: # Using pop here to be thread safe. while (klass = classes.pop) override(klass) end end |
Instance Method Details
#check_validity! ⇒ Object
Raises #invalid_reason if the polygon is not valid, does nothing otherwise.
100 101 102 103 104 105 106 |
# File 'lib/rgeo/impl_helper/validity_check.rb', line 100 def check_validity! # This method will use a cached invalid_reason for performance purposes. # DO NOT MUTATE GEOMETRIES. return unless invalid_reason_memo raise Error::InvalidGeometry, invalid_reason_memo end |
#invalid_reason ⇒ Object
Tell why the geometry is not valid, ‘nil` means it is valid.
109 110 111 112 113 114 115 116 |
# File 'lib/rgeo/impl_helper/validity_check.rb', line 109 def invalid_reason if defined?(super) == "super" raise Error::RGeoError, "ValidityCheck MUST be loaded before " \ "definition of #{self.class}##{__method__}." end raise Error::UnsupportedOperation, "Method #{self.class}##{__method__} not defined." end |
#make_valid ⇒ Object
Try and make the geometry valid, this may change its shape. Returns a valid copy of the geometry.
120 121 122 123 124 125 126 127 |
# File 'lib/rgeo/impl_helper/validity_check.rb', line 120 def make_valid if defined?(super) == "super" raise Error::RGeoError, "ValidityCheck MUST be loaded before " \ "definition of #{self.class}##{__method__}." end raise Error::UnsupportedOperation, "Method #{self.class}##{__method__} not defined." end |