【问题标题】:GEOS C++ geos::Geometry Buffer(0) false assertion on convexHullGEOS C++ geos::Geometry Buffer(0) 在convexHull 上的错误断言
【发布时间】:2016-06-13 01:09:47
【问题描述】:

我目前正在使用 C++ GEOS API 遍历 typedef Pointsvector(x 和 y 成员变量)。

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

每当我发送一个已经是凸包的对象时,我都会得到以下断言: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

【问题讨论】:

  • 断言不是分段错误。断言是对代码进行的检查,以查看在继续之前是否满足某些条件,并且检查失败。
  • 对不起,我的意思是断言。它在他们的内部库中检查失败

标签: c++ geos


【解决方案1】:

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

在当前的 GEOS C++ API 中,默认的构造器是不可访问的,你可以这样创建工厂:

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

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

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

【讨论】:

    猜你喜欢
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 2013-05-29
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    相关资源
    最近更新 更多