Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#3467 closed defect (fixed)

OGRPolygon::PointOnSurface craches on self-intersecting polygon

Reported by: ftrastour Owned by: chaitanya
Priority: normal Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords: GEOS
Cc: warmerdam

Description

The function OGRPolygon::PointOnSurface? crashes on "butterfly" polygons ( self intersecting ). It crashes because the call to GEOSPointOnSurface returns null when the polygon is self intersecting ans the following createFromGEOS failed.

Here is a fix :

int OGRPolygon::PointOnSurface( OGRPoint *poPoint ) const

{
    if( poPoint == NULL )
        return OGRERR_FAILURE;
 
#ifndef HAVE_GEOS
    return OGRERR_FAILURE;
#else
    GEOSGeom hThisGeosGeom = NULL;
    GEOSGeom hOtherGeosGeom = NULL;
     
    hThisGeosGeom = exportToGEOS();
 
    if( hThisGeosGeom != NULL )
    {
     	hOtherGeosGeom = GEOSPointOnSurface( hThisGeosGeom );

        //Check if the function has find a such point.
	if( ! hOtherGeosGeom ) {
          // GEOSPointOnSurface sometimes failed on degenerated polygons.
	  GEOSGeom_destroy( hThisGeosGeom ) ;
	  return OGRERR_FAILURE ;
	}

        ...


Change History (6)

comment:1 Changed 10 years ago by warmerdam

Cc: warmerdam added
Owner: changed from warmerdam to chaitanya

Chaitanya,

Could you review and apply the suggested changes in trunk, 1.7 and 1.6 branches?

Frédéric,

Would it be possible for you to paste in the WKT for a polygon that triggers this? I'd like Chaitanya to add a test of this to the test suite.

comment:2 Changed 10 years ago by chaitanya

Keywords: GEOS added
Milestone: 1.6.4
Status: newassigned

I fixed a similar situation in OGRPolygon::Centroid() too. Applied the patch in trunk (r19088), 1.7 branch (r19090) and 1.6 branch (r19091).

Frédéric, can you give me a sample polygon for testing?

comment:3 Changed 10 years ago by ftrastour

Chaitanya,

here is a self intersecting WKT polygon :

POLYGON ((541777.73621003702 1789399.8326989261,541836.33734208031 1789280.1623735379,541867.88100016885 1789439.9155349836,541964.66262947978 1789325.2472433962,541777.73621003702 1789399.8326989261))

comment:4 Changed 10 years ago by chaitanya

Added a test for centroid of butterfly polygon in trunk (r19981).

In any case, GEOS 3.1.1 has been returning non-null GEOSGeom objects in GEOSCentroid() and GEOSPointOnSurface() methods.

Currently PointOnSurface?() method has neither C API interface nor python interface.

comment:5 Changed 10 years ago by chaitanya

Resolution: fixed
Status: assignedclosed

comment:6 Changed 7 years ago by Even Rouault

Milestone: 1.6.4

Milestone 1.6.4 deleted

Note: See TracTickets for help on using tickets.