How to get boost :: geometry polygon in STL object?
I am sure this should be simple, because I cannot find examples in the documentation. However, I spent about 4 business days trying to do this tiny thing. I am new to C ++ (a long time R programmer), but these small data conversions confuse me.
Yes, there is a question whose title is very similar to mine: Getting point coordinates from a Boost Geometry polygon
But the code is so complex (and the poster constantly changed it so many times) that I cannot make heads or tails out of it, and I cannot imagine what other C ++ newbies will be able to do.
This is a simple example that should translate to some of the other boost :: geometry data types, so hopefully someone can follow it.
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/geometry/geometries/adapted/boost_tuple.hpp> BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) //One thing I tried is a function to use with `for_each_point()` so I set that up first. template <typename Point> void get_coordinates(Point const& p) { using boost::geometry::get; std::cout << get<0>(p) get<1>(p) << std::endl; } int main() { typedef boost::tuple<double, double> point; typedef boost::geometry::model::polygon<point> polygon; polygon poly; boost::geometry::read_wkt("polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6, 3.4 2.0, 4.1 3.0, 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7, 2.0 1.3))", poly); polygon hull; boost::geometry::convex_hull(poly, hull); // Now I know I can `dsv()` and print to the screen like this: using boost::geometry::dsv; std::cout << "hull: " << dsv(hull) << std::endl; // And/Or I can use my function with for_each_point() boost::geometry::for_each_point(hull, get_coordinates<point>); return 0; }
How to get these coordinates in an STL container? I would prefer two std :: vector one for x and one for y, but something will do.
politicalEconomist
source share