Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we get all the points stored in boost polygon

Tags:

c++

polygon

boost

I am trying to iterate over all the points in the boost polygon. Is there an API to handle this.?

like image 732
Ayush Agrawal Avatar asked Dec 13 '16 09:12

Ayush Agrawal


1 Answers

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...
}
like image 160
Olek Avatar answered Nov 07 '22 13:11

Olek