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

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Jun 20 21:46:52 EDT 2010


Author: strk
Date: 2010-06-21 01:46:52 +0000 (Mon, 21 Jun 2010)
New Revision: 3053

Modified:
   trunk/php/TODO
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
dimension() [ spatial ]

Modified: trunk/php/TODO
===================================================================
--- trunk/php/TODO	2010-06-21 01:43:07 UTC (rev 3052)
+++ trunk/php/TODO	2010-06-21 01:46:52 UTC (rev 3053)
@@ -2,6 +2,8 @@
 
 - Complete interfaces of Geometry
  - Normalize ? (is the only modifier function)
+ - CoordSeq accessors ?
+ - Constructors ?
 - Find a way to have GEOSGeometry contents shown on var_dump
 - Implement serialization/deserialization for Geometry
 - Documentation !! (doxygen-based?)

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-21 01:43:07 UTC (rev 3052)
+++ trunk/php/geos.c	2010-06-21 01:46:52 UTC (rev 3053)
@@ -213,6 +213,7 @@
 PHP_METHOD(Geometry, interiorRingN);
 PHP_METHOD(Geometry, exteriorRing);
 PHP_METHOD(Geometry, numCoordinates);
+PHP_METHOD(Geometry, dimension);
 
 static function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -260,6 +261,7 @@
     PHP_ME(Geometry, interiorRingN, NULL, 0)
     PHP_ME(Geometry, exteriorRing, NULL, 0)
     PHP_ME(Geometry, numCoordinates, NULL, 0)
+    PHP_ME(Geometry, dimension, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -1727,7 +1729,24 @@
     RETURN_LONG(ret);
 }
 
+/**
+ * long GEOSGeometry::dimension()
+ * 0:puntual 1:lineal 2:areal
+ */
+PHP_METHOD(Geometry, dimension)
+{
+    GEOSGeometry *geom;
+    long int ret;
 
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    ret = GEOSGeom_getDimensions(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:43:07 UTC (rev 3052)
+++ trunk/php/test/test.php	2010-06-21 01:46:52 UTC (rev 3053)
@@ -1527,4 +1527,43 @@
         $this->assertEquals(29, $g->numCoordinates());
     }
 
+    public function testGeometry_dimension()
+    {
+        $reader = new GEOSWKTReader();
+
+        $g = $reader->read('POINT(0 0)');
+        $this->assertEquals(0, $g->dimension());
+
+        $g = $reader->read('MULTIPOINT (0 1, 2 3)');
+        $this->assertEquals(0, $g->dimension());
+
+        $g = $reader->read('LINESTRING (0 0, 2 3)');
+        $this->assertEquals(1, $g->dimension());
+
+        $g = $reader->read('MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))');
+        $this->assertEquals(1, $g->dimension());
+
+        $g = $reader->read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))');
+        $this->assertEquals(2, $g->dimension());
+
+        $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(2, $g->dimension());
+
+        $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(2, $g->dimension());
+    }
+
 }



More information about the geos-commits mailing list