【问题标题】:GEOS (​JTS Topology Suite) BufferOp / Offset Curve producing additional pointsGEOS (​JTS Topology Suite) BufferOp / Offset Curve 产生额外点
【发布时间】:2021-11-17 20:58:35
【问题描述】:

我正在使用 GEOS(JTS 拓扑套件的 C 端口)来生成线串的偏移曲线。

我已经成功生成了偏移曲线,但是对于某些情况(即起点和终点线都是水平的并且在相同的 x 位置/或垂直和在相同的 y 位置结束),会在以下位置创建一个附加点偏移量的开始和结束。

用图片最容易解释:

Example Image

Example Image 2

如果我没有做某事或者这是库的错误,我无法解决,这是我的代码:

#include "geos_c.h"

std::vector<vec2> Geos::offsetLine(const std::vector<vec2>& points, float offset, int quadrantSegments, int joinStyle, double mitreLimit) 
{    
    // make coord sequence from points
    GEOSCoordSequence* seq = makeCoordSequence(points);

    // Define line string
    GEOSGeometry* lineString = GEOSGeom_createLineString(seq); 
    if(!lineString) return {};

    // offset line
    GEOSGeometry* bufferOp = GEOSOffsetCurve(lineString, offset, quadrantSegments, joinStyle, mitreLimit);
    if(!bufferOp) return {};

    // put coords into vector
    std::vector<vec2> output = outputCoords(bufferOp, (offset < 0.0f));

    // Frees memory of all as memory ownership is passed along
    GEOSGeom_destroy(bufferOp);

    return move(output);
}

GEOSCoordSequence* Geos::makeCoordSequence(const std::vector<vec2>& points) 
{
    GEOSCoordSequence* seq = GEOSCoordSeq_create(points.size(), 2);
    if(!seq) return {};

    for (size_t i = 0; i < points.size(); i++) { 
        GEOSCoordSeq_setX(seq, i, points[i].x);
        GEOSCoordSeq_setY(seq, i, points[i].y);
    }
    return seq;
}

std::vector<vec2> Geos::outputCoords(const GEOSGeometry* points, bool reversePoints) 
{
    // Convert to coord sequence and draw points
    const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq(points);
    if(!coordSeq) return {};

    // get number of points
    int nPoints = GEOSGeomGetNumPoints(points);
    if(nPoints == -1) return {};

    // output onto vector to return
    std::vector<vec2> output;

    // build vector
    for (size_t i = 0; i < (size_t)nPoints; i++) {
        // points are in reverse order if negative offset
        size_t index = reversePoints ? nPoints-i-1 : i;
        double xCoord, yCoord;
        GEOSCoordSeq_getX(coordSeq, index, &xCoord);
        GEOSCoordSeq_getY(coordSeq, index, &yCoord);
        output.push_back({ xCoord, yCoord });
    }
    return move(output);
}

【问题讨论】:

    标签: c++ geometry offset geos jts


    【解决方案1】:

    最新版本的 Geos 现在解决了这个问题。

    请看这里:Issue

    【讨论】:

      猜你喜欢
      • 2018-03-08
      • 2019-06-01
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      相关资源
      最近更新 更多