[geos-commits] r2593 - trunk/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Jun 19 18:32:10 EDT 2009


Author: strk
Date: 2009-06-19 18:32:10 -0400 (Fri, 19 Jun 2009)
New Revision: 2593

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
Log:
Extend the C-API interface to expose a GEOSBufferWithStyle (and corresponding thread-safe version) and related enums.


Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2009-06-16 15:49:53 UTC (rev 2592)
+++ trunk/capi/geos_c.cpp	2009-06-19 22:32:10 UTC (rev 2593)
@@ -318,6 +318,14 @@
 }
 
 Geometry *
+GEOSBufferWithStyle(const Geometry *g1, double width, int quadsegs,
+	int endCapStyle, int joinStyle, double mitreLimit)
+{
+    return GEOSBufferWithStyle_r( handle, g1, width, quadsegs, endCapStyle,
+                               joinStyle, mitreLimit );
+}
+
+Geometry *
 GEOSConvexHull(const Geometry *g1)
 {
     return GEOSConvexHull_r( handle, g1 );

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2009-06-16 15:49:53 UTC (rev 2592)
+++ trunk/capi/geos_c.h.in	2009-06-19 22:32:10 UTC (rev 2593)
@@ -316,6 +316,40 @@
 
 /************************************************************************
  *
+ * Buffer related functions
+ *
+ ***********************************************************************/
+
+enum GEOSBufCapStyles {
+	GEOSBUF_CAP_ROUND=1,
+	GEOSBUF_CAP_FLAT=2,
+	GEOSBUF_CAP_SQUARE=3
+};
+
+enum GEOSBufJoinStyles {
+	GEOSBUF_JOIN_ROUND=1,
+	GEOSBUF_JOIN_MITRE=2,
+	GEOSBUF_JOIN_BEVEL=3
+};
+
+/* These functions return NULL on exception. */
+extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g1,
+	double width, int quadsegs);
+extern GEOSGeometry GEOS_DLL *GEOSBuffer_r(GEOSContextHandle_t handle,
+                                           const GEOSGeometry* g1,
+                                           double width, int quadsegs);
+
+/* These functions return NULL on exception. */
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle(const GEOSGeometry* g1,
+	double width, int quadsegs, int endCapStyle, int joinStyle,
+	double mitreLimit);
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle_r(GEOSContextHandle_t handle,
+	const GEOSGeometry* g1, double width, int quadsegs, int endCapStyle,
+	int joinStyle, double mitreLimit);
+
+
+/************************************************************************
+ *
  * Geometry Constructors.
  * GEOSCoordSequence* arguments will become ownership of the returned object.
  * All functions return NULL on exception.
@@ -380,8 +414,6 @@
 
 extern GEOSGeometry GEOS_DLL *GEOSEnvelope(const GEOSGeometry* g1);
 extern GEOSGeometry GEOS_DLL *GEOSIntersection(const GEOSGeometry* g1, const GEOSGeometry* g2);
-extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g1,
-	double width, int quadsegs);
 extern GEOSGeometry GEOS_DLL *GEOSConvexHull(const GEOSGeometry* g1);
 extern GEOSGeometry GEOS_DLL *GEOSDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
 extern GEOSGeometry GEOS_DLL *GEOSSymDifference(const GEOSGeometry* g1,
@@ -399,9 +431,6 @@
 extern GEOSGeometry GEOS_DLL *GEOSIntersection_r(GEOSContextHandle_t handle,
                                                  const GEOSGeometry* g1,
                                                  const GEOSGeometry* g2);
-extern GEOSGeometry GEOS_DLL *GEOSBuffer_r(GEOSContextHandle_t handle,
-                                           const GEOSGeometry* g1,
-                                           double width, int quadsegs);
 extern GEOSGeometry GEOS_DLL *GEOSConvexHull_r(GEOSContextHandle_t handle,
                                                const GEOSGeometry* g1);
 extern GEOSGeometry GEOS_DLL *GEOSDifference_r(GEOSContextHandle_t handle,

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2009-06-16 15:49:53 UTC (rev 2592)
+++ trunk/capi/geos_ts_c.cpp	2009-06-19 22:32:10 UTC (rev 2593)
@@ -42,7 +42,10 @@
 #include <geos/operation/linemerge/LineMerger.h>
 #include <geos/operation/overlay/OverlayOp.h>
 #include <geos/operation/union/CascadedPolygonUnion.h>
+#include <geos/operation/buffer/BufferOp.h>
+#include <geos/operation/buffer/BufferParameters.h>
 #include <geos/geom/BinaryOp.h>
+#include <geos/util/IllegalArgumentException.h>
 #include <geos/version.h> 
 #include <geos/platform.h>  // for FINITE
 
@@ -1275,6 +1278,62 @@
 }
 
 Geometry *
+GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle, const Geometry *g1, double width, int quadsegs, int endCapStyle, int joinStyle, double mitreLimit)
+{
+    using geos::operation::buffer::BufferParameters;
+    using geos::operation::buffer::BufferOp;
+    using geos::util::IllegalArgumentException;
+
+    if ( 0 == extHandle )
+    {
+        return NULL;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return NULL;
+    }
+
+    try
+    {
+        BufferParameters bp;
+        bp.setQuadrantSegments(quadsegs);
+
+        if ( endCapStyle > BufferParameters::CAP_SQUARE )
+        {
+        	throw IllegalArgumentException("Invalid buffer endCap style");
+        }
+        bp.setEndCapStyle(
+        	static_cast<BufferParameters::EndCapStyle>(endCapStyle)
+        );
+
+        if ( joinStyle > BufferParameters::JOIN_BEVEL )
+        {
+        	throw IllegalArgumentException("Invalid buffer join style");
+        }
+        bp.setJoinStyle(
+        	static_cast<BufferParameters::JoinStyle>(joinStyle)
+        );
+        bp.setMitreLimit(mitreLimit);
+        BufferOp op(g1, bp);
+        Geometry *g3 = op.getResultGeometry(width);
+        return g3;
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return NULL;
+}
+
+Geometry *
 GEOSConvexHull_r(GEOSContextHandle_t extHandle, const Geometry *g1)
 {
     if ( 0 == extHandle )



More information about the geos-commits mailing list