Opened 14 years ago

Closed 13 years ago

Last modified 11 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


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;
    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 by warmerdam, 14 years ago

Cc: warmerdam added
Owner: changed from warmerdam to chaitanya


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


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 by chaitanya, 14 years ago

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 by ftrastour, 14 years ago


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 by chaitanya, 13 years ago

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 by chaitanya, 13 years ago

Resolution: fixed
Status: assignedclosed

comment:6 by Even Rouault, 11 years ago

Milestone: 1.6.4

Milestone 1.6.4 deleted

Note: See TracTickets for help on using tickets.