From 55f79ada6cf86ee0fade97aeac4f7b4d6d98a546 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 11 Jul 2013 08:21:54 +0000 Subject: [PATCH] Expose Delaunay triangulation to PHP API (#567) git-svn-id: http://svn.osgeo.org/geos/trunk@3834 5242fede-7e19-0410-aef8-94bd7d2200fb --- NEWS | 2 +- php/geos.c | 36 ++++++++++++++++++++++++++++++++++++ php/test/test.php | 20 ++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ec57da7f95..57e2d7b980 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ Changes in 3.4.0 ????-??-?? - New things: - - Delaunay Triangulation API (#487, #565, #570) + - Delaunay Triangulation API (#487, #565, #570, #567) - Interruptibility API (C and C++) - CAPI: GEOSNode (#496) - PHP: Geometry->node - GeometryPrecisionReducer class diff --git a/php/geos.c b/php/geos.c index a21726eb0b..bd4d89ec65 100644 --- a/php/geos.c +++ b/php/geos.c @@ -241,6 +241,7 @@ PHP_METHOD(Geometry, distance); PHP_METHOD(Geometry, hausdorffDistance); PHP_METHOD(Geometry, snapTo); PHP_METHOD(Geometry, node); +PHP_METHOD(Geometry, delaunayTriangulation); static zend_function_entry Geometry_methods[] = { PHP_ME(Geometry, __construct, NULL, 0) @@ -303,6 +304,7 @@ static zend_function_entry Geometry_methods[] = { PHP_ME(Geometry, hausdorffDistance, NULL, 0) PHP_ME(Geometry, snapTo, NULL, 0) PHP_ME(Geometry, node, NULL, 0) + PHP_ME(Geometry, delaunayTriangulation, NULL, 0) {NULL, NULL, NULL} }; @@ -2582,6 +2584,40 @@ PHP_FUNCTION(GEOSSharedPaths) setRelay(return_value, geom_out); } +/** + * GEOSGeometry::delaunayTriangulation([], []) + * + * styleArray keys supported: + * 'tolerance' + * Type: double + * snapping tolerance to use for improved robustness + * 'edgesOnly' + * Type: boolean + * if true will return a MULTILINESTRING, otherwise (the default) + * it will return a GEOMETRYCOLLECTION containing triangular POLYGONs. + */ +PHP_METHOD(Geometry, delaunayTriangulation) +{ + GEOSGeometry *this; + GEOSGeometry *ret; + double tolerance = 0.0; + zend_bool edgeonly = 0; + + this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|db", + &tolerance, &edgeonly) == FAILURE) { + RETURN_NULL(); + } + + ret = GEOSDelaunayTriangulation(this, tolerance, edgeonly ? 1 : 0); + if ( ! ret ) RETURN_NULL(); /* should get an exception first */ + + /* return_value is a zval */ + object_init_ex(return_value, Geometry_ce_ptr); + setRelay(return_value, ret); +} + /** * bool GEOSRelateMatch(string matrix, string pattern) */ diff --git a/php/test/test.php b/php/test/test.php index 63490a5188..4c8db6edf9 100644 --- a/php/test/test.php +++ b/php/test/test.php @@ -2017,6 +2017,26 @@ public function testGeometry_hausdorffDistance() } + public function testGeometry_delaunayTriangulation() + { + $reader = new GEOSWKTReader(); + $writer = new GEOSWKTWriter(); + $writer->setRoundingPrecision(0); + + $g = $reader->read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'); + + $b = $g->delaunayTriangulation(); + $this->assertEquals( +'GEOMETRYCOLLECTION (POLYGON ((0 1, 0 0, 1 0, 0 1)), POLYGON ((0 1, 1 0, 1 1, 0 1)))' + , $writer->write($b)); + + $b = $g->delaunayTriangulation(0,true); + $this->assertEquals( +'MULTILINESTRING ((0 1, 1 1), (0 0, 0 1), (0 0, 1 0), (1 0, 1 1), (0 1, 1 0))' + , $writer->write($b)); + + } + public function testGeometry_snapTo() { $reader = new GEOSWKTReader();