Opened 9 years ago
Closed 9 years ago
#9756 closed Bugs (invalid)
boost::geometry::union_ no result
| Reported by: | Owned by: | Barend Gehrels | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | geometry |
| Version: | Boost 1.54.0 | Severity: | Problem |
| Keywords: | union_ | Cc: |
Description
I'm trying to merge some polygons using boost::geometry::union_ but the output vector is empty for some entries.
here is an 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;
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);
if(boost::geometry::area(green) < 0) boost::geometry::reverse(green);
if(boost::geometry::area(blue) < 0 ) boost::geometry::reverse(blue);
std::vector<polygon> output;
boost::geometry::union_(green, blue, output);
std::cout << " output size is : " << output.size() << std::endl;
int i = 0;
std::cout << "green || blue:" << std::endl;
BOOST_FOREACH(polygon const& p, output)
{
std::cout << i++ << ": " << boost::geometry::area(p) << std::endl;
}
system("pause");
return 0;
}
when I drew the two polygons I obtained : (attached image)
but the result of the code above was :
output size is : 0
green | | blue:
Press any key to continue . . .
is this a bug in this function or there is a mistake in my code ?
Attachments (1)
Change History (2)
by , 9 years ago
| Attachment: | testPolygons.PNG added |
|---|
comment:1 by , 9 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

Your polygons are not closed. Please close them in the WKT, or call geometry::correct. If they are closed, the union works correctly. Or use a non-closed polygon as type.