diff --git a/src/core/qgsgeometry.cpp b/src/core/qgsgeometry.cpp index 9c7ad8245cb..ca3a437f86f 100644 --- a/src/core/qgsgeometry.cpp +++ b/src/core/qgsgeometry.cpp @@ -6225,45 +6225,45 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList 0 ) { - return 3; //an error occured during noding + return 3; } - GEOSGeometry *mergedLines = GEOSLineMerge( nodedGeometry ); - if ( !mergedLines ) - { - GEOSGeom_destroy( nodedGeometry ); - return 4; - } + GEOSGeometry* splitGeom = GEOSDifference( mGeos, splitLine ); + QVector lineGeoms; - QVector testedGeometries; - - for ( int i = 0; i < GEOSGetNumGeometries( mergedLines ); i++ ) + int splitType = GEOSGeomTypeId( splitGeom ); + if ( splitType == GEOS_MULTILINESTRING ) { - const GEOSGeometry *testing = GEOSGetGeometryN( mergedLines, i ); - if ( lineContainedInLine( testing, mGeos ) == 1 ) + int nGeoms = GEOSGetNumGeometries( splitGeom ); + for ( int i = 0; i < nGeoms; ++i ) { - testedGeometries << GEOSGeom_clone( testing ); + lineGeoms << GEOSGeom_clone( GEOSGetGeometryN( splitGeom, i ) ); } } + else + { + lineGeoms << GEOSGeom_clone( splitGeom ); + } - mergeGeometriesMultiTypeSplit( testedGeometries ); + mergeGeometriesMultiTypeSplit( lineGeoms ); - if ( testedGeometries.size() > 0 ) + if ( lineGeoms.size() > 0 ) { GEOSGeom_destroy( mGeos ); - mGeos = testedGeometries[0]; + mGeos = lineGeoms[0]; mDirtyWkb = true; } - for ( int i = 1; i < testedGeometries.size(); ++i ) - newGeometries << fromGeosGeom( testedGeometries[i] ); + for ( int i = 1; i < lineGeoms.size(); ++i ) + { + newGeometries << fromGeosGeom( lineGeoms[i] ); + } - GEOSGeom_destroy( nodedGeometry ); - GEOSGeom_destroy( mergedLines ); + GEOSGeom_destroy( splitGeom ); return 0; }