[geos-devel] GEOS FFI Ruby bindings now on github

J Smith dark.panda+lists at gmail.com
Sat Dec 4 21:56:51 EST 2010


Howdy y'all.

I just finished pushing an implementation of the FFI-based GEOS Ruby
bindings to github. The new repository is available here:

https://github.com/dark-panda/ffi-geos

Included in the code:

- the code is built on the current svn trunk and definitely bombs out
using GEOS 3.2.2 at the moment. You can set the GEOS_LIBRARY_PATH
environment variable to point towards a GEOS install to run against,
and by default we look in the usual locations. (/usr/lib,
/usr/local/lib, /opt/local/lib, etc.)

- we're using the re-entrant CAPI functions. The TS handle is set in
Thread.current[:ffi_geos_handle] and calling Geos.current_handle grabs
whatever the current handle as well as initializes one if none exists
in the current thread.

- a test suite based mostly on the PHP extension's test suite.
Included are 99 tests and 481 assertions. The same test suite can be
run against the binary SWIG-based library too to help with
compatibility testing. Set the USE_BINARY_GEM environment variable to
run against the old GEOS binary. (This is kind of a poorly named
variable -- on my system I do have the original binary extension set
up as a gem, but that hasn't been released yet, so this name is
awkward, but I'm way too tired to change it at this point.) Anyways,
the test suite will run 75 tests and 354 assertions against the old
library, as it will skip any functionality not implemented in the
older build.

- extra goodies like rounding_precision and all that jazz.

- new functionality like polygonize et al, hausdorff_distance,
union_cascaded, extract_unique_points, valid_reason and valid_detail,
project, interpolate, point_n, start_point, end_point, snap,
shared_paths, and stuff I can't even begin to remember at the moment.

- Ruby's FFI bindings can't do varargs in callbacks, so the error
handling code the C API can't report its errors to Ruby at the moment.
All errors thrown from the C API unfortunately show up as
RuntimeErrors without much of an explanation other than a back trace.
I don't think there's much we can do about that short of re-jiggering
how the C API reports errors.

- I think there's a few methods I forgot to implement -- I'm seeing
module functions for Geos.create_point, create_polygon, etc., which I
never noticed before and don't personally use Whoops. I'll add those
tomorrow.

- I've made GeometryCollection an enumerable as I did in my other
extensions module.

Outside of the unit tests I haven't had a chance to try this in any
sort of real-world situation like testing it out on a major
application; I literally finished writing things up as I'm typing
this, so this is very much an alpha and anyone using it for anything
serious at the moment is crazy, 'cause this thing needs to be
thoroughly tested and re-tested and so on.

The Big To Do List:

- documentation. I basically just wrote code flat out and nonstop,
rdoc API docs would be nice.

- implement those aforementioned functions for create_point,
create_polygon, etc. I forgot about, along with any other functions I
might have missed.

- testing on platforms other than my laptop. I haven't run this code
outside of my MacBook, so the only platform known to work at the
moment is OSX 10.6.5 in 64-bit mode running Ruby 1.8.7-p302. I tried
running with Ruby 1.9.2-p0 but I'm getting segfaults coming out of
FFI, so more investigation is needed on that front.

- look for memory leaks and stuff. I don't know if I'm cleaning up
everything as I should be.

- optimize for performance. The code isn't all that much slower than
the current bindings, but it is slower.

- other clean ups.

Anyways, that's the code in a nut shell. Comments and patches are welcomed!

Cheers!


More information about the geos-devel mailing list