我正在使用 GEOS 库,并且正在尝试创建一个Polygon
带有孔的库。根据文档,我必须传入LinearRing
代表外部“外壳”的 a 和std::vector<Geometry*>
代表外壳中的孔的 a 。第一个参数很简单,但第二个参数给我带来了麻烦。Polygon
希望第二个参数中的元素是LineString
s(LineString
是 的子类Geometry
);否则,它会抛出一个异常,说明LineString
这些孔需要 s。如果我只是将LineString
s 转换为Geometry
,那么它会引发异常。如果我不强制转换它,我会收到一个编译错误,指出一种类型的指针不能转换为另一种类型的指针。我不知道在这里做什么。
这是一个演示错误的简短代码示例:
geos::geom::CoordinateSequence* temp = factory->getCoordinateSequenceFactory()->create((std::size_t) 0, 0);
temp->add(geos::geom::Coordinate(0, 0));
temp->add(geos::geom::Coordinate(100, 0));
temp->add(geos::geom::Coordinate(100, 100));
temp->add(geos::geom::Coordinate(0, 100));
temp->add(geos::geom::Coordinate(0, 0));
geos::geom::LinearRing *shell=factory->createLinearRing(temp);
temp = factory->getCoordinateSequenceFactory()->create((std::size_t) 0, 0);
temp->add(geos::geom::Coordinate(1, 1));
temp->add(geos::geom::Coordinate(10, 1));
temp->add(geos::geom::Coordinate(10, 10));
temp->add(geos::geom::Coordinate(1, 10));
temp->add(geos::geom::Coordinate(1, 1));
geos::geom::LinearRing *hole=factory->createLinearRing(temp);
holes->push_back((geos::geom::Geometry*) hole);
factory->createPolygon(shell,holes);
有什么建议么?