[geos-commits] r2927 - trunk/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Feb 23 15:00:51 EST 2010


Author: strk
Date: 2010-02-23 15:00:50 -0500 (Tue, 23 Feb 2010)
New Revision: 2927

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
Log:
GEOSPolygonize_full [RT-SIGTA]


Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2010-02-22 22:21:29 UTC (rev 2926)
+++ trunk/capi/geos_c.cpp	2010-02-23 20:00:50 UTC (rev 2927)
@@ -504,6 +504,13 @@
     return GEOSPolygonizer_getCutEdges_r( handle, g, ngeoms );
 }
 
+GEOSGeometry *
+GEOSPolygonize_full(const GEOSGeometry* input,
+	GEOSGeometry** cuts, GEOSGeometry** dangles, GEOSGeometry** invalid)
+{
+    return GEOSPolygonize_full_r(handle, input, cuts, dangles, invalid );
+}
+
 Geometry *
 GEOSLineMerge(const Geometry *g)
 {

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-02-22 22:21:29 UTC (rev 2926)
+++ trunk/capi/geos_c.h.in	2010-02-23 20:00:50 UTC (rev 2927)
@@ -523,6 +523,13 @@
  */
 extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[], unsigned int ngeoms);
 extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges(const GEOSGeometry * const geoms[], unsigned int ngeoms);
+/*
+ * Return rings constructed from fully-noded input linestrings.
+ * Optionally (if output parameter pointers are not null) return cut edges, dangles
+ * and invalid rings lines.
+ */
+extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full(const GEOSGeometry* input,
+	GEOSGeometry** cuts, GEOSGeometry** dangles, GEOSGeometry** invalid);
 
 extern GEOSGeometry GEOS_DLL *GEOSLineMerge(const GEOSGeometry* g);
 extern GEOSGeometry GEOS_DLL *GEOSSimplify(const GEOSGeometry* g1, double tolerance);
@@ -536,6 +543,9 @@
                               GEOSContextHandle_t handle,
                               const GEOSGeometry * const geoms[],
                               unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full_r(GEOSContextHandle_t handle,
+                              const GEOSGeometry* input, GEOSGeometry** cuts,
+                              GEOSGeometry** dangles, GEOSGeometry** invalidRings);
 
 extern GEOSGeometry GEOS_DLL *GEOSLineMerge_r(GEOSContextHandle_t handle,
                                               const GEOSGeometry* g);

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-02-22 22:21:29 UTC (rev 2926)
+++ trunk/capi/geos_ts_c.cpp	2010-02-23 20:00:50 UTC (rev 2927)
@@ -2466,6 +2466,102 @@
 }
 
 Geometry *
+GEOSPolygonize_full_r(GEOSContextHandle_t extHandle, const Geometry* g,
+	Geometry** cuts, Geometry** dangles, Geometry** invalid)
+{
+    if ( 0 == extHandle )
+    {
+        return 0;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return 0;
+    }
+
+    try
+    {
+        // Polygonize
+        using geos::operation::polygonize::Polygonizer;
+        Polygonizer plgnzr;
+        for (std::size_t i = 0; i <g->getNumGeometries(); ++i)
+        {
+            plgnzr.add(g->getGeometryN(i));
+        }
+
+#if GEOS_DEBUG
+        handle->NOTICE_MESSAGE("geometry vector added to polygonizer");
+#endif
+        const GeometryFactory *gf = handle->geomFactory;
+
+	if ( cuts ) {
+
+        	const std::vector<const LineString *>& lines = plgnzr.getCutEdges();
+        	std::vector<Geometry*> *linevec = new std::vector<Geometry *>(lines.size());
+		for (std::size_t i = 0, n=lines.size(); i < n; ++i)
+		{
+		    (*linevec)[i] = lines[i]->clone();
+		}
+
+		// The below takes ownership of the passed vector,
+		// so we must *not* delete it
+		*cuts = gf->createGeometryCollection(linevec);
+	}
+
+	if ( dangles ) {
+
+        	const std::vector<const LineString *>& lines = plgnzr.getDangles();
+        	std::vector<Geometry*> *linevec = new std::vector<Geometry *>(lines.size());
+		for (std::size_t i = 0, n=lines.size(); i < n; ++i)
+		{
+		    (*linevec)[i] = lines[i]->clone();
+		}
+
+		// The below takes ownership of the passed vector,
+		// so we must *not* delete it
+		*dangles = gf->createGeometryCollection(linevec);
+	}
+
+	if ( invalid ) {
+
+        	const std::vector<LineString *>& lines = plgnzr.getInvalidRingLines();
+        	std::vector<Geometry*> *linevec = new std::vector<Geometry *>(lines.size());
+		for (std::size_t i = 0, n=lines.size(); i < n; ++i)
+		{
+		    (*linevec)[i] = lines[i]->clone();
+		}
+
+		// The below takes ownership of the passed vector,
+		// so we must *not* delete it
+		*invalid = gf->createGeometryCollection(linevec);
+	}
+
+        std::vector<Polygon*> *polys = plgnzr.getPolygons();
+        std::vector<Geometry*> *polyvec = new std::vector<Geometry *>(polys->size());
+        for (std::size_t i = 0; i < polys->size(); ++i)
+	{
+            (*polyvec)[i] = (*polys)[i];
+	}
+        delete polys;
+
+        return gf->createGeometryCollection(polyvec);
+
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+	return 0;
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+	return 0;
+    }
+}
+
+Geometry *
 GEOSLineMerge_r(GEOSContextHandle_t extHandle, const Geometry *g)
 {
     if ( 0 == extHandle )



More information about the geos-commits mailing list