我创建一个包含长度为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::TopologyException
消息:
TopologyException: depth mismatch at at -6 -10.5
这意味着什么,我该怎么办?
答案 0 :(得分:0)
创建GEOS几何图形时必须使用PrecisionModel::makePrecise
。解决方案是添加 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);
}