我目前正在使用 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/