[geos-commits] r3136 - in trunk: capi php php/test

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Nov 29 05:51:13 EST 2010


Author: strk
Date: 2010-11-29 02:51:13 -0800 (Mon, 29 Nov 2010)
New Revision: 3136

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Merge branch 'rt'

Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2010-11-29 09:43:32 UTC (rev 3135)
+++ trunk/capi/geos_c.cpp	2010-11-29 10:51:13 UTC (rev 3136)
@@ -1094,4 +1094,13 @@
     return GEOSOrientationIndex_r(handle, Ax, Ay, Bx, By, Px, Py);
 }
 
+GEOSGeometry *
+GEOSSharedPaths(const GEOSGeometry* g1, const GEOSGeometry* g2)
+{
+    return GEOSSharedPaths_r(handle, g1, g2);
+}
+
+extern GEOSGeometry GEOS_DLL *GEOSSharedPaths_r(GEOSContextHandle_t handle,
+  const GEOSGeometry* g1, const GEOSGeometry* g2);
+
 } /* extern "C" */

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-11-29 09:43:32 UTC (rev 3135)
+++ trunk/capi/geos_c.h.in	2010-11-29 10:51:13 UTC (rev 3136)
@@ -597,6 +597,22 @@
                               GEOSContextHandle_t handle,
                               const GEOSGeometry* g);
 
+/*
+ * Find paths shared between the two given lineal geometries.
+ *
+ * Returns a GEOMETRYCOLLECTION having two elements:
+ * - first element is a MULTILINESTRING containing shared paths
+ *   having the _same_ direction on both inputs
+ * - second element is a MULTILINESTRING containing shared paths
+ *   having the _opposite_ direction on the two inputs
+ * 
+ * Returns NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL *GEOSSharedPaths(const GEOSGeometry* g1,
+  const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSSharedPaths_r(GEOSContextHandle_t handle,
+  const GEOSGeometry* g1, const GEOSGeometry* g2);
+
 /************************************************************************
  *
  *  Binary predicates - return 2 on exception, 1 on true, 0 on false

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-11-29 09:43:32 UTC (rev 3135)
+++ trunk/capi/geos_ts_c.cpp	2010-11-29 10:51:13 UTC (rev 3136)
@@ -53,6 +53,7 @@
 #include <geos/operation/buffer/BufferOp.h>
 #include <geos/operation/buffer/BufferParameters.h>
 #include <geos/operation/buffer/BufferBuilder.h>
+#include <geos/operation/sharedpaths/SharedPathsOp.h>
 #include <geos/linearref/LengthIndexedLine.h>
 #include <geos/geom/BinaryOp.h>
 #include <geos/util/IllegalArgumentException.h>
@@ -5327,6 +5328,79 @@
     }
 }
 
+GEOSGeometry *
+GEOSSharedPaths_r(GEOSContextHandle_t extHandle, const GEOSGeometry* g1, const GEOSGeometry* g2)
+{
+    using namespace geos::operation::sharedpaths;
 
+    if ( 0 == extHandle ) return 0;
+    GEOSContextHandleInternal_t *handle =
+      reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( handle->initialized == 0 ) return 0;
+
+    SharedPathsOp::PathList forw, back;
+    try {
+      SharedPathsOp::sharedPathsOp(*g1, *g2, forw, back);
+    } 
+    catch (const std::exception &e)
+    {
+        SharedPathsOp::clearEdges(forw);
+        SharedPathsOp::clearEdges(back);
+        handle->ERROR_MESSAGE("%s", e.what());
+        return 0;
+    }
+    catch (...)
+    {
+        SharedPathsOp::clearEdges(forw);
+        SharedPathsOp::clearEdges(back);
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+        return 0;
+    }
+
+    // Now forw and back have the geoms we want to use to construct
+    // our output GeometryCollections...
+
+    const GeometryFactory* factory = g1->getFactory();
+    size_t count;
+
+    std::auto_ptr< std::vector<Geometry*> > out1(
+      new std::vector<Geometry*>()
+    );
+    count = forw.size();
+    out1->reserve(count);
+    for (size_t i=0; i<count; ++i) {
+        out1->push_back(forw[i]);
+    }
+    std::auto_ptr<Geometry> out1g (
+      factory->createMultiLineString(out1.release())
+    );
+
+    std::auto_ptr< std::vector<Geometry*> > out2(
+      new std::vector<Geometry*>()
+    );
+    count = back.size();
+    out2->reserve(count);
+    for (size_t i=0; i<count; ++i) {
+        out2->push_back(back[i]);
+    }
+    std::auto_ptr<Geometry> out2g (
+      factory->createMultiLineString(out2.release())
+    );
+
+    std::auto_ptr< std::vector<Geometry*> > out(
+      new std::vector<Geometry*>()
+    );
+    out->reserve(2);
+    out->push_back(out1g.release());
+    out->push_back(out2g.release());
+
+    std::auto_ptr<Geometry> outg (
+      factory->createGeometryCollection(out.release())
+    );
+
+    return outg.release();
+
+}
+
 } /* extern "C" */
 

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-11-29 09:43:32 UTC (rev 3135)
+++ trunk/php/geos.c	2010-11-29 10:51:13 UTC (rev 3136)
@@ -41,11 +41,13 @@
 PHP_FUNCTION(GEOSVersion);
 PHP_FUNCTION(GEOSPolygonize);
 PHP_FUNCTION(GEOSLineMerge);
