Modify

Opened 21 months ago

Closed 15 months ago

Last modified 15 months ago

#11725 closed Bugs (fixed)

union_ fails to create holes

Reported by: jan.kleemann@… Owned by: barendgehrels
Milestone: Boost 1.61.0 Component: geometry
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

When uniting 2 polygons union_ does not create holes when it can also express the resulting polygon as a single ring, even if that ring has self-tangencies, which makes the polygon invalid.

The following code

typedef double FloatType;
typedef model::d2::point_xy<FloatType> Point;
typedef model::polygon<Point> Polygon;
typedef model::multi_polygon<Polygon> MultiPolygon;
typedef model::ring<Point> Ring;
typedef model::box<Point> Box;
typedef model::linestring<Point> LineString;


int main(int argc, char *argv[])
{
   using namespace std;

   Polygon p1, p2;
   boost::geometry::read_wkt("POLYGON((0 0, 0 1, 3 1, 3 0, 0 0))", p1);
   boost::geometry::read_wkt("POLYGON((0 1, 0 3, 3 3, 3 1, 2 2, 1 2 , 1 1, 0 1))", p2);

   boost::geometry::correct(p1);
   boost::geometry::correct(p2);

   MultiPolygon p3;
   boost::geometry::union_(p1, p2, p3);
   boost::geometry::correct(p3);

   cout << "p1: " << boost::geometry::wkt(p1) << endl;
   cout << "p2: " << boost::geometry::wkt(p2) << endl;
   cout << "p3: " << boost::geometry::wkt(p3) << endl;

   cout << "is_simple(p1): " << boost::geometry::is_simple(p1) << endl;
   cout << "is_simple(p2): " << boost::geometry::is_simple(p2) << endl;
   cout << "is_simple(p3): " << boost::geometry::is_simple(p3) << endl;
   cout << "is_valid(p1): " << boost::geometry::is_valid(p1) << endl;
   cout << "is_valid(p2): " << boost::geometry::is_valid(p2) << endl;
   cout << "is_valid(p3): " << boost::geometry::is_valid(p3) << endl;
   return 0;
}

has the output

p1: POLYGON((0 0,0 1,3 1,3 0,0 0))
p2: POLYGON((0 1,0 3,3 3,3 1,2 2,1 2,1 1,0 1))
p3: MULTIPOLYGON(((0 1,0 3,3 3,3 1,2 2,1 2,1 1,3 1,3 0,0 0,0 1)))
is_simple(p1): 1
is_simple(p2): 1
is_simple(p3): 1
is_valid(p1): 1
is_valid(p2): 1
is_valid(p3): 0

but p3 should be

MULTIPOLYGON(((0 1,0 3,3 3,3 0,0 0,0 1),(3 1,2 2,1 2,1 1,3 1)))

Attachments (0)

Change History (4)

comment:1 Changed 21 months ago by jan.kleemann@…

  • Component changed from algorithm to geometry
  • Owner changed from marshall to barendgehrels

comment:2 Changed 21 months ago by jan.kleemann@…

difference has the same problem:

p1: POLYGON((0 0,0 3,3 3,3 0,0 0))
p2: POLYGON((3 1,1 1,1 2,2 2,3 1))
is_valid(p1): 1
is_valid(p2): 1
p1 - p2: MULTIPOLYGON(((3 1,3 0,0 0,0 3,3 3,3 1,2 2,1 2,1 1,3 1)))
is_valid(p1 - p2): 0

Should also be

p1 - p2: MULTIPOLYGON(((0 1,0 3,3 3,3 0,0 0,0 1),(3 1,2 2,1 2,1 1,3 1)))

comment:3 Changed 15 months ago by barendgehrels

  • Milestone changed from To Be Determined to Boost 1.61.0
  • Resolution set to fixed
  • Status changed from new to closed

Thanks for the report. It is fixed now in branch feature/cluster_touch. Hope to get it in 1.61

comment:4 Changed 15 months ago by jan.kleemann@…

Nice! Thank you for your work.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain barendgehrels.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.