[geos-commits] r3303 - in trunk: . capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Apr 27 09:06:22 EDT 2011
Author: strk
Date: 2011-04-27 06:06:22 -0700 (Wed, 27 Apr 2011)
New Revision: 3303
Modified:
trunk/NEWS
trunk/capi/geos_c.cpp
trunk/capi/geos_c.h.in
trunk/capi/geos_ts_c.cpp
Log:
Add GEOSBufferParams type and GEOSBufferWithParams function to have an extensible buffer operation. Allows areal single sided buffer.
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2011-04-27 11:13:28 UTC (rev 3302)
+++ trunk/NEWS 2011-04-27 13:06:22 UTC (rev 3303)
@@ -2,6 +2,7 @@
????-??-??
- New things:
+ - CAPI: GEOSBufferWithParams (allows single sided buffers)
- CAPI: GEOSOffsetCurve deprecates GEOSSingleSidedBuffer
- CAPI: GEOSUnaryUnion deprecates GEOSCascadedUnion
- CAPI: GEOSisValidDetail: tell state, reason & location apart. allows
Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp 2011-04-27 11:13:28 UTC (rev 3302)
+++ trunk/capi/geos_c.cpp 2011-04-27 13:06:22 UTC (rev 3303)
@@ -40,6 +40,7 @@
#define GEOSWKTWriter_t geos::io::WKTWriter
#define GEOSWKBReader_t geos::io::WKBReader
#define GEOSWKBWriter_t geos::io::WKBWriter
+typedef struct GEOSBufParams_t GEOSBufferParams;
#include "geos_c.h"
@@ -1144,4 +1145,52 @@
return GEOSSnap_r(handle, g1, g2, tolerance);
}
+GEOSBufferParams*
+GEOSBufferParams_create()
+{
+ return GEOSBufferParams_create_r(handle);
+}
+
+void
+GEOSBufferParams_destroy(GEOSBufferParams* p)
+{
+ return GEOSBufferParams_destroy_r(handle, p);
+}
+
+int
+GEOSBufferParams_setEndCapStyle(GEOSBufferParams* p, int style)
+{
+ return GEOSBufferParams_setEndCapStyle_r(handle, p, style);
+}
+
+int
+GEOSBufferParams_setJoinStyle(GEOSBufferParams* p, int joinStyle)
+{
+ return GEOSBufferParams_setJoinStyle_r(handle, p, joinStyle);
+}
+
+int
+GEOSBufferParams_setMitreLimit(GEOSBufferParams* p, double l)
+{
+ return GEOSBufferParams_setMitreLimit_r(handle, p, l);
+}
+
+int
+GEOSBufferParams_setQuadrantSegments(GEOSBufferParams* p, int joinStyle)
+{
+ return GEOSBufferParams_setQuadrantSegments_r(handle, p, joinStyle);
+}
+
+int
+GEOSBufferParams_setSingleSided(GEOSBufferParams* p, int singleSided)
+{
+ return GEOSBufferParams_setSingleSided_r(handle, p, singleSided);
+}
+
+Geometry*
+GEOSBufferWithParams(const Geometry* g, const GEOSBufferParams* p, double w)
+{
+ return GEOSBufferWithParams_r(handle, g, p, w);
+}
+
} /* extern "C" */
Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in 2011-04-27 11:13:28 UTC (rev 3302)
+++ trunk/capi/geos_c.h.in 2011-04-27 13:06:22 UTC (rev 3303)
@@ -103,6 +103,7 @@
typedef struct GEOSPrepGeom_t GEOSPreparedGeometry;
typedef struct GEOSCoordSeq_t GEOSCoordSequence;
typedef struct GEOSSTRtree_t GEOSSTRtree;
+typedef struct GEOSBufParams_t GEOSBufferParams;
#endif
/* Those are compatibility definitions for source compatibility
@@ -383,6 +384,72 @@
GEOSBUF_JOIN_BEVEL=3
};
+/* @return 0 on exception */
+extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create();
+extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create_r(
+ GEOSContextHandle_t handle);
+extern void GEOS_DLL GEOSBufferParams_destroy(GEOSBufferParams* parms);
+extern void GEOS_DLL GEOSBufferParams_destroy_r(
+ GEOSContextHandle_t handle,
+ GEOSBufferParams* parms);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setEndCapStyle(
+ GEOSBufferParams* p,
+ int style);
+extern int GEOS_DLL GEOSBufferParams_setEndCapStyle_r(
+ GEOSContextHandle_t handle,
+ GEOSBufferParams* p,
+ int style);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setJoinStyle(
+ GEOSBufferParams* p,
+ int joinStyle);
+extern int GEOS_DLL GEOSBufferParams_setJoinStyle_r(
+ GEOSContextHandle_t handle,
+ GEOSBufferParams* p,
+ int joinStyle);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setMitreLimit(
+ GEOSBufferParams* p,
+ double mitreLimit);
+extern int GEOS_DLL GEOSBufferParams_setMitreLimit_r(
+ GEOSContextHandle_t handle,
+ GEOSBufferParams* p,
+ double mitreLimit);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments(
+ GEOSBufferParams* p,
+ int quadSegs);
+extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments_r(
+ GEOSContextHandle_t handle,
+ GEOSBufferParams* p,
+ int quadSegs);
+
+/* @param singleSided: 1 for single sided, 0 otherwise */
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setSingleSided(
+ GEOSBufferParams* p,
+ int singleSided);
+extern int GEOS_DLL GEOSBufferParams_setSingleSided_r(
+ GEOSContextHandle_t handle,
+ GEOSBufferParams* p,
+ int singleSided);
+
+/* @return NULL on exception. */
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams(
+ const GEOSGeometry* g1,
+ const GEOSBufferParams* p,
+ double width);
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams_r(
+ GEOSContextHandle_t handle,
+ const GEOSGeometry* g1,
+ const GEOSBufferParams* p,
+ double width);
+
/* These functions return NULL on exception. */
extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g1,
double width, int quadsegs);
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2011-04-27 11:13:28 UTC (rev 3302)
+++ trunk/capi/geos_ts_c.cpp 2011-04-27 13:06:22 UTC (rev 3303)
@@ -84,6 +84,7 @@
#define GEOSGeometry geos::geom::Geometry
#define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
#define GEOSCoordSequence geos::geom::CoordinateSequence
+#define GEOSBufferParams geos::operation::buffer::BufferParameters
#define GEOSSTRtree geos::index::strtree::STRtree
#define GEOSWKTReader_t geos::io::WKTReader
#define GEOSWKTWriter_t geos::io::WKTWriter
@@ -120,7 +121,8 @@
using geos::operation::overlay::OverlayOp;
using geos::operation::overlay::overlayOp;
using geos::operation::geounion::CascadedPolygonUnion;
-
+using geos::operation::buffer::BufferParameters;
+using geos::util::IllegalArgumentException;
using geos::algorithm::distance::DiscreteHausdorffDistance;
typedef std::auto_ptr<Geometry> GeomAutoPtr;
@@ -5657,5 +5659,208 @@
}
}
+BufferParameters *
+GEOSBufferParams_create_r(GEOSContextHandle_t extHandle)
+{
+ if ( 0 == extHandle ) return NULL;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return NULL;
+
+ try
+ {
+ BufferParameters *p = new BufferParameters();
+ return p;
+ }
+ catch (const std::exception &e)
+ {
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return 0;
+}
+
+void
+GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle, BufferParameters* p)
+{
+ delete p;
+}
+
+int
+GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle,
+ GEOSBufferParams* p, int style)
+{
+ if ( 0 == extHandle ) return 0;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return 0;
+
+ try
+ {
+ if ( style > BufferParameters::CAP_SQUARE )
+ {
+ throw IllegalArgumentException("Invalid buffer endCap style");
+ }
+ p->setEndCapStyle(static_cast<BufferParameters::EndCapStyle>(style));
+ return 1;
+ }
+ catch (const std::exception &e)
+ {
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return 0;
+}
+
+int
+GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle,
+ GEOSBufferParams* p, int style)
+{
+ if ( 0 == extHandle ) return 0;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return 0;
+
+ try
+ {
+ if ( style > BufferParameters::JOIN_BEVEL ) {
+ throw IllegalArgumentException("Invalid buffer join style");
+ }
+ p->setJoinStyle(static_cast<BufferParameters::JoinStyle>(style));
+ return 1;
+ }
+ catch (const std::exception &e)
+ {
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return 0;
+}
+
+int
+GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle,
+ GEOSBufferParams* p, double limit)
+{
+ if ( 0 == extHandle ) return 0;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return 0;
+
+ try
+ {
+ p->setMitreLimit(limit);
+ return 1;
+ }
+ catch (const std::exception &e)
+ {
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return 0;
+}
+
+int
+GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle,
+ GEOSBufferParams* p, int segs)
+{
+ if ( 0 == extHandle ) return 0;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return 0;
+
+ try
+ {
+ p->setQuadrantSegments(segs);
+ return 1;
+ }
+ catch (const std::exception &e)
+ {
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return 0;
+}
+
+int
+GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle,
+ GEOSBufferParams* p, int ss)
+{
+ if ( 0 == extHandle ) return 0;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return 0;
+
+ try
+ {
+ p->setSingleSided( (ss != 0) );
+ return 1;
+ }
+ catch (const std::exception &e)
+ {
+ handle->ERROR_MESSAGE("%s", e.what());
+ }
+ catch (...)
+ {
+ handle->ERROR_MESSAGE("Unknown exception thrown");
+ }
+
+ return 0;
+}
+
+Geometry *
+GEOSBufferWithParams_r(GEOSContextHandle_t extHandle, const Geometry *g1, const BufferParameters* bp, double width)
+{
+ using geos::operation::buffer::BufferOp;
+
+ if ( 0 == extHandle ) return NULL;
+
+ GEOSContextHandleInternal_t *handle = 0;
+ handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+ if ( 0 == handle->initialized ) return NULL;
+
+ try
+ {
+ 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;
+}
+
} /* extern "C" */
More information about the geos-commits
mailing list