Fix crash in QgsGeometry::unaryUnion with empty geometries

This commit is contained in:
Nyall Dawson 2016-07-14 08:24:17 +10:00
parent 2db7fca7a6
commit b61641dc72
2 changed files with 17 additions and 1 deletions

View File

@ -1618,7 +1618,7 @@ QgsGeometry *QgsGeometry::unaryUnion( const QList<QgsGeometry*> &geometryList )
QList<QgsGeometry*>::const_iterator it = geometryList.constBegin();
for ( ; it != geometryList.constEnd(); ++it )
{
if ( *it )
if ( *it && !(( *it )->isEmpty() ) )
{
geomV2List.append(( *it )->geometry() );
}

View File

@ -90,6 +90,8 @@ class TestQgsGeometry : public QObject
void bufferCheck();
void smoothCheck();
void unaryUnion();
void dataStream();
void exportToGeoJSON();
@ -3256,6 +3258,20 @@ void TestQgsGeometry::smoothCheck()
QVERIFY( QgsGeometry::compare( multipoly, expectedMultiPoly ) );
}
void TestQgsGeometry::unaryUnion()
{
//test QgsGeometry::unaryUnion with null geometry
QString wkt1 = "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0 ))";
QString wkt2 = "Polygon ((2 2, 4 2, 4 4, 2 4, 2 2))";
QScopedPointer< QgsGeometry > geom1( QgsGeometry::fromWkt( wkt1 ) );
QScopedPointer< QgsGeometry > geom2( QgsGeometry::fromWkt( wkt2 ) );
QScopedPointer< QgsGeometry > empty( new QgsGeometry() );
QList< QgsGeometry* > list;
list << geom1.data() << empty.data() << geom2.data();
QScopedPointer< QgsGeometry > result( QgsGeometry::unaryUnion( list ) );
}
void TestQgsGeometry::dataStream()
{
QString wkt = "Point (40 50)";