I am trying to iterate over all the points in the boost polygon. Is there an API to handle this.?
Here is a simple example of setting and retrieving the BOOST polygon vertex coordinates:
#include <boost/geometry.hpp>
namespace bg = boost::geometry;
typedef bg::model::d2::point_xy<double> boost_point;
typedef bg::model::polygon<boost_point> boost_polygon;
[...]
//setting vertices
boost_polygon poly;
bg::append(poly.outer(), boost_point(-1, -1));
bg::append(poly.outer(), boost_point(-1, 1));
bg::append(poly.outer(), boost_point( 1, 1));
bg::append(poly.outer(), boost_point( 1, -1));
bg::append(poly.outer(), boost_point(-1, -1));
//getting the vertices back
for(auto it = boost::begin(boost::geometry::exterior_ring(poly)); it != boost::end(boost::geometry::exterior_ring(poly)); ++it)
{
double x = bg::get<0>(*it);
double y = bg::get<1>(*it);
//use the coordinates...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With