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

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Jun 20 21:58:23 EDT 2010


Author: strk
Date: 2010-06-21 01:58:23 +0000 (Mon, 21 Jun 2010)
New Revision: 3056

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
pointN


Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-21 01:57:50 UTC (rev 3055)
+++ trunk/php/geos.c	2010-06-21 01:58:23 UTC (rev 3056)
@@ -215,6 +215,7 @@
 PHP_METHOD(Geometry, numCoordinates);
 PHP_METHOD(Geometry, dimension);
 PHP_METHOD(Geometry, coordinateDimension);
+PHP_METHOD(Geometry, pointN);
 
 static function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -264,6 +265,7 @@
     PHP_ME(Geometry, numCoordinates, NULL, 0)
     PHP_ME(Geometry, dimension, NULL, 0)
     PHP_ME(Geometry, coordinateDimension, NULL, 0)
+    PHP_ME(Geometry, pointN, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -1764,7 +1766,33 @@
     RETURN_LONG(ret);
 }
 
+/**
+ * GEOSGeometry GEOSGeometry::pointN()
+ */
+PHP_METHOD(Geometry, pointN)
+{
+    GEOSGeometry *geom;
+    const GEOSGeometry *c;
+    GEOSGeometry *cc;
+    long int num;
 
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
+        &num) == FAILURE) {
+        RETURN_NULL();
+    }
+
+    c = GEOSGeomGetPointN(geom, num);
+    if ( ! c ) RETURN_NULL(); /* should get an exception first */
+    cc = GEOSGeom_clone(c);
+    if ( ! cc ) RETURN_NULL(); /* should get an exception first */
+
+    object_init_ex(return_value, Geometry_ce_ptr);
+    setRelay(return_value, cc);
+}
+
+
 /* ------ Initialization / Deinitialization / Meta ------------------ */
 
 /* per-module initialization */

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2010-06-21 01:57:50 UTC (rev 3055)
+++ trunk/php/test/test.php	2010-06-21 01:58:23 UTC (rev 3056)
@@ -1578,4 +1578,32 @@
 
     }
 
+    public function testGeometry_pointN()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+        $g = $reader->read('LINESTRING (10 10, 10 14, 14 14, 14 10)');
+        $this->assertEquals('POINT (10 10)', $writer->write($g->pointN(0)) );
+        $this->assertEquals('POINT (10 14)', $writer->write($g->pointN(1)) );
+        $this->assertEquals('POINT (14 14)', $writer->write($g->pointN(2)) );
+        $this->assertEquals('POINT (14 10)', $writer->write($g->pointN(3)) );
+        $this->assertNull( $g->pointN(4) );
+
+        $g = $reader->read('LINEARRING (11 11, 11 12, 12 11, 11 11)');
+        $this->assertEquals('POINT (11 11)', $writer->write($g->pointN(0)) );
+        $this->assertEquals('POINT (11 12)', $writer->write($g->pointN(1)) );
+        $this->assertEquals('POINT (12 11)', $writer->write($g->pointN(2)) );
+        $this->assertEquals('POINT (11 11)', $writer->write($g->pointN(3)) );
+
+        $g = $reader->read('POINT (0 0)');
+        try {
+            $g->pointN(0);
+            $this->assertTrue( FALSE );
+        } catch (Exception $e) {
+            $this->assertContains( 'LineString', $e->getMessage() );
+        }
+
+    }
 }



More information about the geos-commits mailing list