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

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Jun 20 21:43:07 EDT 2010


Author: strk
Date: 2010-06-21 01:43:07 +0000 (Mon, 21 Jun 2010)
New Revision: 3052

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

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-21 01:39:50 UTC (rev 3051)
+++ trunk/php/geos.c	2010-06-21 01:43:07 UTC (rev 3052)
@@ -212,6 +212,7 @@
 PHP_METHOD(Geometry, getY);
 PHP_METHOD(Geometry, interiorRingN);
 PHP_METHOD(Geometry, exteriorRing);
+PHP_METHOD(Geometry, numCoordinates);
 
 static function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -258,6 +259,7 @@
     PHP_ME(Geometry, getY, NULL, 0)
     PHP_ME(Geometry, interiorRingN, NULL, 0)
     PHP_ME(Geometry, exteriorRing, NULL, 0)
+    PHP_ME(Geometry, numCoordinates, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -1709,8 +1711,23 @@
     setRelay(return_value, cc);
 }
 
+/**
+ * long GEOSGeometry::numCoordinates()
+ */
+PHP_METHOD(Geometry, numCoordinates)
+{
+    GEOSGeometry *geom;
+    long int ret;
 
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
 
+    ret = GEOSGetNumCoordinates(geom);
+    if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
+
+    RETURN_LONG(ret);
+}
+
+
 /* ------ Initialization / Deinitialization / Meta ------------------ */
 
 /* per-module initialization */

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2010-06-21 01:39:50 UTC (rev 3051)
+++ trunk/php/test/test.php	2010-06-21 01:43:07 UTC (rev 3052)
@@ -1488,4 +1488,43 @@
 
     }
 
+    public function testGeometry_numCoordinates()
+    {
+        $reader = new GEOSWKTReader();
+
+        $g = $reader->read('POINT(0 0)');
+        $this->assertEquals(1, $g->numCoordinates());
+
+        $g = $reader->read('MULTIPOINT (0 1, 2 3)');
+        $this->assertEquals(2, $g->numCoordinates());
+
+        $g = $reader->read('LINESTRING (0 0, 2 3)');
+        $this->assertEquals(2, $g->numCoordinates());
+
+        $g = $reader->read('MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))');
+        $this->assertEquals(4, $g->numCoordinates());
+
+        $g = $reader->read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))');
+        $this->assertEquals(5, $g->numCoordinates());
+
+        $g = $reader->read('MULTIPOLYGON (
+            ((0 0, 1 0, 1 1, 0 1, 0 0)),
+            ((10 10, 10 14, 14 14, 14 10, 10 10),
+                (11 11, 11 12, 12 12, 12 11, 11 11)))');
+        $this->assertEquals(15, $g->numCoordinates());
+
+        $g = $reader->read('GEOMETRYCOLLECTION (
+            MULTIPOLYGON (
+                ((0 0, 1 0, 1 1, 0 1, 0 0)),
+                ((10 10, 10 14, 14 14, 14 10, 10 10),
+                    (11 11, 11 12, 12 12, 12 11, 11 11))
+            ),
+            POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)),
+            MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)),
+            LINESTRING (0 0, 2 3),
+            MULTIPOINT (0 0, 2 3),
+            POINT (9 0))');
+        $this->assertEquals(29, $g->numCoordinates());
+    }
+
 }



More information about the geos-commits mailing list