4

我正在使用 GEOS 库,并且正在尝试创建一个Polygon带有孔的库。根据文档,我必须传入LinearRing代表外部“外壳”的 a 和std::vector<Geometry*>代表外壳中的孔的 a 。第一个参数很简单,但第二个参数给我带来了麻烦。Polygon希望第二个参数中的元素是LineStrings(LineString是 的子类Geometry);否则,它会抛出一个异常,说明LineString这些孔需要 s。如果我只是将LineStrings 转换为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);

有什么建议么?

4

1 回答 1

2

我解决了。

我有一个包含行,其中包含geos/geom/GeometryFactory.h. 在那个文件中,有一个前向声明 to geos::geom::LinearRing,但它没有说那个类是geos::geom::Geometry. 因此,编译器将其视为两个不同的类。修好#include <geos/geom/LinearRing.h>了。

于 2014-01-30T03:41:42.680 回答