c++ - GEOS C++ geos::Geometry Buffer(0) 对 convexHull 的错误断言

标签 c++ geos

我目前正在使用 C++ GEOS API 迭代 typedef Points(x 和 y 成员变量)的 vector

我通过创建一个 geos::geom::Geometry 对象,在 0 处缓冲以防止自相交,然后创建一个凸包,将这个 vector 变成一个凸包。

每当我发送一个已经是 convexHull 的对象时,我都会得到以下断言:Assertion 'precisionModel' failed

这是 GEOS 错误吗?我需要注意不要缓冲在凸多边形上吗?

geo_algos_test2:/tmp/libgeos/src/operation/buffer/BufferBuilder.cpp:373: geos::geom::Geometry* geos::operation::buffer::BufferBuilder::buffer(const geos: :geom::Geometry*, double): 断言“precisionModel”失败。*

这是我的代码:

// Remove self intersections or collinear points

geos::geom::GeometryFactory factory;
geos::geom::CoordinateSequence* temp =
    factory.getCoordinateSequenceFactory()->create((std::size_t)0, 0);

// Convert vector of cruise points to GEOS
for (auto point : poly) {
    temp->add(geos::geom::Coordinate(point.x, point.y));
}
// Add beggining point to create linear ring
temp->add(geos::geom::Coordinate(poly.begin()->x, poly.begin()->y));

// Create Linear Ring For Constructor
geos::geom::LinearRing* box = factory.createLinearRing(temp);
// Factory returns a pointer, dereference this
geos::geom::Geometry* GEOSPoly = factory.createPolygon(box, NULL);

// Remove Self Intersections and create Hull
return GEOSPoly->buffer(0); //line that causes assertion

最佳答案

断言表明您的 factory 和/或 box 几何体没有附加任何 PrecisionModel 实例。

在当前的 GEOS C++ API 中,默认构造器不可访问,您可以通过这种方式创建工厂:

auto factory = geos::geom::GeometryFactory::create()

现在,factory 使用默认的浮点精度模型并且 factory->getPrecisionModel() 必须是非 nullptr

任何使用 geos::geom::GeometryFactory::create* 函数族创建的几何实例都接收工厂的精度模型,即 box->getPrecisionModel() 返回指向 PrecisionModel 类的同一实例的指针。

关于c++ - GEOS C++ geos::Geometry Buffer(0) 对 convexHull 的错误断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37780628/

相关文章:

c++ - 防止 IOKit 驱动程序在 "kextunload"中关闭,除非某些客户端保持连接

c++ - for 循环不会从 i = 0 开始

django - 在 GeoDjango 上剥离 Z 维度(强制 2D 几何)

c++ - API 内存 : Heap or Stack? (C++)

用于双向随机访问的 C++ 高效数据结构

c++ - 如何在终止前强制输入?

c++ - 查找最接近质心的几何内部点

gis - 为什么 shapely/geos 可以解析这个 'invalid' Well Known Binary?

postgresql - st_clusterdbscan 不可用,但 postgis 正在安装在 postgresql 上

postgis - 在 PostGIS 中,大于半个世界的多边形被视为相反的多边形