+PHP_FUNCTION(GEOSSharedPaths);
 
 static function_entry geos_functions[] = {
     PHP_FE(GEOSVersion, NULL)
     PHP_FE(GEOSPolygonize, NULL)
     PHP_FE(GEOSLineMerge, NULL)
+    PHP_FE(GEOSSharedPaths, NULL)
     {NULL, NULL, NULL}
 };
 
@@ -2309,6 +2311,32 @@
     GEOSGeom_destroy(geom_out);
 }
 
+/**
+ * GEOSGeometry GEOSSharedPaths(GEOSGeometry $geom1, GEOSGeometry *geom2)
+ */
+PHP_FUNCTION(GEOSSharedPaths)
+{
+    GEOSGeometry *geom_in_1;
+    GEOSGeometry *geom_in_2;
+    GEOSGeometry *geom_out;
+    zval *zobj1, *zobj2;
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oo", &zobj1, &zobj2)
+        == FAILURE)
+    {
+        RETURN_NULL();
+    }
+    geom_in_1 = getRelay(zobj1, Geometry_ce_ptr);
+    geom_in_2 = getRelay(zobj2, Geometry_ce_ptr);
+
+    geom_out = GEOSSharedPaths(geom_in_1, geom_in_2);
+    if ( ! geom_out ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    object_init_ex(return_value, Geometry_ce_ptr);
+    setRelay(return_value, geom_out);
+}
+
 /* ------ Initialization / Deinitialization / Meta ------------------ */
 
 /* per-module initialization */

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2010-11-29 09:43:32 UTC (rev 3135)
+++ trunk/php/test/test.php	2010-11-29 10:51:13 UTC (rev 3136)
@@ -1055,6 +1055,21 @@
 
     }
 
+    public function testGeometry_sharedPaths()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+        /* LINE - LINE */
+        $g1 = $reader->read('LINESTRING(0 0, 50 0)');
+        $g2 = $reader->read('MULTILINESTRING((5 0, 15 0),(40 0, 30 0))');
+        $gs = GEOSSharedPaths($g1, $g2);
+        $this->assertEquals(
+'GEOMETRYCOLLECTION (MULTILINESTRING ((5 0, 15 0)), MULTILINESTRING ((30 0, 40 0)))'
+            , $writer->write($gs));
+    }
+
     public function testGeometry_simplify()
     {
         $reader = new GEOSWKTReader();
@@ -2011,4 +2026,5 @@
         $this->assertEquals(53, $g->getSRID());
 
     }
+
 }



More information about the geos-commits mailing list