Opened 9 years ago

Closed 8 years ago

#9206 closed Bugs (invalid)

intersection of non-closed polygons returns closed polygon

Reported by: Volker Schöch <volker@…> Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.55.0 Severity: Problem
Keywords: intersection, multi-polygon, polygon, closed, open, correct Cc: mkaravel

Description

The output multi-polygon from boost::geometry::intersection should have the same orientation, closed-ness and underlying scalar data type, as the input (multi-)polygons. My polygon type is oriented counter-clockwise and not closed, my point type is based on int. Please find below some code that results in a closed polygon.

Note: The sym_difference and difference algorithms have the same problem which I filed as separate tickets #8375, #8376.

This is the data used as input to intersection:

_TPolygon<int> const polygon =
	_TPolygon<int>("MULTIPOLYGON(((1374 1092,1734 1092,3174 2526,3174 2886,1374 2886)))")
	& _TPolygon<int>("POLYGON((2817 2449,2817 2603,3134 2603,3134 2449,2817 2449))");

This is the resulting multi-polygon, with the polygon being closed:

MULTIPOLYGON(((3134 2486,3134 2603,2817 2603,2817 2449,3096 2449,3134 2486)))

This is my code that wraps boost::geometry to implement the operator used above:

template<typename T>
template<typename Geometry>
_TPolygon< T > _TPolygon< T >::operator&(Geometry const& geometry) const
{
	_TPolygon< T > polygonOut;
	boost::geometry::intersection(*this, geometry, polygonOut);

	// should not be necessary
	//boost::geometry::correct( polygonOut );

	return polygonOut;
}

Attachments (2)

ticket_9206.out (222 bytes ) - added by mkaravel 8 years ago.
output of the ticket_9206.cpp program
ticket_9206.cpp (1.5 KB ) - added by mkaravel 8 years ago.
stand-alone test program to be used with the BG develop branch

Download all attachments as: .zip

Change History (7)

comment:1 by vschoech@…, 9 years ago

Version: Boost 1.52.0Boost 1.55.0

Still reproducible in boost 1.55.0.

by mkaravel, 8 years ago

Attachment: ticket_9206.out added

output of the ticket_9206.cpp program

comment:2 by mkaravel, 8 years ago

I have attached my own stand-alone test program.

First of all I am checking whether the two polygons are valid (new functionality in develop branch and soon in boost 1.56). As you can see the second polygon is reported as invalid. Indeed it is supposed to be counter-clockwise and open, but it is given as clockwise and open.

So after I correct this polygon, I run intersects and display the output in WKT format and using boost::geometry::dsv. I also print the number of points of the output polygon. As you can see, the WKT output "closes" the polygon. This behavior is new in the develop branch and in the upcoming boost 1.56 release: the WKT description of a polygon always reports the polygon as if it were closed. On the other hand the dsv output displays the polygon as open, which is also in sync with what num_points reports: 5 points. So the resulting polygon (at least with my program) is still open, but in order to see that you cannot rely on the WKT output.

comment:3 by mkaravel, 8 years ago

Cc: mkaravel added
Resolution: worksforme
Status: newclosed

comment:4 by mkaravel, 8 years ago

Resolution: worksforme
Status: closedreopened

comment:5 by mkaravel, 8 years ago

Resolution: invalid
Status: reopenedclosed

by mkaravel, 8 years ago

Attachment: ticket_9206.cpp added

stand-alone test program to be used with the BG develop branch

Note: See TracTickets for help on using tickets.