Fix crash in QgsGeometry::splitGeometry

This commit is contained in:
Nyall Dawson 2017-10-18 15:35:48 +10:00
parent a6ac876d90
commit f77377e6ae
2 changed files with 15 additions and 10 deletions

View File

@ -888,18 +888,10 @@ QgsGeometryEngine::EngineOperationResult QgsGeos::splitPolygonGeometry( GEOSGeom
}
GEOSGeom_destroy_r( geosinit.ctxt, polygons );
bool splitDone = true;
int nGeometriesThis = numberOfGeometries( mGeos ); //original number of geometries
if ( testedGeometries.size() == nGeometriesThis )
{
splitDone = false;
}
mergeGeometriesMultiTypeSplit( testedGeometries );
//no split done, preserve original geometry
if ( !splitDone )
if ( testedGeometries.empty() || testedGeometries.size() == nGeometriesThis )
{
//no split done, preserve original geometry
for ( int i = 0; i < testedGeometries.size(); ++i )
{
GEOSGeom_destroy_r( geosinit.ctxt, testedGeometries[i] );
@ -907,6 +899,8 @@ QgsGeometryEngine::EngineOperationResult QgsGeos::splitPolygonGeometry( GEOSGeom
return NothingHappened;
}
mergeGeometriesMultiTypeSplit( testedGeometries );
int i;
for ( i = 0; i < testedGeometries.size() && GEOSisValid_r( geosinit.ctxt, testedGeometries[i] ); ++i )
;

View File

@ -136,6 +136,7 @@ class TestQgsGeometry : public QObject
void createCollectionOfType();
void minimalEnclosingCircle( );
void splitGeometry();
private:
//! A helper method to do a render check to see if the geometry op is as expected
@ -15553,6 +15554,16 @@ void TestQgsGeometry::minimalEnclosingCircle()
}
void TestQgsGeometry::splitGeometry()
{
QgsGeometry g1 = QgsGeometry::fromWkt( QStringLiteral( "Polygon ((492980.38648063864093274 7082334.45244149677455425, 493082.65415841294452548 7082319.87918917648494244, 492980.38648063858272508 7082334.45244149677455425, 492980.38648063864093274 7082334.45244149677455425))" ) );
QList<QgsGeometry> newGeoms;
QList<QgsPointXY> testPoints;
QCOMPARE( g1.splitGeometry( QList< QgsPointXY >() << QgsPointXY( 493825.46541286131832749, 7082214.02779923938214779 ) << QgsPointXY( 492955.04876351181883365, 7082338.06309300474822521 ),
newGeoms, false, testPoints ), QgsGeometry::NothingHappened );
QVERIFY( newGeoms.isEmpty() );
}
QGSTEST_MAIN( TestQgsGeometry )
#include "testqgsgeometry.moc"