[geos-commits] r2661 - in trunk: capi tests/unit/capi
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Oct 7 03:53:03 EDT 2009
Author: strk
Date: 2009-10-07 03:53:01 -0400 (Wed, 07 Oct 2009)
New Revision: 2661
Modified:
trunk/capi/geos_c.cpp
trunk/capi/geos_c.h.in
trunk/capi/geos_ts_c.cpp
trunk/tests/unit/capi/GEOSBufferTest.cpp
Log:
Expose single-sided buffering in C-API (see ticket #258)
Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp 2009-10-05 21:48:29 UTC (rev 2660)
+++ trunk/capi/geos_c.cpp 2009-10-07 07:53:01 UTC (rev 2661)
@@ -342,6 +342,14 @@
}
Geometry *
+GEOSSingleSidedBuffer(const Geometry *g1, double width, int quadsegs,
+ int joinStyle, double mitreLimit, int leftSide)
+{
+ return GEOSSingleSidedBuffer_r( handle, g1, width, quadsegs,
+ joinStyle, mitreLimit, leftSide );
+}
+
+Geometry *
GEOSConvexHull(const Geometry *g1)
{
return GEOSConvexHull_r( handle, g1 );
Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in 2009-10-05 21:48:29 UTC (rev 2660)
+++ trunk/capi/geos_c.h.in 2009-10-07 07:53:01 UTC (rev 2661)
@@ -387,7 +387,16 @@
const GEOSGeometry* g1, double width, int quadsegs, int endCapStyle,
int joinStyle, double mitreLimit);
+/* These functions return NULL on exception. Only LINESTRINGs are accepted. */
+extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer(const GEOSGeometry* g1,
+ double width, int quadsegs, int joinStyle, double mitreLimit,
+ int leftSide);
+extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer_r(
+ GEOSContextHandle_t handle,
+ const GEOSGeometry* g1, double width, int quadsegs,
+ int joinStyle, double mitreLimit, int leftSide);
+
/************************************************************************
*
* Geometry Constructors.
Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp 2009-10-05 21:48:29 UTC (rev 2660)
+++ trunk/capi/geos_ts_c.cpp 2009-10-07 07:53:01 UTC (rev 2661)
@@ -48,6 +48,7 @@
#include <geos/operation/union/CascadedPolygonUnion.h>
#include <geos/operation/buffer/BufferOp.h>
#include <geos/operation/buffer/BufferParameters.h>
+#include <geos/operation/buffer/BufferBuilder.h>
#include <geos/linearref/LengthIndexedLine.h>
#include <geos/geom/BinaryOp.h>
#include <geos/util/IllegalArgumentException.h>
@@ -1423,6 +1424,58 @@
}
Geometry *
+GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle, const Geometry *g1, double width, int quadsegs, int joinStyle, double mitreLimit, int leftSide)
+{
+ using geos::operation::buffer::BufferParameters;
+ using geos::operation::buffer::BufferBuilder;
+ 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.setEndCapStyle( BufferParameters::CAP_FLAT );
+ bp.setQuadrantSegments(quadsegs);
+
+ if ( joinStyle > BufferParameters::JOIN_BEVEL )
+ {
+ throw IllegalArgumentException("Invalid buffer join style");
+ }
+ bp.setJoinStyle(
+ static_cast<BufferParameters::JoinStyle>(joinStyle)
+ );
+ bp.setMitreLimit(mitreLimit);
+
+ BufferBuilder bufBuilder (bp);
+ Geometry *g3 = bufBuilder.bufferLineSingleSided(g1, width, leftSide);
+
+ 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 )
Modified: trunk/tests/unit/capi/GEOSBufferTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSBufferTest.cpp 2009-10-05 21:48:29 UTC (rev 2660)
+++ trunk/tests/unit/capi/GEOSBufferTest.cpp 2009-10-07 07:53:01 UTC (rev 2661)
@@ -444,6 +444,48 @@
}
+ // Single-sided buffer (1)
+ template<>
+ template<>
+ void object::test<17>()
+ {
+ geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0)");
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSSingleSidedBuffer(geom1_, 2, 2, GEOSBUF_JOIN_ROUND, 2, 1);
+
+ ensure( 0 != geom2_ );
+
+ wkt_ = GEOSGeomToWKT(geom2_);
+
+ ensure_equals(std::string(wkt_), std::string(
+"LINESTRING (0.0000000000000000 2.0000000000000000, 10.0000000000000000 2.0000000000000000)"
+ ));
+
+ }
+
+ // Single-sided buffer (2)
+ template<>
+ template<>
+ void object::test<18>()
+ {
+ geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0)");
+
+ ensure( 0 != geom1_ );
+
+ geom2_ = GEOSSingleSidedBuffer(geom1_, 2, 2, GEOSBUF_JOIN_ROUND, 2, 0);
+
+ ensure( 0 != geom2_ );
+
+ wkt_ = GEOSGeomToWKT(geom2_);
+
+ ensure_equals(std::string(wkt_), std::string(
+"LINESTRING (10.0000000000000000 -2.0000000000000000, 0.0000000000000000 -2.0000000000000000)"
+ ));
+
+ }
+
+
} // namespace tut
More information about the geos-commits
mailing list