diff --git a/src/core/geometry/qgsgeos.cpp b/src/core/geometry/qgsgeos.cpp index f16cc29577d..e91e3e5f33f 100644 --- a/src/core/geometry/qgsgeos.cpp +++ b/src/core/geometry/qgsgeos.cpp @@ -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 ) ; diff --git a/tests/src/core/testqgsgeometry.cpp b/tests/src/core/testqgsgeometry.cpp index ab294050098..abfda953bce 100644 --- a/tests/src/core/testqgsgeometry.cpp +++ b/tests/src/core/testqgsgeometry.cpp @@ -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 newGeoms; + QList 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"