[geos-devel] C-API extension
Jürgen E. Fischer
jef at norbit.de
Wed Jul 30 16:38:45 EDT 2008
Hi there,
while porting Quantum GIS from the C++ API to the C API I found that
there currently seems to be no way to get the cut edges from
the Polygonizer.
Please consider the attached patch, which adds that.
tia
Jürgen
--
Jürgen E. Fischer norBIT GmbH Tel. +49-4931-918175-0
Dipl.-Inf. (FH) Rheinstraße 13 Fax. +49-4931-918175-50
Software Engineer D-26506 Norden http://www.norbit.de
--
norBIT Gesellschaft fuer Unternehmensberatung und Informationssysteme mbH
Rheinstrasse 13, 26506 Norden
GF: Jelto Buurman, HR: Amtsgericht Emden, HRB 5502
-------------- next part --------------
Index: capi/geos_c.cpp
===================================================================
--- capi/geos_c.cpp (revision 2135)
+++ capi/geos_c.cpp (working copy)
@@ -1349,6 +1349,54 @@
}
Geometry *
+GEOSPolygonizeGetCutEdges(const Geometry * const * g, unsigned int ngeoms)
+{
+ using geos::operation::polygonize::Polygonizer;
+ unsigned int i;
+ Geometry *out = NULL;
+
+ try{
+ // Polygonize
+ Polygonizer plgnzr;
+ for (i=0; i<ngeoms; i++) plgnzr.add(g[i]);
+#if GEOS_DEBUG
+ NOTICE_MESSAGE("geometry vector added to polygonizer");
+#endif
+
+ std::vector<const LineString *>*lines = plgnzr.getCutEdges();
+
+#if GEOS_DEBUG
+ NOTICE_MESSAGE("output polygons got");
+#endif
+
+ // We need a vector of Geometry pointers, not
+ // Polygon pointers.
+ // STL vector doesn't allow transparent upcast of this
+ // nature, so we explicitly convert.
+ // (it's just a waste of processor and memory, btw)
+ std::vector<Geometry*> *linevec =
+ new std::vector<Geometry *>(lines->size());
+ for (i=0; i<lines->size(); i++) (*linevec)[i] = (*lines)[i]->clone();
+
+ out = geomFactory->createGeometryCollection(linevec);
+ // the above method takes ownership of the passed
+ // vector, so we must *not* delete it
+ }
+ catch (const std::exception &e)
+ {
+ ERROR_MESSAGE("%s", e.what());
+ return NULL;
+ }
+ catch (...)
+ {
+ ERROR_MESSAGE("Unknown exception thrown");
+ return NULL;
+ }
+
+ return out;
+}
+
+Geometry *
GEOSLineMerge(const Geometry *g)
{
using geos::operation::linemerge::LineMerger;
Index: capi/geos_c.h.in
===================================================================
--- capi/geos_c.h.in (revision 2135)
+++ capi/geos_c.h.in (working copy)
@@ -283,8 +283,8 @@
* all arguments remain ownership of the caller
* (both Geometries and pointers)
*/
-extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[],
- unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[], unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSPolygonizeGetCutEdges(const GEOSGeometry * const geoms[], unsigned int ngeoms);
extern GEOSGeometry GEOS_DLL *GEOSLineMerge(const GEOSGeometry* g);
extern GEOSGeometry GEOS_DLL *GEOSSimplify(const GEOSGeometry* g1, double tolerance);
More information about the geos-devel
mailing list