Skip to content

Commit 9f3a879

Browse files
committed
also handle ringless polygons with GEOS <3.3 (follows 6370153)
1 parent 07ea0aa commit 9f3a879

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/core/qgsgeometry.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -353,24 +353,37 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline )
353353

354354
static GEOSGeometry *createGeosPolygon( const QVector<GEOSGeometry*> &rings )
355355
{
356-
if ( rings.size() < 1 )
356+
GEOSGeometry *shell;
357+
358+
if ( rings.size() == 0 )
357359
{
360+
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
361+
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
358362
return GEOSGeom_createEmptyPolygon();
363+
#else
364+
shell = GEOSGeom_createLinearRing( GEOSCoordSeq_create( 0, 2 ) );
365+
#endif
359366
}
360-
GEOSGeometry *shell = rings[0];
367+
else
368+
{
369+
shell = rings[0];
370+
}
371+
361372
GEOSGeometry **holes = NULL;
373+
int nHoles = 0;
362374

363375
if ( rings.size() > 1 )
364376
{
365-
holes = new GEOSGeometry*[ rings.size()-1 ];
377+
nHoles = rings.size() - 1;
378+
holes = new GEOSGeometry*[ nHoles ];
366379
if ( !holes )
367380
return 0;
368381

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

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

375388
if ( holes )
376389
delete [] holes;

0 commit comments

Comments
 (0)