Sha256: 54434a0a0176486bfe74fd65fec28709d9dea4c7ba393e768310f7ce1ee188f6

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'ogr'
require_relative '../../ffi/lwgeom'

module OGR
  module GeometryExtensions
    # Methods for {{OGR::Geometry}}s that use lwgeom to operate on
    # themselves.
    #
    # @see http://postgis.net/docs/doxygen/2.1/da/de7/liblwgeom_8h_af8d208cf4c0bb7c9f96c75bddc6c498a.html#af8d208cf4c0bb7c9f96c75bddc6c498a
    module LWGeomWrappers
      # Uses lwgeom's MakeValid to make the current geometry valid.
      #
      # @return [OGR::Geometry] Returns a new geometry, based on the
      #   lwgeom_make_valid call.
      def make_valid
        geom = FFI::LWGeom.lwgeom_from_wkb(to_wkb, wkb_size, FFI::LWGeom::LW_PARSER_CHECK_NONE)
        valid_geom = FFI::LWGeom.lwgeom_make_valid(geom)
        valid_wkb_size = FFI::MemoryPointer.new(:size_t)
        valid_wkb_ptr = FFI::LWGeom.lwgeom_to_wkb(valid_geom, FFI::LWGeom::VARIANT_WKB_EXTENDED, valid_wkb_size)
        valid_wkb = valid_wkb_ptr.read_bytes(valid_wkb_size.read_int)

        OGR::Geometry.create_from_wkb(valid_wkb)
      end
    end
  end
end

module OGR
  module Geometry
    include OGR::GeometryExtensions::LWGeomWrappers
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-gdal-extensions-0.1.2 lib/ogr/geometry_extensions/lwgeom_wrappers.rb