[geos-commits] r3032 - trunk/php

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Jun 20 04:50:44 EDT 2010


Author: strk
Date: 2010-06-20 08:50:44 +0000 (Sun, 20 Jun 2010)
New Revision: 3032

Modified:
   trunk/php/TODO
   trunk/php/geos.c
Log:
Geometry.__toString for easier debuggin


Modified: trunk/php/TODO
===================================================================
--- trunk/php/TODO	2010-06-20 08:32:29 UTC (rev 3031)
+++ trunk/php/TODO	2010-06-20 08:50:44 UTC (rev 3032)
@@ -1,7 +1,7 @@
 In order of priority
 
-- Equip GEOSGeometry with standard string output
-  (and make sure it comes out on var_dump)
+- Find a way to have GEOSGeometry contents shown 
+  on var_dump
 - Complete interfaces of Geometry
 - Add interfaces for WKBReader/WKBWriter ?
 - Doxygen based documentation ?

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-20 08:32:29 UTC (rev 3031)
+++ trunk/php/geos.c	2010-06-20 08:50:44 UTC (rev 3032)
@@ -175,6 +175,7 @@
 /* -- class GEOSGeometry -------------------- */
 
 PHP_METHOD(Geometry, __construct);
+PHP_METHOD(Geometry, __toString);
 PHP_METHOD(Geometry, project);
 PHP_METHOD(Geometry, interpolate);
 PHP_METHOD(Geometry, buffer);
@@ -194,6 +195,7 @@
 
 static function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
+    PHP_ME(Geometry, __toString, NULL, 0)
     PHP_ME(Geometry, project, NULL, 0)
     PHP_ME(Geometry, interpolate, NULL, 0)
     PHP_ME(Geometry, buffer, NULL, 0)
@@ -278,6 +280,35 @@
 
 }
 
+PHP_METHOD(Geometry, __toString)
+{
+    GEOSGeometry *geom;
+    GEOSWKTWriter *writer;
+    char *wkt;
+    char *ret;
+
+    geom = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+    writer = GEOSWKTWriter_create();
+    /* NOTE: if we get an exception before reaching
+     *       GEOSWKTWriter_destory below we'll be leaking memory.
+     *       One fix could be storing the object in a refcounted
+     *       zval.
+     */
+    GEOSWKTWriter_setTrim(writer, 1);
+
+    wkt = GEOSWKTWriter_write(writer, geom);
+    /* we'll probably get an exception if wkt is null */
+    if ( ! wkt ) RETURN_NULL();
+
+    GEOSWKTWriter_destroy(writer);
+    
+
+    ret = estrdup(wkt);
+    GEOSFree(wkt);
+
+    RETURN_STRING(ret, 0);
+}
+
 PHP_METHOD(Geometry, numGeometries)
 {
     GEOSGeometry *geom;



More information about the geos-commits mailing list