lib/rgeo/geos/ffi_feature_methods.rb in rgeo-2.4.0 vs lib/rgeo/geos/ffi_feature_methods.rb in rgeo-3.0.0.pre.rc.1
- old
+ new
@@ -4,10 +4,12 @@
#
# FFI-GEOS geometry implementation
#
# -----------------------------------------------------------------------------
+require "ffi-geos"
+
module RGeo
module Geos
module FFIGeometryMethods # :nodoc:
include Feature::Instance
@@ -93,15 +95,13 @@
def envelope
@factory.wrap_fg_geom(@fg_geom.envelope, nil)
end
def boundary
- if self.class == FFIGeometryCollectionImpl
- nil
- else
- @factory.wrap_fg_geom(@fg_geom.boundary, nil)
- end
+ @factory.wrap_fg_geom(@fg_geom.boundary, nil)
+ rescue ::Geos::GEOSException
+ raise Error::InvalidGeometry, "Operation not supported by GeometryCollection"
end
def as_text
str = @factory.generate_wkt(self)
str.force_encoding("US-ASCII") if str.respond_to?(:force_encoding)
@@ -128,9 +128,27 @@
def is_simple?
warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
simple?
end
+
+ def valid?
+ @fg_geom.valid?
+ end
+
+ def invalid_reason
+ # valid_detail gives solely the reason, or nil if valid, which is
+ # what we want.
+ fg_geom.valid_detail&.dig(:detail)&.force_encoding(Encoding::UTF_8)
+ end
+
+ # (see RGeo::ImplHelper::ValidityCheck#make_valid)
+ # Only available since GEOS 3.8+
+ def make_valid
+ @factory.wrap_fg_geom(@fg_geom.make_valid, nil)
+ rescue ::Geos::GEOSException
+ raise Error::UnsupportedOperation
+ end if ::Geos::FFIGeos.respond_to?(:GEOSMakeValid_r)
def equals?(rhs)
return false unless rhs.is_a?(RGeo::Feature::Instance)
fg = factory.convert_to_fg_geometry(rhs)
if !fg