我正在尝试使用GEOS(使用c api)产生多边形的负缓冲区(偏移)。
到目前为止,我已经实现了正偏移(see image),但是当我尝试使宽度为-时,它什么也不会产生。我怀疑“偏移”需要在获取外圈之前以某种方式进行裁剪。
对文档有很好的了解,但无法解决,将不胜感激!
如果有帮助,我的代码在下面:
#include <geos_c.h>
// Define coordinate sequence
int noPoints = 6 + 1; // +1 because it is a loop
GEOSCoordSequence* points = GEOSCoordSeq_create(noPoints, 2 /*# ordinates*/);
GEOSCoordSeq_setX(points, 0, 0);
GEOSCoordSeq_setY(points, 0, 0);
GEOSCoordSeq_setX(points, 1, 0);
GEOSCoordSeq_setY(points, 1, 50);
GEOSCoordSeq_setX(points, 2, 50);
GEOSCoordSeq_setY(points, 2, 50);
GEOSCoordSeq_setX(points, 3, 50);
GEOSCoordSeq_setY(points, 3, 0);
GEOSCoordSeq_setX(points, 4, 30);
GEOSCoordSeq_setY(points, 4, 15);
GEOSCoordSeq_setX(points, 5, 20);
GEOSCoordSeq_setY(points, 5, 15);
GEOSCoordSeq_setX(points, noPoints-1, 0);
GEOSCoordSeq_setY(points, noPoints-1, 0);
// Define linear ring
GEOSGeometry* ploop = GEOSGeom_createLinearRing(points);
// Define offset
double width = 15;
int quadsegs = 100;
int endCapStyle = 1;
int joinStyle = 1;
double mitreLimit = 1.0;
const GEOSGeometry* offset = GEOSBufferWithStyle(ploop, width, quadsegs, endCapStyle, joinStyle, mitreLimit);
// Get exterior ring
const GEOSGeometry* exteriorRing = GEOSGetExteriorRing(offset);
// Convert to coord sequence and draw points
const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq(exteriorRing);
uint numPoints = GEOSGeomGetNumPoints(exteriorRing);
double xCoord, yCoord;
for (uint p = 0; p < numPoints; p++) {
GEOSCoordSeq_getX(coordSeq, p, &xCoord);
GEOSCoordSeq_getY(coordSeq, p, &yCoord);
printf("x: %g\ty:%g\n", xCoord, yCoord);
drawPoint(xCoord, yCoord);
}
提前感谢!
终于解决了!我输入的几何图形是线性环,而不是多边形。