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

svn_geos at osgeo.org svn_geos at osgeo.org
Wed May 11 05:47:57 EDT 2011


Author: strk
Date: 2011-05-11 02:47:57 -0700 (Wed, 11 May 2011)
New Revision: 3344

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Add single-sided buffering support in PHP binding

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2011-05-11 09:15:08 UTC (rev 3343)
+++ trunk/php/geos.c	2011-05-11 09:47:57 UTC (rev 3344)
@@ -548,12 +548,18 @@
  *       Type: double
  *       mitre ratio limit (only affects joins with GEOSBUF_JOIN_MITRE style)
  *       'miter_limit' is also accepted as a synonym for 'mitre_limit'.
+ *  'single_sided'
+ *       Type: bool
+ *       If true buffer lines only on one side, so that the input line
+ *       will be a portion of the boundary of the returned polygon.
+ *       Only applies to lineal input. Defaults to false.
  */
 PHP_METHOD(Geometry, buffer)
 {
     GEOSGeometry *this;
     double dist;
     GEOSGeometry *ret;
+    GEOSBufferParams *params;
     static const double default_mitreLimit = 5.0;
     static const int default_endCapStyle = GEOSBUF_CAP_ROUND;
     static const int default_joinStyle = GEOSBUF_JOIN_ROUND;
@@ -562,6 +568,7 @@
     long int endCapStyle = default_endCapStyle;
     long int joinStyle = default_joinStyle;
     double mitreLimit = default_mitreLimit;
+    long singleSided = 0;
     zval *style_val = NULL;
     zval **data;
     HashTable *style;
@@ -575,6 +582,8 @@
         RETURN_NULL();
     }
 
+    params = GEOSBufferParams_create();
+
     if ( style_val )
     {
         style = HASH_OF(style_val);
@@ -585,29 +594,39 @@
             {
                 zend_hash_get_current_data(style, (void**)&data);
                 quadSegs = getZvalAsLong(*data);
+                GEOSBufferParams_setQuadrantSegments(params, quadSegs);
             }
             else if(!strcmp(key, "endcap"))
             {
                 zend_hash_get_current_data(style, (void**)&data);
                 endCapStyle = getZvalAsLong(*data);
+                GEOSBufferParams_setEndCapStyle(params, endCapStyle);
             }
             else if(!strcmp(key, "join"))
             {
                 zend_hash_get_current_data(style, (void**)&data);
                 joinStyle = getZvalAsLong(*data);
+                GEOSBufferParams_setJoinStyle(params, joinStyle);
             }
             else if(!strcmp(key, "mitre_limit"))
             {
                 zend_hash_get_current_data(style, (void**)&data);
                 mitreLimit = getZvalAsDouble(*data);
+                GEOSBufferParams_setMitreLimit(params, mitreLimit);
             }
+            else if(!strcmp(key, "single_sided"))
+            {
+                zend_hash_get_current_data(style, (void**)&data);
+                singleSided = getZvalAsLong(*data);
+                GEOSBufferParams_setSingleSided(params, singleSided);
+            }
 
             zend_hash_move_forward(style);
         }
     }
 
-    ret = GEOSBufferWithStyle(this, dist,
-        quadSegs, endCapStyle, joinStyle, mitreLimit);
+    ret = GEOSBufferWithParams(this, params, dist);
+    GEOSBufferParams_destroy(params);
     if ( ! ret ) RETURN_NULL(); /* should get an exception first */
 
     /* return_value is a zval */

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2011-05-11 09:15:08 UTC (rev 3343)
+++ trunk/php/test/test.php	2011-05-11 09:47:57 UTC (rev 3344)
@@ -499,7 +499,24 @@
         $this->assertEquals('array', gettype($myStyle['endcap']));
         $this->assertEquals('integer', gettype($myStyle['mitre_limit']));
 
+        /* Single-sided buffering */
 
+        $g = $reader->read('LINESTRING(0 0, 100 0)');
+
+        $b = $g->buffer(10, array(
+            'single_sided' => true
+        ));
+        $this->assertEquals(
+'POLYGON ((100 0, 0 0, 0 10, 100 10, 100 0))'
+            , $writer->write($b));
+
+        $b = $g->buffer(-10, array(
+            'single_sided' => true
+        ));
+        $this->assertEquals(
+'POLYGON ((0 0, 100 0, 100 -10, 0 -10, 0 0))'
+            , $writer->write($b));
+
     }
 
     public function testGeometry_envelope()



More information about the geos-commits mailing list