Boost Geomwetry algorithms, for efficiency, assume that input is 'normalized' or 'canonical'.
So you have to make sure that your input polygons are:
correct(green);
correct(blue);
boost::geometry::union_(green, blue, output);
int i = 0;
for(polygon const& p: output)
{
std::cout << i++ << ": " << boost::geometry::area(p) << "\n";
std::cout << "Shape: " << dsv(p) << "\n";
}
prints:
0: 1289.08
Shape: (((440813, 4.04693e+06), (440804, 4.04689e+06), (440797, 4.0469e+06), (440807, 4.04694e+06), (440820, 4.04701e+06), (440827, 4.047e+06), (440815, 4.04694e+06), (440856, 4.04693e+06), (440848, 4.04693e+06), (440813, 4.04693e+06)))
See it Live on Coliru
Full Example
#include <iostream>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/foreach.hpp>
int main()
{
typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;
using boost::geometry::correct;
using boost::geometry::dsv;
polygon green, blue;
boost::geometry::read_wkt(
"POLYGON((440820.110024126 4047009.80267429, 440806.545727707 4046942.39533656, 440797.171880196 4046895.8425726, 440804.202135392 4046888.73092639, 440813.573458131 4046935.27114371, 440827.140279322 4047002.69102807))",
green);
boost::geometry::read_wkt(
"POLYGON((440855.857887967 4046932.1248641, 440813.740724389 4046942.21109839, 440806.376538684 4046935.44583646, 440848.493702262 4046925.35960217))",
blue);
correct(green);
correct(blue);
std::vector<polygon> output;
boost::geometry::union_(green, blue, output);
int i = 0;
BOOST_FOREACH(polygon const& p, output)
{
std::cout << i++ << ": " << boost::geometry::area(p) << "\n";
std::cout << "Shape: " << dsv(p) << "\n";
}
}