GEOS Ruby Bindings via FFI

Requirements

  • the ffi extension for Ruby.

  • GEOS version 3.3.0 or greater. GEOS 3.2.2 and below will work to an extent, but some features and methods will be disabled or missing.

Ruby versions known to work:

  • Ruby MRI 1.8.7, 1.9.2 and 1.9.3 x86_64, OSX 10.6.5+

  • Ruby MRI 1.8.7 and 1.9.2, i386, linux

  • Ruby MRI 1.8.7, 1.9.2 and 1.9.3, x86_64, linux

  • JRuby 1.6, x86_64 OSX 10.6.5+

JRuby Notes

Note that versions of JRuby prior to version 1.6.3 have problems in their ffi implementation when dealing with AutoPointers that can lead to segfaults during garbage collection.

JRuby 1.7.0 is exhibiting some strange and sporadic memory problems that are difficult to lock down. Unit tests show that the errors do not occur 100% of the time, so it has been difficult to trace the root cause of the errors.

Features

ffi-geos supports all of the features found in the binary SWIG-based GEOS Ruby bindings along with the following enhancements and additions:

  • support for prepared geometries via Geos::Geometry#to_prepared.

  • an implementation of Geos::STRtree.

  • use of GEOS’s re-entrant interface for thread-safety.

  • new options for controlling WKT output like trim and rounding precision.

  • many new methods on geometry types. See below for a list.

  • Geos::LineString, Geos::LinearRing, Geos::CoordinateSequence and Geos::GeometryCollection and its descendants are now enumerable.

  • The aforementioned enumerable classes also define some additional Array-like methods such as [] and slice.

  • Geos::WkbWriter and Geos::WktWriter have had their constructors extended to allow for settings via an options Hash.

  • Geos::WkbWriter#write, Geos::WkbWriter#write_hex and Geos::WktWriter#write have been enhanced to take options Hashes allowing you to set per-write settings.

  • Geos::BufferParams class that allows for more extensive Geos::Geometry#buffer options.

  • Geos::PreparedGeometry class and Geos::Geometry#to_prepared method to allow for prepared geometries and more efficient relationship testing.

New Methods and Additions (not exhaustive)

  • SRIDs can be copied on many operations. GEOS doesn’t usually copy SRIDs around, but for the sake of convenience, we do. The default behaviour for SRID copying can be set via the Geos.srid_copy_policy= method. The default behaviour is to use 0 values as before, but you can optionally allow for copying in either a lenient or a strict sort of manner. See the documentation for Geos.srid_copy_policy= for details.

Geos

  • Geos.create_multi_point

  • Geos.create_multi_line_string

  • Geos.create_multi_polygon

  • Geos.create_geometry_collection

  • Geos.create_collection

  • Geos.create_empty_point

  • Geos.create_empty_polygon

  • Geos.create_empty_line_string

  • Geos.create_empty_multi_point

  • Geos.create_empty_multi_line_string

  • Geos.create_empty_multi_polygon

  • Geos.create_empty_geometry_collection

Geos::Geometry

  • Geos::Geometry#num_coordinates

  • Geos::Geometry#union_cascaded. Geos::Geometry#union can also be called without a geometry argument to produce the same effect.

  • Geos::Geometry#extract_unique_points (aliased to Geos::Geometry#unique_points)

  • Geos::Geometry#valid_reason

  • Geos::Geometry#valid_detail

  • Geos::Geometry#project

  • Geos::Geometry#project_normalized

  • Geos::Geometry#interpolate

  • Geos::Geometry#interpolate_normalized

  • Geos::Geometry#start_point

  • Geos::Geometry#end_point

  • Geos::Geometry#hausdorff_distance

  • Geos::Geometry#snap

  • Geos::Geometry#shared_paths

  • Geos::Geometry#polygonize_full

  • Geos::Geometry#polygonize

  • Geos::Geometry#polygonize_cut_edges

  • Geos::Geometry#to_prepared

Geos::LineString and Geos::LinearRing

  • Geos::LineString#num_points

  • Geos::LineString#point_n

  • Geos::LineString#closed?

Geos::WktWriter

  • Geos::WktWriter#trim=

  • Geos::WktWriter#rounding_precision=

  • Geos::WktWriter#old_3d=

Geos::Utils

  • Geos::Utils.orientation_index

Thanks

  • Thanks to Daniel Azuma for the testing and JRuby help.

  • Christopher Meiklejohn for the bug reporting and PreparedGeometry fix.

  • Wayne Meissner for some help with some ffi issues.

  • Charlie Savage for the original SWIG-based GEOS bindings implementation and some fixes for MinGW.

License

This gem is licensed under an MIT-style license. See the MIT-LICENSE file for details.