Skip to content

Commit

Permalink
also handle ringless polygons with GEOS <3.3 (follows 6370153)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 15, 2013
1 parent 07ea0aa commit 9f3a879
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/core/qgsgeometry.cpp
Expand Up @@ -353,24 +353,37 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline )

static GEOSGeometry *createGeosPolygon( const QVector<GEOSGeometry*> &rings )
{
if ( rings.size() < 1 )
GEOSGeometry *shell;

if ( rings.size() == 0 )
{
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
return GEOSGeom_createEmptyPolygon();
#else
shell = GEOSGeom_createLinearRing( GEOSCoordSeq_create( 0, 2 ) );
#endif
}
GEOSGeometry *shell = rings[0];
else
{
shell = rings[0];
}

GEOSGeometry **holes = NULL;
int nHoles = 0;

if ( rings.size() > 1 )
{
holes = new GEOSGeometry*[ rings.size()-1 ];
nHoles = rings.size() - 1;
holes = new GEOSGeometry*[ nHoles ];
if ( !holes )
return 0;

for ( int i = 0; i < rings.size() - 1; i++ )
for ( int i = 0; i < nHoles; i++ )
holes[i] = rings[i+1];
}

GEOSGeometry *geom = GEOSGeom_createPolygon( shell, holes, rings.size() - 1 );
GEOSGeometry *geom = GEOSGeom_createPolygon( shell, holes, nHoles );

if ( holes )
delete [] holes;
Expand Down

0 comments on commit 9f3a879

Please sign in to comment.