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

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Jun 20 22:02:05 EDT 2010


Author: strk
Date: 2010-06-21 02:02:05 +0000 (Mon, 21 Jun 2010)
New Revision: 3057

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
startPoint, endPoint


Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-21 01:58:23 UTC (rev 3056)
+++ trunk/php/geos.c	2010-06-21 02:02:05 UTC (rev 3057)
@@ -216,6 +216,8 @@
 PHP_METHOD(Geometry, dimension);
 PHP_METHOD(Geometry, coordinateDimension);
 PHP_METHOD(Geometry, pointN);
+PHP_METHOD(Geometry, startPoint);
+PHP_METHOD(Geometry, endPoint);
 
 static function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -266,6 +268,8 @@
     PHP_ME(Geometry, dimension, NULL, 0)
     PHP_ME(Geometry, coordinateDimension, NULL, 0)
     PHP_ME(Geometry, pointN, NULL, 0)
+    PHP_ME(Geometry, startPoint, NULL, 0)
+    PHP_ME(Geometry, endPoint, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -1792,7 +1796,46 @@
     setRelay(return_value, cc);
 }
 
+/**
+ * GEOSGeometry GEOSGeometry::startPoint()
+ */
+PHP_METHOD(Geometry, startPoint)
+{
+    GEOSGeometry *geom;
+    const GEOSGeometry *c;
+    GEOSGeometry *cc;
 
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    c = GEOSGeomGetStartPoint(geom);
+    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);
+}
+
+/**
+ * GEOSGeometry GEOSGeometry::endPoint()
+ */
+PHP_METHOD(Geometry, endPoint)
+{
+    GEOSGeometry *geom;
+    const GEOSGeometry *c;
+    GEOSGeometry *cc;
+
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    c = GEOSGeomGetEndPoint(geom);
+    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:58:23 UTC (rev 3056)
+++ trunk/php/test/test.php	2010-06-21 02:02:05 UTC (rev 3057)
@@ -1606,4 +1606,29 @@
         }
 
     }
+
+    public function testGeometry_startendPoint()
+    {
+        $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->startPoint()) );
+        $this->assertEquals('POINT (14 10)', $writer->write($g->endPoint()) );
+        $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->startPoint()) );
+        $this->assertEquals('POINT (11 11)', $writer->write($g->endPoint()) );
+
+        $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