class Geos::Geometry

Attributes

ptr[R]

Public Class Methods

new(ptr, options = {}) click to toggle source

For internal use. Geometry objects should be created via WkbReader, WktReader and the various Geos.create_* methods.

# File lib/ffi-geos/geometry.rb, line 17
def initialize(ptr, options = {})
  options = {
    auto_free: true
  }.merge(options)

  @ptr = FFI::AutoPointer.new(
    ptr,
    self.class.method(:release)
  )

  @ptr.autorelease = !!options[:auto_free]
  @parent = options[:parent] if options[:parent]
end

Public Instance Methods

==(other) click to toggle source
# File lib/ffi-geos/geometry.rb, line 448
def ==(other)
  return eql?(other) if other.is_a?(Geos::Geometry)

  false
end
almost_equals?(other, decimal = 6)
Alias for: eql_almost?
area() click to toggle source
# File lib/ffi-geos/geometry.rb, line 570
def area
  return 0 if empty?

  double_ptr = FFI::MemoryPointer.new(:double)
  FFIGeos.GEOSArea_r(Geos.current_handle_pointer, ptr, double_ptr)
  double_ptr.read_double
end
boundary() click to toggle source
# File lib/ffi-geos/geometry.rb, line 213
def boundary
  cast_geometry_ptr(FFIGeos.GEOSBoundary_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
buffer(width) click to toggle source
buffer(width, options)
buffer(width, buffer_params)
buffer(width, quad_segs)

Calls buffer on the Geometry. Options can be passed as either a BufferParams object, as an equivalent Hash or as a quad_segs value. Default values can be found in Geos::Constants::BUFFER_PARAM_DEFAULTS.

Note that when using versions of GEOS prior to 3.3.0, only the quad_segs option is recognized when using Geometry#buffer and other options are ignored.

# File lib/ffi-geos/geometry.rb, line 122
def buffer(width, options = nil)
  options ||= {}
  params = case options
    when Hash
      Geos::BufferParams.new(options)
    when Geos::BufferParams
      options
    when Numeric
      Geos::BufferParams.new(quad_segs: options)
    else
      raise ArgumentError, 'Expected Geos::BufferParams, a Hash or a Numeric'
  end

  cast_geometry_ptr(FFIGeos.GEOSBufferWithParams_r(Geos.current_handle_pointer, ptr, params.ptr, width), srid_copy: srid)
end
build_area() click to toggle source

Added in GEOS 3.8+

# File lib/ffi-geos/geometry.rb, line 697
def build_area
  cast_geometry_ptr(FFIGeos.GEOSBuildArea_r(Geos.current_handle_pointer, ptr))
end
center()
Alias for: centroid
centroid() click to toggle source
# File lib/ffi-geos/geometry.rb, line 285
def centroid
  cast_geometry_ptr(FFIGeos.GEOSGetCentroid_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
Also aliased as: center
clip_by_rect(xmin, ymin, xmax, ymax) click to toggle source

Available in GEOS 3.5.0+.

# File lib/ffi-geos/geometry.rb, line 279
def clip_by_rect(xmin, ymin, xmax, ymax)
  cast_geometry_ptr(FFIGeos.GEOSClipByRect_r(Geos.current_handle_pointer, ptr, xmin, ymin, xmax, ymax))
end
Also aliased as: clip_by_rectangle
clip_by_rectangle(xmin, ymin, xmax, ymax)
Alias for: clip_by_rect
concave_hull(ratio: 0.0, allow_holes: false, length: nil) click to toggle source
# File lib/ffi-geos/geometry.rb, line 166
def concave_hull(ratio: 0.0, allow_holes: false, length: nil)
  cast_geometry_ptr(
    case length
      when Numeric
        FFIGeos.GEOSConcaveHullByLength_r(Geos.current_handle_pointer, ptr, length, bool_to_int(allow_holes))
      else
        FFIGeos.GEOSConcaveHull_r(Geos.current_handle_pointer, ptr, ratio, bool_to_int(allow_holes))
    end,
    srid_copy: srid
  )
end
concave_hull_of_polygons(length_ratio, tight: false, allow_holes: false) click to toggle source
# File lib/ffi-geos/geometry.rb, line 797
def concave_hull_of_polygons(length_ratio, tight: false, allow_holes: false)
  cast_geometry_ptr(FFIGeos.GEOSConcaveHullOfPolygons_r(Geos.current_handle_pointer, ptr, length_ratio, bool_to_int(tight), bool_to_int(allow_holes)), srid_copy: srid)
end
constrained_delaunay_triangulation() click to toggle source
# File lib/ffi-geos/geometry.rb, line 729
def constrained_delaunay_triangulation
  cast_geometry_ptr(FFIGeos.GEOSConstrainedDelaunayTriangulation_r(Geos.current_handle_pointer, ptr))
end
contains?(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 388
def contains?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSContains_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
convex_hull() click to toggle source
# File lib/ffi-geos/geometry.rb, line 161
def convex_hull
  cast_geometry_ptr(FFIGeos.GEOSConvexHull_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
coord_seq() click to toggle source
# File lib/ffi-geos/geometry.rb, line 94
def coord_seq
  CoordinateSequence.new(FFIGeos.GEOSGeom_getCoordSeq_r(Geos.current_handle_pointer, ptr), false, self)
end
coverage_union() click to toggle source

Added in GEOS 3.8+

# File lib/ffi-geos/geometry.rb, line 242
def coverage_union
  cast_geometry_ptr(FFIGeos.GEOSCoverageUnion_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
covered_by?(geom) click to toggle source

In GEOS versions 3.3+, the native GEOSCovers method will be used, while in older GEOS versions we’ll use a relate_pattern-based implementation.

# File lib/ffi-geos/geometry.rb, line 424
def covered_by?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSCoveredBy_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
covers?(geom) click to toggle source

In GEOS versions 3.3+, the native GEOSCoveredBy method will be used, while in older GEOS versions we’ll use a relate_pattern-based implementation.

# File lib/ffi-geos/geometry.rb, line 402
def covers?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSCovers_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
crosses?(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 378
def crosses?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSCrosses_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
delaunay_triangulation(options = {}) click to toggle source
delaunay_triangulation(tolerance, options = {})

Options:

  • :tolerance

  • :only_edges

# File lib/ffi-geos/geometry.rb, line 718
def delaunay_triangulation(*args)
  options = extract_options!(args)

  tolerance = args.first || options[:tolerance] || 0.0
  only_edges = bool_to_int(options[:only_edges])

  cast_geometry_ptr(FFIGeos.GEOSDelaunayTriangulation_r(Geos.current_handle_pointer, ptr, tolerance, only_edges))
end
densify(tolerance = 0.0) click to toggle source
# File lib/ffi-geos/geometry.rb, line 156
def densify(tolerance = 0.0)
  cast_geometry_ptr(FFIGeos.GEOSDensify_r(Geos.current_handle_pointer, ptr, tolerance), srid_copy: srid)
end
difference(geom, precision: nil) click to toggle source
# File lib/ffi-geos/geometry.rb, line 192
def difference(geom, precision: nil)
  check_geometry(geom)

  if precision
    cast_geometry_ptr(FFIGeos.GEOSDifferencePrec_r(Geos.current_handle_pointer, ptr, geom.ptr, precision), srid_copy: pick_srid_from_geoms(srid, geom.srid))
  else
    cast_geometry_ptr(FFIGeos.GEOSDifference_r(Geos.current_handle_pointer, ptr, geom.ptr), srid_copy: pick_srid_from_geoms(srid, geom.srid))
  end
end
dimensions() click to toggle source
# File lib/ffi-geos/geometry.rb, line 82
def dimensions
  FFIGeos.GEOSGeom_getDimensions_r(Geos.current_handle_pointer, ptr)
end
disjoint?(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 363
def disjoint?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSDisjoint_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
disjoint_subset_union() click to toggle source

Added in GEOS 3.12+

# File lib/ffi-geos/geometry.rb, line 249
def disjoint_subset_union
  cast_geometry_ptr(FFIGeos.GEOSDisjointSubsetUnion_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
distance(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 586
def distance(geom)
  check_geometry(geom)
  double_ptr = FFI::MemoryPointer.new(:double)
  FFIGeos.GEOSDistance_r(Geos.current_handle_pointer, ptr, geom.ptr, double_ptr)
  double_ptr.read_double
end
distance_indexed(geom) click to toggle source

Available in GEOS 3.7+.

# File lib/ffi-geos/geometry.rb, line 595
def distance_indexed(geom)
  check_geometry(geom)
  double_ptr = FFI::MemoryPointer.new(:double)
  FFIGeos.GEOSDistanceIndexed_r(Geos.current_handle_pointer, ptr, geom.ptr, double_ptr)
  double_ptr.read_double
end
Also aliased as: indexed_distance
empty?() click to toggle source
# File lib/ffi-geos/geometry.rb, line 476
def empty?
  bool_result(FFIGeos.GEOSisEmpty_r(Geos.current_handle_pointer, ptr))
end
end_point() click to toggle source
# File lib/ffi-geos/geometry.rb, line 566
def end_point
  cast_geometry_ptr(FFIGeos.GEOSGeomGetEndPoint_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
envelope() click to toggle source
# File lib/ffi-geos/geometry.rb, line 307
def envelope
  cast_geometry_ptr(FFIGeos.GEOSEnvelope_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
eql?(other) click to toggle source
# File lib/ffi-geos/geometry.rb, line 442
def eql?(other)
  check_geometry(other)
  bool_result(FFIGeos.GEOSEquals_r(Geos.current_handle_pointer, ptr, other.ptr))
end
Also aliased as: equals?
eql_almost?(other, decimal = 6) click to toggle source
# File lib/ffi-geos/geometry.rb, line 469
def eql_almost?(other, decimal = 6)
  check_geometry(other)
  bool_result(FFIGeos.GEOSEqualsExact_r(Geos.current_handle_pointer, ptr, other.ptr, 0.5 * (10 ** -decimal)))
end
Also aliased as: equals_almost?, almost_equals?
eql_exact?(other, tolerance) click to toggle source
# File lib/ffi-geos/geometry.rb, line 454
def eql_exact?(other, tolerance)
  check_geometry(other)
  bool_result(FFIGeos.GEOSEqualsExact_r(Geos.current_handle_pointer, ptr, other.ptr, tolerance))
end
Also aliased as: equals_exact?, exactly_equals?
eql_identical?(other) click to toggle source
# File lib/ffi-geos/geometry.rb, line 462
def eql_identical?(other)
  check_geometry(other)
  bool_result(FFIGeos.GEOSEqualsIdentical_r(Geos.current_handle_pointer, ptr, other.ptr))
end
Also aliased as: equals_identical?
equals?(other)
Alias for: eql?
equals_almost?(other, decimal = 6)
Alias for: eql_almost?
equals_exact?(other, tolerance)
Alias for: eql_exact?
equals_identical?(other)
Alias for: eql_identical?
exactly_equals?(other, tolerance)
Alias for: eql_exact?
extract_unique_points() click to toggle source
# File lib/ffi-geos/geometry.rb, line 358
def extract_unique_points
  cast_geometry_ptr(FFIGeos.GEOSGeom_extractUniquePoints_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
Also aliased as: unique_points
frechet_distance(geom, densify_frac = nil) click to toggle source
# File lib/ffi-geos/geometry.rb, line 847
def frechet_distance(geom, densify_frac = nil)
  check_geometry(geom)

  double_ptr = FFI::MemoryPointer.new(:double)

  if densify_frac
    FFIGeos.GEOSFrechetDistanceDensify_r(Geos.current_handle_pointer, ptr, geom.ptr, densify_frac, double_ptr)
  else
    FFIGeos.GEOSFrechetDistance_r(Geos.current_handle_pointer, ptr, geom.ptr, double_ptr)
  end

  double_ptr.read_double
end
geom_type() click to toggle source

Returns the name of the Geometry type, i.e. “Point”, “Polygon”, etc.

# File lib/ffi-geos/geometry.rb, line 46
def geom_type
  FFIGeos.GEOSGeomType_r(Geos.current_handle_pointer, ptr)
end
has_m?() click to toggle source
# File lib/ffi-geos/geometry.rb, line 525
def has_m?
  bool_result(FFIGeos.GEOSHasM_r(Geos.current_handle_pointer, ptr))
end
has_z?() click to toggle source
# File lib/ffi-geos/geometry.rb, line 520
def has_z?
  bool_result(FFIGeos.GEOSHasZ_r(Geos.current_handle_pointer, ptr))
end
hausdorff_distance(geom, densify_frac = nil) click to toggle source
# File lib/ffi-geos/geometry.rb, line 604
def hausdorff_distance(geom, densify_frac = nil)
  check_geometry(geom)

  double_ptr = FFI::MemoryPointer.new(:double)

  if densify_frac
    FFIGeos.GEOSHausdorffDistanceDensify_r(Geos.current_handle_pointer, ptr, geom.ptr, densify_frac, double_ptr)
  else
    FFIGeos.GEOSHausdorffDistance_r(Geos.current_handle_pointer, ptr, geom.ptr, double_ptr)
  end

  double_ptr.read_double
end
hilbert_code(extent, level) click to toggle source
# File lib/ffi-geos/geometry.rb, line 291
def hilbert_code(extent, level)
  check_geometry(extent)
  code_ptr = FFI::MemoryPointer.new(:uint)
  FFIGeos.GEOSHilbertCode_r(Geos.current_handle_pointer, ptr, extent.ptr, level, code_ptr)
  code_ptr.read_uint
end
indexed_distance(geom)
Alias for: distance_indexed
initialize_copy(source) click to toggle source
# File lib/ffi-geos/geometry.rb, line 31
def initialize_copy(source)
  @ptr = FFI::AutoPointer.new(
    FFIGeos.GEOSGeom_clone_r(Geos.current_handle_pointer, source.ptr),
    self.class.method(:release)
  )

  # Copy over SRID since GEOS does not
  self.srid = source.srid
end
interpolate(d, normalized = false) click to toggle source
# File lib/ffi-geos/geometry.rb, line 548
def interpolate(d, normalized = false)
  ret = if normalized
    FFIGeos.GEOSInterpolateNormalized_r(Geos.current_handle_pointer, ptr, d)
  else
    FFIGeos.GEOSInterpolate_r(Geos.current_handle_pointer, ptr, d)
  end

  cast_geometry_ptr(ret, srid_copy: srid)
end
interpolate_normalized(d) click to toggle source
# File lib/ffi-geos/geometry.rb, line 558
def interpolate_normalized(d)
  interpolate(d, true)
end
intersection(geom, precision: nil) click to toggle source
# File lib/ffi-geos/geometry.rb, line 98
def intersection(geom, precision: nil)
  check_geometry(geom)

  if precision
    cast_geometry_ptr(FFIGeos.GEOSIntersectionPrec_r(Geos.current_handle_pointer, ptr, geom.ptr, precision), srid_copy: pick_srid_from_geoms(srid, geom.srid))
  else
    cast_geometry_ptr(FFIGeos.GEOSIntersection_r(Geos.current_handle_pointer, ptr, geom.ptr), srid_copy: pick_srid_from_geoms(srid, geom.srid))
  end
end
intersects?(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 373
def intersects?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSIntersects_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
largest_empty_circle(precision, boundary: nil) click to toggle source
# File lib/ffi-geos/geometry.rb, line 829
def largest_empty_circle(precision, boundary: nil)
  cast_geometry_ptr(FFIGeos.GEOSLargestEmptyCircle_r(Geos.current_handle_pointer, ptr, boundary ? boundary.ptr : nil, precision))
end
length() click to toggle source
# File lib/ffi-geos/geometry.rb, line 578
def length
  return 0 if empty?

  double_ptr = FFI::MemoryPointer.new(:double)
  FFIGeos.GEOSLength_r(Geos.current_handle_pointer, ptr, double_ptr)
  double_ptr.read_double
end
line_merge() click to toggle source
# File lib/ffi-geos/geometry.rb, line 333
def line_merge
  cast_geometry_ptr(FFIGeos.GEOSLineMerge_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
line_merge_directed() click to toggle source
# File lib/ffi-geos/geometry.rb, line 338
def line_merge_directed
  cast_geometry_ptr(FFIGeos.GEOSLineMergeDirected_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
line_substring(start_fraction, end_fraction) click to toggle source

Added in GEOS 3.12+

# File lib/ffi-geos/geometry.rb, line 345
def line_substring(start_fraction, end_fraction)
  cast_geometry_ptr(FFIGeos.GEOSLineSubstring_r(Geos.current_handle_pointer, ptr, start_fraction, end_fraction), srid_copy: srid)
end
make_valid() click to toggle source

Added in GEOS 3.8+

# File lib/ffi-geos/geometry.rb, line 704
def make_valid
  cast_geometry_ptr(FFIGeos.GEOSMakeValid_r(Geos.current_handle_pointer, ptr))
end
maximum_inscribed_circle(precision) click to toggle source
# File lib/ffi-geos/geometry.rb, line 823
def maximum_inscribed_circle(precision)
  cast_geometry_ptr(FFIGeos.GEOSMaximumInscribedCircle_r(Geos.current_handle_pointer, ptr, precision))
end
minimum_bounding_circle() click to toggle source

Added in GEOS 3.8+. Does not yet support the radius or center arguments.

# File lib/ffi-geos/geometry.rb, line 302
def minimum_bounding_circle
  cast_geometry_ptr(FFIGeos.GEOSMinimumBoundingCircle_r(Geos.current_handle_pointer, ptr, nil, nil), srid_copy: srid)
end
minimum_clearance() click to toggle source
# File lib/ffi-geos/geometry.rb, line 809
def minimum_clearance
  double_ptr = FFI::MemoryPointer.new(:double)
  FFIGeos.GEOSMinimumClearance_r(Geos.current_handle_pointer, ptr, double_ptr)
  double_ptr.read_double
end
minimum_clearance_line() click to toggle source
# File lib/ffi-geos/geometry.rb, line 817
def minimum_clearance_line
  cast_geometry_ptr(FFIGeos.GEOSMinimumClearanceLine_r(Geos.current_handle_pointer, ptr))
end
minimum_rotated_rectangle() click to toggle source
# File lib/ffi-geos/geometry.rb, line 803
def minimum_rotated_rectangle
  cast_geometry_ptr(FFIGeos.GEOSMinimumRotatedRectangle_r(Geos.current_handle_pointer, ptr))
end
minimum_width() click to toggle source
# File lib/ffi-geos/geometry.rb, line 835
def minimum_width
  cast_geometry_ptr(FFIGeos.GEOSMinimumWidth_r(Geos.current_handle_pointer, ptr))
end
nearest_points(geom) click to toggle source

Available in GEOS 3.4+.

# File lib/ffi-geos/geometry.rb, line 620
def nearest_points(geom)
  check_geometry(geom)
  nearest_points_ptr = FFIGeos.GEOSNearestPoints_r(Geos.current_handle_pointer, ptr, geom.ptr)

  CoordinateSequence.new(nearest_points_ptr) unless nearest_points_ptr.null?
end
node() click to toggle source

Available in GEOS 3.3.4+

# File lib/ffi-geos/geometry.rb, line 267
def node
  cast_geometry_ptr(FFIGeos.GEOSNode_r(Geos.current_handle_pointer, ptr))
end
normalize()
Alias for: normalize!
normalize!() click to toggle source
# File lib/ffi-geos/geometry.rb, line 55
def normalize!
  raise Geos::Geometry::CouldntNormalizeError, self.class if FFIGeos.GEOSNormalize_r(Geos.current_handle_pointer, ptr) == -1

  self
end
Also aliased as: normalize
num_coordinates() click to toggle source
# File lib/ffi-geos/geometry.rb, line 90
def num_coordinates
  FFIGeos.GEOSGetNumCoordinates_r(Geos.current_handle_pointer, ptr)
end
num_geometries() click to toggle source
# File lib/ffi-geos/geometry.rb, line 86
def num_geometries
  FFIGeos.GEOSGetNumGeometries_r(Geos.current_handle_pointer, ptr)
end
orient_polygons(exterior_cw = false) click to toggle source
# File lib/ffi-geos/geometry.rb, line 69
def orient_polygons(exterior_cw = false)
  dup.orient_polygons!(exterior_cw)
end
orient_polygons!(exterior_cw = false) click to toggle source
# File lib/ffi-geos/geometry.rb, line 63
def orient_polygons!(exterior_cw = false)
  raise Geos::GEOSException, self.class if FFIGeos.GEOSOrientPolygons_r(Geos.current_handle_pointer, ptr, bool_to_int(exterior_cw)) == -1

  self
end
overlaps?(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 393
def overlaps?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSOverlaps_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
point_on_surface() click to toggle source
# File lib/ffi-geos/geometry.rb, line 272
def point_on_surface
  cast_geometry_ptr(FFIGeos.GEOSPointOnSurface_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
Also aliased as: representative_point
polygon_hull_simplify(parameter, outer: false, mode: :vertex_ratio) click to toggle source
# File lib/ffi-geos/geometry.rb, line 180
def polygon_hull_simplify(parameter, outer: false, mode: :vertex_ratio)
  check_enum_value(Geos::PolygonHullSimplifyModes, mode)

  case mode
    when :vertex_ratio
      cast_geometry_ptr(FFIGeos.GEOSPolygonHullSimplify_r(Geos.current_handle_pointer, ptr, bool_to_int(outer), parameter), srid_copy: srid)
    when :area_ratio
      cast_geometry_ptr(FFIGeos.GEOSPolygonHullSimplifyMode_r(Geos.current_handle_pointer, ptr, bool_to_int(outer), 2, parameter), srid_copy: srid)
  end
end
polygonize(*geoms) click to toggle source
# File lib/ffi-geos/geometry.rb, line 666
def polygonize(*geoms)
  geoms.each do |geom|
    raise ArgumentError unless geom.is_a?(Geos::Geometry)
  end

  ary = [ptr].concat(geoms.collect(&:ptr))
  ary_ptr = FFI::MemoryPointer.new(:pointer, ary.length)
  ary_ptr.write_array_of_pointer(ary)

  cast_geometry_ptr(FFIGeos.GEOSPolygonize_r(Geos.current_handle_pointer, ary_ptr, ary.length), srid_copy: srid).to_a
end
polygonize_cut_edges() click to toggle source
# File lib/ffi-geos/geometry.rb, line 688
def polygonize_cut_edges
  ary = FFI::MemoryPointer.new(:pointer)
  ary.write_array_of_pointer([ptr])

  cast_geometry_ptr(FFIGeos.GEOSPolygonizer_getCutEdges_r(Geos.current_handle_pointer, ary, 1), srid_copy: srid).to_a
end
polygonize_full() click to toggle source

Returns a Hash with the following structure:

{
  rings: [ ... ],
  cuts: [ ... ],
  dangles: [ ... ],
  invalid_rings: [ ... ]
}
# File lib/ffi-geos/geometry.rb, line 647
def polygonize_full
  cuts = FFI::MemoryPointer.new(:pointer)
  dangles = FFI::MemoryPointer.new(:pointer)
  invalid_rings = FFI::MemoryPointer.new(:pointer)

  rings = cast_geometry_ptr(FFIGeos.GEOSPolygonize_full_r(Geos.current_handle_pointer, ptr, cuts, dangles, invalid_rings), srid_copy: srid)

  cuts = cast_geometry_ptr(cuts.read_pointer, srid_copy: srid)
  dangles = cast_geometry_ptr(dangles.read_pointer, srid_copy: srid)
  invalid_rings = cast_geometry_ptr(invalid_rings.read_pointer, srid_copy: srid)

  {
    rings: rings.to_a,
    cuts: cuts.to_a,
    dangles: dangles.to_a,
    invalid_rings: invalid_rings.to_a
  }
end
polygonize_valid() click to toggle source

Added in GEOS 3.8+

# File lib/ffi-geos/geometry.rb, line 680
def polygonize_valid
  ary = FFI::MemoryPointer.new(:pointer)
  ary.write_array_of_pointer([ptr])

  cast_geometry_ptr(FFIGeos.GEOSPolygonize_valid_r(Geos.current_handle_pointer, ary, 1), srid_copy: srid)
end
precision() click to toggle source
# File lib/ffi-geos/geometry.rb, line 775
def precision
  FFIGeos.GEOSGeom_getPrecision_r(Geos.current_handle_pointer, ptr)
end
project(geom, normalized = false) click to toggle source
# File lib/ffi-geos/geometry.rb, line 533
def project(geom, normalized = false)
  raise TypeError, 'Expected Geos::Point type' unless geom.is_a?(Geos::Point)

  if normalized
    FFIGeos.GEOSProjectNormalized_r(Geos.current_handle_pointer, ptr, geom.ptr)
  else
    FFIGeos.GEOSProject_r(Geos.current_handle_pointer, ptr, geom.ptr)
  end
end
project_normalized(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 543
def project_normalized(geom)
  project(geom, true)
end
relate(geom) click to toggle source

Returns the Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix of the geometries as a String.

# File lib/ffi-geos/geometry.rb, line 313
def relate(geom)
  check_geometry(geom)
  FFIGeos.GEOSRelate_r(Geos.current_handle_pointer, ptr, geom.ptr)
end
relate_boundary_node_rule(geom, bnr = :mod2) click to toggle source

Available in GEOS 3.3+.

# File lib/ffi-geos/geometry.rb, line 326
def relate_boundary_node_rule(geom, bnr = :mod2)
  check_geometry(geom)
  check_enum_value(Geos::RelateBoundaryNodeRules, bnr)
  FFIGeos.GEOSRelateBoundaryNodeRule_r(Geos.current_handle_pointer, ptr, geom.ptr, bnr)
end
relate_pattern(geom, pattern) click to toggle source

Checks the DE-9IM pattern against the geoms.

# File lib/ffi-geos/geometry.rb, line 319
def relate_pattern(geom, pattern)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSRelatePattern_r(Geos.current_handle_pointer, ptr, geom.ptr, pattern))
end
representative_point()
Alias for: point_on_surface
reverse() click to toggle source
# File lib/ffi-geos/geometry.rb, line 841
def reverse
  cast_geometry_ptr(FFIGeos.GEOSReverse_r(Geos.current_handle_pointer, ptr))
end
ring?() click to toggle source
# File lib/ffi-geos/geometry.rb, line 516
def ring?
  bool_result(FFIGeos.GEOSisRing_r(Geos.current_handle_pointer, ptr))
end
shared_paths(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 634
def shared_paths(geom)
  check_geometry(geom)
  cast_geometry_ptr(FFIGeos.GEOSSharedPaths_r(Geos.current_handle_pointer, ptr, geom.ptr), srid_copy: pick_srid_from_geoms(srid, geom.srid)).to_a
end
simple?() click to toggle source
# File lib/ffi-geos/geometry.rb, line 512
def simple?
  bool_result(FFIGeos.GEOSisSimple_r(Geos.current_handle_pointer, ptr))
end
simplify(tolerance) click to toggle source
# File lib/ffi-geos/geometry.rb, line 350
def simplify(tolerance)
  cast_geometry_ptr(FFIGeos.GEOSSimplify_r(Geos.current_handle_pointer, ptr, tolerance), srid_copy: srid)
end
snap(geom, tolerance) click to toggle source
# File lib/ffi-geos/geometry.rb, line 628
def snap(geom, tolerance)
  check_geometry(geom)
  cast_geometry_ptr(FFIGeos.GEOSSnap_r(Geos.current_handle_pointer, ptr, geom.ptr, tolerance), srid_copy: pick_srid_from_geoms(srid, geom.srid))
end
Also aliased as: snap_to
snap_to(geom, tolerance)
Alias for: snap
srid() click to toggle source
# File lib/ffi-geos/geometry.rb, line 74
def srid
  FFIGeos.GEOSGetSRID_r(Geos.current_handle_pointer, ptr)
end
srid=(s) click to toggle source
# File lib/ffi-geos/geometry.rb, line 78
def srid=(s)
  FFIGeos.GEOSSetSRID_r(Geos.current_handle_pointer, ptr, s)
end
start_point() click to toggle source
# File lib/ffi-geos/geometry.rb, line 562
def start_point
  cast_geometry_ptr(FFIGeos.GEOSGeomGetStartPoint_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
sym_difference(geom, precision: nil) click to toggle source
# File lib/ffi-geos/geometry.rb, line 202
def sym_difference(geom, precision: nil)
  check_geometry(geom)

  if precision
    cast_geometry_ptr(FFIGeos.GEOSSymDifferencePrec_r(Geos.current_handle_pointer, ptr, geom.ptr, precision), srid_copy: pick_srid_from_geoms(srid, geom.srid))
  else
    cast_geometry_ptr(FFIGeos.GEOSSymDifference_r(Geos.current_handle_pointer, ptr, geom.ptr), srid_copy: pick_srid_from_geoms(srid, geom.srid))
  end
end
Also aliased as: symmetric_difference
symmetric_difference(geom, precision: nil)
Alias for: sym_difference
to_prepared() click to toggle source
# File lib/ffi-geos/geometry.rb, line 762
def to_prepared
  Geos::PreparedGeometry.new(self)
end
to_s() click to toggle source
# File lib/ffi-geos/geometry.rb, line 766
def to_s
  writer = WktWriter.new
  wkt = writer.write(self)
  wkt = "#{wkt[0...120]} ... " if wkt.length > 120

  "#<Geos::#{geom_type}: #{wkt}>"
end
topology_preserve_simplify(tolerance) click to toggle source
# File lib/ffi-geos/geometry.rb, line 354
def topology_preserve_simplify(tolerance)
  cast_geometry_ptr(FFIGeos.GEOSTopologyPreserveSimplify_r(Geos.current_handle_pointer, ptr, tolerance), srid_copy: srid)
end
touches?(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 368
def touches?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSTouches_r(Geos.current_handle_pointer, ptr, geom.ptr))
end
type_id() click to toggle source

Returns one of the values from Geos::GeomTypes.

# File lib/ffi-geos/geometry.rb, line 51
def type_id
  FFIGeos.GEOSGeomTypeId_r(Geos.current_handle_pointer, ptr)
end
unary_union(precision = nil) click to toggle source

Available in GEOS 3.3+

# File lib/ffi-geos/geometry.rb, line 256
def unary_union(precision = nil)
  if precision
    cast_geometry_ptr(FFIGeos.GEOSUnaryUnionPrec_r(Geos.current_handle_pointer, ptr, precision), srid_copy: srid)
  else
    cast_geometry_ptr(FFIGeos.GEOSUnaryUnion_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
  end
end
union(geom = nil, precision: nil) click to toggle source

Calling without a geom argument is equivalent to calling unary_union when using GEOS 3.3+ and is equivalent to calling union_cascaded in older versions.

# File lib/ffi-geos/geometry.rb, line 220
def union(geom = nil, precision: nil)
  if geom
    check_geometry(geom)

    if precision
      cast_geometry_ptr(FFIGeos.GEOSUnionPrec_r(Geos.current_handle_pointer, ptr, geom.ptr, precision), srid_copy: pick_srid_from_geoms(srid, geom.srid))
    else
      cast_geometry_ptr(FFIGeos.GEOSUnion_r(Geos.current_handle_pointer, ptr, geom.ptr), srid_copy: pick_srid_from_geoms(srid, geom.srid))
    end
  elsif respond_to?(:unary_union)
    unary_union
  else
    union_cascaded
  end
end
union_cascaded() click to toggle source
# File lib/ffi-geos/geometry.rb, line 236
def union_cascaded
  cast_geometry_ptr(FFIGeos.GEOSUnionCascaded_r(Geos.current_handle_pointer, ptr), srid_copy: srid)
end
unique_points()
valid?() click to toggle source
# File lib/ffi-geos/geometry.rb, line 480
def valid?
  bool_result(FFIGeos.GEOSisValid_r(Geos.current_handle_pointer, ptr))
end
valid_detail(flags = 0) click to toggle source

Returns a Hash containing the following structure on invalid geometries:

{
  detail: "String explaining the problem",
  location: Geos::Point # centered on the problem
}

If the Geometry is valid, returns nil.

# File lib/ffi-geos/geometry.rb, line 497
def valid_detail(flags = 0)
  detail = FFI::MemoryPointer.new(:pointer)
  location = FFI::MemoryPointer.new(:pointer)
  valid = bool_result(
    FFIGeos.GEOSisValidDetail_r(Geos.current_handle_pointer, ptr, flags, detail, location)
  )

  return if valid

  {
    detail: detail.read_pointer.read_string,
    location: cast_geometry_ptr(location.read_pointer, srid_copy: srid)
  }
end
valid_reason() click to toggle source

Returns a String describing whether or not the Geometry is valid.

# File lib/ffi-geos/geometry.rb, line 485
def valid_reason
  FFIGeos.GEOSisValidReason_r(Geos.current_handle_pointer, ptr)
end
voronoi_diagram(options = {}) click to toggle source
voronoi_diagram(tolerance, options = {})

Available in GEOS 3.5.0+

Options:

* :tolerance
* :envelope
* :only_edges
# File lib/ffi-geos/geometry.rb, line 746
def voronoi_diagram(*args)
  options = extract_options!(args)

  tolerance = args.first || options[:tolerance] || 0.0

  envelope_ptr = if options[:envelope]
    check_geometry(options[:envelope])
    options[:envelope].ptr
  end

  only_edges = bool_to_int(options[:only_edges])

  cast_geometry_ptr(FFIGeos.GEOSVoronoiDiagram_r(Geos.current_handle_pointer, ptr, envelope_ptr, tolerance, only_edges))
end
with_precision(grid_size, options = {}) click to toggle source
# File lib/ffi-geos/geometry.rb, line 781
def with_precision(grid_size, options = {})
  options = {
    no_topology: false,
    keep_collapsed: false
  }.merge(options)

  flags = options.reduce(0) do |memo, (key, value)|
    memo |= Geos::PrecisionOptions[key] if value
    memo
  end

  cast_geometry_ptr(FFIGeos.GEOSGeom_setPrecision_r(Geos.current_handle_pointer, ptr, grid_size, flags))
end
within?(geom) click to toggle source
# File lib/ffi-geos/geometry.rb, line 383
def within?(geom)
  check_geometry(geom)
  bool_result(FFIGeos.GEOSWithin_r(Geos.current_handle_pointer, ptr, geom.ptr))
end