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

svn_geos at osgeo.org svn_geos at osgeo.org
Sat Jun 19 17:36:42 EDT 2010


Author: strk
Date: 2010-06-19 21:36:42 +0000 (Sat, 19 Jun 2010)
New Revision: 3029

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
relate, relatePattern


Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-19 18:27:12 UTC (rev 3028)
+++ trunk/php/geos.c	2010-06-19 21:36:42 UTC (rev 3029)
@@ -187,6 +187,7 @@
 PHP_METHOD(Geometry, union); /* also does union cascaded */
 PHP_METHOD(Geometry, pointOnSurface); 
 PHP_METHOD(Geometry, centroid); 
+PHP_METHOD(Geometry, relate); 
 
 PHP_METHOD(Geometry, numGeometries);
 
@@ -204,6 +205,7 @@
     PHP_ME(Geometry, union, NULL, 0)
     PHP_ME(Geometry, pointOnSurface, NULL, 0)
     PHP_ME(Geometry, centroid, NULL, 0)
+    PHP_ME(Geometry, relate, NULL, 0)
 
     PHP_ME(Geometry, numGeometries, NULL, 0)
     {NULL, NULL, NULL}
@@ -571,6 +573,47 @@
     setRelay(return_value, ret);
 }
 
+/**
+ * GEOSGeometry::relate(otherGeom)
+ * GEOSGeometry::relate(otherGeom, pattern)
+ */
+PHP_METHOD(Geometry, relate)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    zval *zobj;
+    char* pat = NULL;
+    int patlen;
+    int retInt;
+    zend_bool retBool;
+    char* retStr;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|s",
+        &zobj, &pat, &patlen) == FAILURE)
+    {
+        RETURN_NULL();
+    }
+
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    if ( ! pat ) {
+        /* we'll compute it */
+        pat = GEOSRelate(this, other);
+        if ( ! pat ) RETURN_NULL(); /* should get an exception first */
+        retStr = estrdup(pat);
+        GEOSFree(pat);
+        RETURN_STRING(retStr, 0);
+    } else {
+        retInt = GEOSRelatePattern(this, other, pat);
+        if ( retInt == 2 ) RETURN_NULL(); /* should get an exception first */
+        retBool = retInt;
+        RETURN_BOOL(retBool);
+    }
+
+}
+
 /* -- class GEOSWKTReader -------------------- */
 
 PHP_METHOD(WKTReader, __construct);

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2010-06-19 18:27:12 UTC (rev 3028)
+++ trunk/php/test/test.php	2010-06-19 21:36:42 UTC (rev 3029)
@@ -853,4 +853,45 @@
 'POINT (5 4)'
             , $writer->write($b));
     }
+
+    public function testGeometry_relate()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+        $g = $reader->read('POINT(0 0)');
+        $g2 = $reader->read('POINT(0 0)');
+        $ret = $g->relate($g2);
+        $this->assertEquals('0FFFFFFF2', $ret);
+        $ret = $g->relate($g2, '0FFFFFFF2');
+        $this->assertEquals(TRUE, $ret);
+        $ret = $g->relate($g2, '0*******2');
+        $this->assertEquals(TRUE, $ret);
+        $ret = $g->relate($g2, '0*******1');
+        $this->assertEquals(FALSE, $ret);
+
+        $g = $reader->read('POINT(0 0)');
+        $g2 = $reader->read('POINT(1 0)');
+        $ret = $g->relate($g2);
+        $this->assertEquals('FF0FFF0F2', $ret);
+        $ret = $g->relate($g2, 'FF0FFF0F2');
+        $this->assertEquals(TRUE, $ret);
+        $ret = $g->relate($g2, 'F*******2');
+        $this->assertEquals(TRUE, $ret);
+        $ret = $g->relate($g2, 'T*******2');
+        $this->assertEquals(FALSE, $ret);
+
+        $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))');
+        $g2 = $reader->read('POINT(1 0)');
+        $ret = $g->relate($g2);
+        $this->assertEquals('FF20F1FF2', $ret);
+        $ret = $g->relate($g2, 'FF20F1FF2');
+        $this->assertEquals(TRUE, $ret);
+        $ret = $g->relate($g2, 'F*******2');
+        $this->assertEquals(TRUE, $ret);
+        $ret = $g->relate($g2, 'T*******2');
+        $this->assertEquals(FALSE, $ret);
+
+    }
 }



More information about the geos-commits mailing list