GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS). This includes all the OpenGIS Simple Features for SQL spatial predicate functions and spatial operators. GeoPHP transparently integrates GEOS. If geoPHP detects that GEOS is installed it will automatically start using it - you don't need to do anything. When GEOS is installed, a bunch of additional geometry methods become available (detailed in the API Reference).
When you install GEOS you also get some pretty awesome automatic performance improvements.
You can learn more about GEOS on its website at http://trac.osgeo.org/geos
You don't need to do anything special to integrate GEOS, just install it. However, if you want to make use of special GEOS functions that are not part of OpenGIS Standard (there aren't many), then you need to call them explicitly. Lucky for you, this is easy to do. Example:
$geos_geom = $foo->geos(); $geos_result = $bar->geos()->relateBoundaryNodeRule($geos_geom); // Put it back into a geoPHP geometry $geometry = geoPHP::geosToGeometry($geos_result);
However, it's unlikely that you will need to do this since most methods are cleanly wrapped and can be called directly from a geoPHP geometry. To get a list of all available methods see http://trac.osgeo.org/geos/browser/trunk/php/geos.c
To install GEOS with it's PHP extension, you need to compile it from source. This may sound scary, but it's really quite easy! Various instructions on installing GEOS (with the requisite PHP extension) can be found here:
MAMP users: See GEOS Installation on OSX with MAMP for special requirements.
CentOS 6 users: See GEOS Installation on CentOS6 for special instructions.
Below are some simple performance tests that I ran using both a large set of roads (2MB of JSON), and a really simple polygon. For the polygon, I looped the test 3000 times to get an average.
The results are number of seconds to complete the operation (lower is better). As you can see installing the geos-php extension at least doubles performance and can, in some cases, lead to a 10x improvement in performance.
Without Geos: 1.2631900310516 secs With Geos: 0.6027820110321 secs
Without Geos: 1.2799670696259 secs With Geos: 0.6133630275726 secs
Without Geos: 0.21501302719116 secs With Geos: 0.03558087348938 secs
Without Geos: 0.073577880859375 secs With Geos: 0.009435892105102 secs
Without Geos: 0.09908390045166 secs With Geos: 0.05712819099426 secs
Without Geos: 11.156386852264 secs With Geos: 7.8141958713531 secs
Without Geos: 13.316060066223 secs With Geos: 2.0791599750519 secs
Last edited by phayes,