Skip to content

Commit b61641d

Browse files
committedJul 13, 2016
Fix crash in QgsGeometry::unaryUnion with empty geometries
1 parent 2db7fca commit b61641d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ QgsGeometry *QgsGeometry::unaryUnion( const QList<QgsGeometry*> &geometryList )
16181618
QList<QgsGeometry*>::const_iterator it = geometryList.constBegin();
16191619
for ( ; it != geometryList.constEnd(); ++it )
16201620
{
1621-
if ( *it )
1621+
if ( *it && !(( *it )->isEmpty() ) )
16221622
{
16231623
geomV2List.append(( *it )->geometry() );
16241624
}

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class TestQgsGeometry : public QObject
9090
void bufferCheck();
9191
void smoothCheck();
9292

93+
void unaryUnion();
94+
9395
void dataStream();
9496

9597
void exportToGeoJSON();
@@ -3256,6 +3258,20 @@ void TestQgsGeometry::smoothCheck()
32563258
QVERIFY( QgsGeometry::compare( multipoly, expectedMultiPoly ) );
32573259
}
32583260

3261+
void TestQgsGeometry::unaryUnion()
3262+
{
3263+
//test QgsGeometry::unaryUnion with null geometry
3264+
QString wkt1 = "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0 ))";
3265+
QString wkt2 = "Polygon ((2 2, 4 2, 4 4, 2 4, 2 2))";
3266+
QScopedPointer< QgsGeometry > geom1( QgsGeometry::fromWkt( wkt1 ) );
3267+
QScopedPointer< QgsGeometry > geom2( QgsGeometry::fromWkt( wkt2 ) );
3268+
QScopedPointer< QgsGeometry > empty( new QgsGeometry() );
3269+
QList< QgsGeometry* > list;
3270+
list << geom1.data() << empty.data() << geom2.data();
3271+
3272+
QScopedPointer< QgsGeometry > result( QgsGeometry::unaryUnion( list ) );
3273+
}
3274+
32593275
void TestQgsGeometry::dataStream()
32603276
{
32613277
QString wkt = "Point (40 50)";

0 commit comments

Comments
 (0)
Please sign in to comment.