samedi 30 décembre 2017

How to create a geometry using a variant

Is it possible to define a boost::geometry object using a boost::variant ?

This code doesn't compile as it doesn't like the variant object used inside geom::read_wkt().

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/variant/variant.hpp>
#include <boost/variant.hpp>

namespace geom = boost::geometry;

typedef geom::model::d2::point_xy<double> point_type;
typedef geom::model::linestring<point_type> linestring_type;
typedef geom::model::polygon<point_type> polygon_type;

typedef boost::variant
  <
    point_type,
    linestring_type,
    polygon_type,
  > 
  geometryVariant;

int main() {
  std::string wkt = "LINESTRING(0 0, 1 1, 2, 2)";
  geometryVariant gv;
  geom::read_wkt(wkt, gv);
  return 0;
}

However, if I explicitly define the linestring_type it works fine

int main() {
  std::string wkt = "LINESTRING(0 0, 1 1, 2, 2)";
  linestring_type ls;
  geom::read_wkt(wkt, ls);
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire