首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GEOS (​JTS拓扑套件)产生附加点的​/偏移曲线

GEOS (​JTS拓扑套件)产生附加点的​/偏移曲线
EN

Stack Overflow用户
提问于 2021-11-17 20:58:35
回答 1查看 145关注 0票数 0

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

我已经成功地产生了偏移曲线,但是对于某些情况(即起始线和结束线都是水平和结束在相同的x位置/或垂直和结束在相同的y位置),一个额外的点在偏移的开始和结束。

用图像来解释这一点是最简单的:

示例图像

示例图像2

我无法确定是否有什么事情我失败了,或者如果这是库中的一个bug,下面是我的代码:

代码语言:javascript
复制
#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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-21 20:47:34

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

见此处:问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70011468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档