0

我创建了一个包含长度为 167 的 CoordinateSequence 的 LineString,然后使用以下代码执行缓冲区操作:

geos::operation::buffer::BufferParameters buffer_params;
geos::operation::buffer::BufferOp buffer_op(input, buffer_params);
std::unique_ptr<geos::geom::Geometry> output(buffer_op.getResultGeometry(1.5));

这会引发一条geos::geom::TopologyExceptionwith 消息:

TopologyException: depth mismatch at  at -6 -10.5

这是什么意思,我能做些什么呢?

4

1 回答 1

0

PrecisionModel::makePrecise在创建 GEOS 几何图形时必须使用。解决方案是像这样添加makePrecise调用:

geos::geom::LineString* LineStringFromPath(const std::vector<Math::LineSegment2D>& segments,
                                           const geos::geom::GeometryFactory& factory) {
    const geos::geom::PrecisionModel& pm = *factory.getPrecisionModel();

    // Geos will take ownership over this coordinate sequence:
    geos::geom::CoordinateSequence* cl = new geos::geom::CoordinateArraySequence();
    cl->add(geos::geom::Coordinate(pm.makePrecise(segments.front().start[0]),
                                   pm.makePrecise(segments.front().start[1])));

    for (const auto& segment : segments) {
        // Geos will take ownership over this coordinatesequence:
        cl->add(geos::geom::Coordinate(pm.makePrecise(segment.end[0]),
                                       pm.makePrecise(segment.end[1])));
    }

    // Create the full geometry. Object returned from this method must be deleted by caller.
    return factory.createLineString(cl);
}
于 2014-09-23T13:46:27.480 回答