Search code examples
boostogrboost-geometry

How to register OGRLineString as boost linestring?


I would like to use the boost::geometry::simplify method with OGRLineStrings. While I am able to register the OGRPointvia the macro:

BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(OGRPoint, double, cs::cartesian, OGRPoint::getX, OGRPoint::getY, OGRPoint::setX, OGRPoint::setY)

I am currently not able to use the following code:

#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);
}

The Simplyfy method doens't compile and I get errors stating something about boost:mpl::eval_if_c which doesn't help me.


Solution

  • A Boost.Geometry linestring must fulfil the Boost.Range Concept. A std::vector would, for example, do. But an OGRLineString, out of the box,.

    First, there should be an iterator defined, walking over the points the OGRLineString contains. Using OGRLineString::getPoint(...) this should basically be possible.

    Second, if the iterator is implemented, which is probably the toughest part, OGRLineString should be adapted to Boost.Range, e.g. as described here.

    If that is done, Boost.Geometry should recognize the OGRLineString as a linestring and can read it.

    However, to write into an OGRLineString, an additional step should be done. It should be a "mutable range". Because that is not (yet) defined in Boost.Range, it is until now a geometry-only thing and can be implemented by specializing three classes in the boost::geometry::traits namespace (clear, push_back and resize).