[geos-commits] r3984 - in trunk/php: . test

svn_geos at osgeo.org svn_geos at osgeo.org
Wed May 21 07:21:10 PDT 2014


Author: strk
Date: 2014-05-21 07:21:10 -0700 (Wed, 21 May 2014)
New Revision: 3984

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Expose Geometry.voronoiDiagram in PHP interface

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2014-05-21 14:21:02 UTC (rev 3983)
+++ trunk/php/geos.c	2014-05-21 14:21:10 UTC (rev 3984)
@@ -242,6 +242,7 @@
 PHP_METHOD(Geometry, snapTo);
 PHP_METHOD(Geometry, node);
 PHP_METHOD(Geometry, delaunayTriangulation);
+PHP_METHOD(Geometry, voronoiDiagram);
 
 static zend_function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -305,6 +306,7 @@
     PHP_ME(Geometry, snapTo, NULL, 0)
     PHP_ME(Geometry, node, NULL, 0)
     PHP_ME(Geometry, delaunayTriangulation, NULL, 0)
+    PHP_ME(Geometry, voronoiDiagram, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -2587,11 +2589,10 @@
 /**
  * GEOSGeometry::delaunayTriangulation([<tolerance>], [<onlyEdges>])
  *
- * styleArray keys supported:
  *  'tolerance'
  *       Type: double
  *       snapping tolerance to use for improved robustness
- *  'edgesOnly'
+ *  'onlyEdges'
  *       Type: boolean
  *       if true will return a MULTILINESTRING, otherwise (the default)
  *       it will return a GEOMETRYCOLLECTION containing triangular POLYGONs.
@@ -2619,6 +2620,40 @@
 }
 
 /**
+ * GEOSGeometry::voronoiDiagram([<tolerance>], [<onlyEdges>])
+ *
+ * styleArray keys supported:
+ *  'tolerance'
+ *       Type: double
+ *       snapping tolerance to use for improved robustness
+ *  'onlyEdges'
+ *       Type: boolean
+ *       if true will return a MULTILINESTRING, otherwise (the default)
+ *       it will return a GEOMETRYCOLLECTION containing POLYGONs.
+ */
+PHP_METHOD(Geometry, voronoiDiagram)
+{
+    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 = GEOSVoronoiDiagram(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)
  */
 PHP_FUNCTION(GEOSRelateMatch)

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2014-05-21 14:21:02 UTC (rev 3983)
+++ trunk/php/test/test.php	2014-05-21 14:21:10 UTC (rev 3984)
@@ -2037,6 +2037,26 @@
 
     }
 
+    public function testGeometry_voronoiDiagram()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+        $g = $reader->read('MULTIPOINT(0 0, 100 0, 100 100, 0 100)');
+
+        $b = $g->voronoiDiagram(0);
+        $this->assertEquals(
+'GEOMETRYCOLLECTION (POLYGON ((50 200, 200 200, 200 50, 50 50, 50 200)), POLYGON ((-100 50, -100 200, 50 200, 50 50, -100 50)), POLYGON ((50 -100, -100 -100, -100 50, 50 50, 50 -100)), POLYGON ((200 50, 200 -100, 50 -100, 50 50, 200 50)))'
+            , $writer->write($b));
+
+        $b = $g->voronoiDiagram(0, 1);
+        $this->assertEquals(
+'MULTILINESTRING ((50 50, 50 200), (200 50, 50 50), (50 50, -100 50), (50 50, 50 -100))'
+            , $writer->write($b));
+
+    }
+
     public function testGeometry_snapTo()
     {
         $reader = new GEOSWKTReader();



More information about the geos-commits mailing list