dazuma/rgeo — pull request #56 by griffordson (2013-08-08 16:03:43+00:00)
Title: Add support for GEOSUnaryUnion_r which is available in GEOS 3.3+

The GEOS UnaryUnion operation performs much better than iteratively unioning a collection of geometries. It is available in GEOS versions 3.3+. FFI-GEOS has had support for it for at least a couple years, so it was easy to add this feature in a way that works for both native interfaces.

I've successfully run the full test suite on the following Ruby interpreters:

* Ruby 1.8.7
* Ruby 1.9.3
* Ruby 2.0.0

I've also run the geos_ffi/tc_misc test case against JRuby 1.7.4 and it runs cleanly there too.

The code for the CAPI and FFI-GEOS implementations test for the presence of the GEOSUnaryUnion_r function and if it is missing, they return nil. GEOSUnaryUnion_r should work against any Geometry object, including a single Point, but it makes the most sense to use it on GeometryCollections. It also works on collections with mixed Geometry types.

I've compared UnaryUnion to iteratively unioning a collection of 4717 real world polys using GEOS directly from C. UnaryUnion finishes in less than 2 seconds while an iterative unioning of all the polys takes over 6 minutes.

See the attached images showing the before and after of the UnaryUnion on that test data.

![before union](https://f.cloud.github.com/assets/16569/932581/b93b96de-0042-11e3-9765-5a9fd23cbe6f.png)
![after union](https://f.cloud.github.com/assets/16569/932585/c7c6bc42-0042-11e3-8c7b-bcaa05067ea8.png)

I know this isn't a trivial change, but I'd love to see it in the official gem if possible. Let me know if there is anything I need to change or clarify to help get it merged.