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

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Dec 2 11:48:24 EST 2010


Author: strk
Date: 2010-12-02 08:48:24 -0800 (Thu, 02 Dec 2010)
New Revision: 3148

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Expose GEOSSnap to PHP interface


Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-12-02 16:44:03 UTC (rev 3147)
+++ trunk/php/geos.c	2010-12-02 16:48:24 UTC (rev 3148)
@@ -225,6 +225,7 @@
 PHP_METHOD(Geometry, length);
 PHP_METHOD(Geometry, distance);
 PHP_METHOD(Geometry, hausdorffDistance);
+PHP_METHOD(Geometry, snapTo);
 
 static function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -281,6 +282,7 @@
     PHP_ME(Geometry, length, NULL, 0)
     PHP_ME(Geometry, distance, NULL, 0)
     PHP_ME(Geometry, hausdorffDistance, NULL, 0)
+    PHP_ME(Geometry, snapTo, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -1680,7 +1682,32 @@
     RETURN_DOUBLE(dist);
 }
 
+PHP_METHOD(Geometry, snapTo)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    GEOSGeometry *ret;
+    double tolerance;
+    zval *zobj;
 
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "od", &zobj,
+            &tolerance) == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSSnap(this, other, tolerance);
+    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);
+}
+
+
+
 /* -- class GEOSWKTReader -------------------- */
 
 PHP_METHOD(WKTReader, __construct);

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2010-12-02 16:44:03 UTC (rev 3147)
+++ trunk/php/test/test.php	2010-12-02 16:48:24 UTC (rev 3148)
@@ -1778,6 +1778,25 @@
 
     }
 
+    public function testGeometry_snapTo()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setTrim(true);
+
+        $g = $reader->read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))');
+
+        $g2 = $reader->read('POINT(0.1 0)');
+
+        $snapped = $g->snapTo($g2, 0);
+        $this->assertEquals('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
+            , $writer->write($snapped) );
+
+        $snapped = $g->snapTo($g2, 0.5);
+        $this->assertEquals('POLYGON ((0.1 0, 1 0, 1 1, 0 1, 0.1 0))'
+            , $writer->write($snapped) );
+    }
+
     public function testWKBWriter__construct()
     {
         $writer = new GEOSWKBWriter();



More information about the geos-commits mailing list