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

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Jun 20 21:36:53 EDT 2010


Author: strk
Date: 2010-06-21 01:36:53 +0000 (Mon, 21 Jun 2010)
New Revision: 3050

Modified:
   trunk/php/TODO
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
numPoints, getX, getY, interiorRingN


Modified: trunk/php/TODO
===================================================================
--- trunk/php/TODO	2010-06-21 01:34:51 UTC (rev 3049)
+++ trunk/php/TODO	2010-06-21 01:36:53 UTC (rev 3050)
@@ -1,6 +1,7 @@
 In order of priority
 
 - Complete interfaces of Geometry
+ - Normalize ? (is the only modifier function)
 - 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:34:51 UTC (rev 3049)
+++ trunk/php/geos.c	2010-06-21 01:36:53 UTC (rev 3050)
@@ -207,6 +207,10 @@
 PHP_METHOD(Geometry, numGeometries);
 PHP_METHOD(Geometry, getGeometryN);
 PHP_METHOD(Geometry, numInteriorRings);
+PHP_METHOD(Geometry, numPoints);
+PHP_METHOD(Geometry, getX);
+PHP_METHOD(Geometry, getY);
+PHP_METHOD(Geometry, interiorRingN);
 
 static function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -248,6 +252,10 @@
     PHP_ME(Geometry, numGeometries, NULL, 0)
     PHP_ME(Geometry, getGeometryN, NULL, 0)
     PHP_ME(Geometry, numInteriorRings, NULL, 0)
+    PHP_ME(Geometry, numPoints, NULL, 0)
+    PHP_ME(Geometry, getX, NULL, 0)
+    PHP_ME(Geometry, getY, NULL, 0)
+    PHP_ME(Geometry, interiorRingN, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -1603,8 +1611,84 @@
     RETURN_LONG(ret);
 }
 
+/**
+ * long GEOSGeometry::numPoints()
+ */
+PHP_METHOD(Geometry, numPoints)
+{
+    GEOSGeometry *geom;
+    long int ret;
 
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
 
+    ret = GEOSGeomGetNumPoints(geom);
+    if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
+
+    RETURN_LONG(ret);
+}
+
+/**
+ * double GEOSGeometry::getX()
+ */
+PHP_METHOD(Geometry, getX)
+{
+    GEOSGeometry *geom;
+    int ret;
+    double x;
+
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    ret = GEOSGeomGetX(geom, &x);
+    if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
+
+    RETURN_DOUBLE(x);
+}
+
+/**
+ * double GEOSGeometry::getY()
+ */
+PHP_METHOD(Geometry, getY)
+{
+    GEOSGeometry *geom;
+    int ret;
+    double y;
+
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    ret = GEOSGeomGetY(geom, &y);
+    if ( ret == -1 ) RETURN_NULL(); /* should get an exception first */
+
+    RETURN_DOUBLE(y);
+}
+
+/**
+ * GEOSGeometry GEOSGeometry::interiorRingN()
+ */
+PHP_METHOD(Geometry, interiorRingN)
+{
+    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 = GEOSGetInteriorRingN(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:34:51 UTC (rev 3049)
+++ trunk/php/test/test.php	2010-06-21 01:36:53 UTC (rev 3050)
@@ -1378,7 +1378,7 @@
 
         $g = $reader->read('POINT (0 0)');
         try {
-            $this->assertEquals(2, $g->numInteriorRings());
+            $g->numInteriorRings();
             $this->assertTrue( FALSE );
         } catch (Exception $e) {
             $this->assertContains( 'Polygon', $e->getMessage() );
@@ -1386,4 +1386,83 @@
 
     }
 
+    public function testGeometry_numPoints()
+    {
+        $reader = new GEOSWKTReader();
+
+        $g = $reader->read('LINESTRING (0 0, 1 0, 1 1, 0 1)');
+        $this->assertEquals(4, $g->numPoints());
+
+        $g = $reader->read('POINT (0 0)');
+        try {
+            $g->numPoints();
+            $this->assertTrue( FALSE );
+        } catch (Exception $e) {
+            $this->assertContains( 'LineString', $e->getMessage() );
+        }
+
+    }
+
+    public function testGeometry_getXY()
+    {
+        $reader = new GEOSWKTReader();
+
+        $g = $reader->read('POINT (1 2)');
+        $this->assertEquals(1, $g->getX());
+        $this->assertEquals(2, $g->getY());
+
+        $g = $reader->read('LINESTRING (0 0, 1 1)');
+        try {
+            $g->getX();
+            $this->assertTrue( FALSE );
+        } catch (Exception $e) {
+            $this->assertContains( 'Point', $e->getMessage() );
+        }
+
+        try {
+            $g->getY();
+            $this->assertTrue( FALSE );
+        } catch (Exception $e) {
+            $this->assertContains( 'Point', $e->getMessage() );
+        }
+
+    }
+
+    public function testGeometry_interiorRingN()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+        $g = $reader->read('POLYGON (
+            (10 10, 10 14, 14 14, 14 10, 10 10),
+                (11 11, 11 12, 12 12, 12 11, 11 11))');
+        $r = $g->interiorRingN(0);
+        $this->assertEquals('LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
+            $writer->write($r) );
+
+        $g = $reader->read('POLYGON (
+            (10 10, 10 14, 14 14, 14 10, 10 10),
+                (11 11, 11 12, 12 12, 12 11, 11 11),
+                (13 11, 13 12, 13.5 12, 13.5 11, 13 11))');
+        $r = $g->interiorRingN(0);
+        $this->assertEquals('LINEARRING (11 11, 11 12, 12 12, 12 11, 11 11)',
+            $writer->write($r) );
+        $r = $g->interiorRingN(1);
+        $this->assertEquals('LINEARRING (13 11, 13 12, 14 12, 14 11, 13 11)',
+            $writer->write($r) );
+
+        $g = $reader->read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))');
+        $this->assertNull($g->interiorRingN(0));
+
+        $g = $reader->read('POINT (0 0)');
+        try {
+            $g->interiorRingN(0);
+            $this->assertTrue( FALSE );
+        } catch (Exception $e) {
+            $this->assertContains( 'Polygon', $e->getMessage() );
+        }
+
+    }
+
 }



More information about the geos-commits mailing list