Hi Stefan,

Welcome to the list.

Stefan Wörthmüller wrote On 30-10-2013 12:09:

i am currently struggling with the process of subtracting small polygons from a larger polygon. None of the polygons have holes and all small polygones are completely covered by the larger polygone. Of course, the result will be a polygon with holes.

I first tried with boost 1.48, but as this resulted in compilation errors i now upgradet to 1.54 as i read in the release notes of 1.54:
>    support for line/polygon intersections and differences.

My code looks like this:
typedef boost::geometry::model::d2::point_xy<double> boost_pnt;
typedef boost::geometry::model::polygon<boost_pnt>   boost_poly;
boost_poly outputPoly = outerPolygon;
    boost_poly innerPoly = ...;
    boost_poly new_output;
    boost::geometry::difference(outputPoly, innerPoly, new_output);
    outputPoly = new_output;

Compiling thjs with VC2010 results in the line of difference
>D:\Develop\boost\boost_1_54_0\boost/range/iterator.hpp(63): error C2039: 'type' : is not a member of 'boost::mpl::eval_if_c<C,F1,F2>'
1>          with
1>          [
1>              C=false,
1>              F1=boost::range_const_iterator<boost::geometry::model::polygon<boost_pnt>>,
1>              F2=boost::range_mutable_iterator<boost_poly>
1>          ]


So my understanding is, that difference() does not work with all parameters of type polygon.
When using std::vector<boost_poly> as last parameter, difference compiles and works, but i see no way of converting this back to a polygon.
I can not find a way to to distance in a loop.

Yes, the output should be either a multi-polygon, or a vector of polygons. The reason for that is that difference can (by theory) create multiple polygons as output. If you have a rectangle, and subtract a less wide, but higher rectangle lying in the center of the other one (like a cross), you get two rectangles, one left and one right, as output.

So the output must be a collection of polygons. If there is only one output, you have a polygon-result, you can take output.front(). If there are more, you have to deal with that, it is just the correct result.

Regards, Barend