Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#9777-ML: Avoid Fill invalid geometries to GEOSGeometry
  • Loading branch information
ahuarte47 committed Oct 8, 2014
1 parent e5850f3 commit 80871c6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/core/qgsgeometry.cpp
Expand Up @@ -268,7 +268,7 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline )
{
GEOSCoordSequence *coord = 0;

if ( polyline.count() == 0 )
if ( polyline.count() <= 2 )
return 0;

try
Expand All @@ -282,6 +282,9 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline )
}
else
{
if ( polyline.count() == 3 ) //-> Avoid 'GEOS::IllegalArgumentException: Invalid number of points in LinearRing found 3 - must be 0 or >= 4'
return 0;

coord = createGeosCoordSequence( polyline );
}

Expand Down Expand Up @@ -352,7 +355,10 @@ static GEOSGeometry *createGeosPolygon( const QgsPolygon& polygon )
try
{
for ( int i = 0; i < polygon.count(); i++ )
geoms << createGeosLinearRing( polygon[i] );
{
GEOSGeometry *ring = createGeosLinearRing( polygon[i] );
if ( ring ) geoms << ring;
}

return createGeosPolygon( geoms );
}
Expand Down Expand Up @@ -4063,7 +4069,8 @@ bool QgsGeometry::exportWkbToGeos() const
sequence << QgsPoint( x, y );
}

rings << createGeosLinearRing( sequence );
GEOSGeometry *ring = createGeosLinearRing( sequence );
if ( ring ) rings << ring;
}
mGeos = createGeosPolygon( rings );
mDirtyGeos = false;
Expand Down Expand Up @@ -4110,10 +4117,12 @@ bool QgsGeometry::exportWkbToGeos() const
sequence << QgsPoint( x, y );
}

rings << createGeosLinearRing( sequence );
GEOSGeometry *ring = createGeosLinearRing( sequence );
if ( ring ) rings << ring;
}

polygons << createGeosPolygon( rings );
GEOSGeometry *polygon = createGeosPolygon( rings );
if ( polygon ) polygons << polygon;
}
mGeos = createGeosCollection( GEOS_MULTIPOLYGON, polygons );
mDirtyGeos = false;
Expand Down

0 comments on commit 80871c6

Please sign in to comment.