我想将 boost::geometry::simplify
方法与 OGRLineString
一起使用。
虽然我可以通过宏注册 OGRPoint
:
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(OGRPoint, double, cs::cartesian, OGRPoint::getX, OGRPoint::getY, OGRPoint::setX, OGRPoint::setY)
我目前无法使用以下代码:
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/linestring.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(OGRPoint, double, cs::cartesian, OGRPoint::getX, OGRPoint::getY, OGRPoint::setX, OGRPoint::setY)
BOOST_GEOMETRY_REGISTER_LINESTRING(OGRLineString)
void example()
{
OGRLineString test;
OGRLineString simplified;
boost::geometry::simplify(test, simplified, 0.5);
}
Simplyfy 方法无法编译,我收到有关 boost:mpl::eval_if_c 的错误信息,这对我没有帮助。
最佳答案
Boost.Geometry linestring必须满足 Boost.Range 概念。例如,std::vector 会这样做。但是开箱即用的 OGRLineString。
首先,应该定义一个迭代器,遍历 OGRLineString 包含的点。使用 OGRLineString::getPoint(...) 这基本上是可能的。
其次,如果实现了迭代器,这可能是最难的部分,OGRLineString 应该适应 Boost.Range,例如如所述here .
如果这样做,Boost.Geometry 应该将 OGRLineString 识别为线串并可以读取它。
但是,要写入 OGRLineString,还需要执行一个额外的步骤。它应该是一个“可变范围”。因为这还没有在 Boost.Range 中定义,直到现在它只是一个几何图形,可以通过在 boost::geometry::traits 命名空间(clear、push_back 和 resize)中专门化三个类来实现。
关于boost - 如何将 OGRLineString 注册为 boost 线串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13196503/