@@ -6225,45 +6225,45 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry
6225
6225
return 1 ;
6226
6226
}
6227
6227
6228
- // first union all the polygon rings together (to get them noded, see JTS developer guide)
6229
- GEOSGeometry* nodedGeometry = nodeGeometries ( splitLine, mGeos );
6230
- if ( !nodedGeometry )
6228
+ // check that split line has no linear intersection
6229
+ int linearIntersect = GEOSRelatePattern ( mGeos , splitLine, " 1******** " );
6230
+ if ( linearIntersect > 0 )
6231
6231
{
6232
- return 3 ; // an error occured during noding
6233
- }
6234
-
6235
- GEOSGeometry *mergedLines = GEOSLineMerge ( nodedGeometry );
6236
- if ( !mergedLines )
6237
- {
6238
- GEOSGeom_destroy ( nodedGeometry );
6239
- return 4 ;
6232
+ return 3 ;
6240
6233
}
6241
6234
6242
- QVector<GEOSGeometry*> testedGeometries;
6235
+ GEOSGeometry* splitGeom = GEOSDifference ( mGeos , splitLine );
6236
+ QVector<GEOSGeometry*> lineGeoms;
6243
6237
6244
- for ( int i = 0 ; i < GEOSGetNumGeometries ( mergedLines ); i++ )
6238
+ int splitType = GEOSGeomTypeId ( splitGeom );
6239
+ if ( splitType == GEOS_MULTILINESTRING )
6245
6240
{
6246
- const GEOSGeometry *testing = GEOSGetGeometryN ( mergedLines, i );
6247
- if ( lineContainedInLine ( testing, mGeos ) == 1 )
6241
+ int nGeoms = GEOSGetNumGeometries ( splitGeom );
6242
+ for ( int i = 0 ; i < nGeoms; ++i )
6248
6243
{
6249
- testedGeometries << GEOSGeom_clone ( testing );
6244
+ lineGeoms << GEOSGeom_clone ( GEOSGetGeometryN ( splitGeom, i ) );
6250
6245
}
6251
6246
}
6247
+ else
6248
+ {
6249
+ lineGeoms << GEOSGeom_clone ( splitGeom );
6250
+ }
6252
6251
6253
- mergeGeometriesMultiTypeSplit ( testedGeometries );
6252
+ mergeGeometriesMultiTypeSplit ( lineGeoms );
6254
6253
6255
- if ( testedGeometries .size () > 0 )
6254
+ if ( lineGeoms .size () > 0 )
6256
6255
{
6257
6256
GEOSGeom_destroy ( mGeos );
6258
- mGeos = testedGeometries [0 ];
6257
+ mGeos = lineGeoms [0 ];
6259
6258
mDirtyWkb = true ;
6260
6259
}
6261
6260
6262
- for ( int i = 1 ; i < testedGeometries.size (); ++i )
6263
- newGeometries << fromGeosGeom ( testedGeometries[i] );
6261
+ for ( int i = 1 ; i < lineGeoms.size (); ++i )
6262
+ {
6263
+ newGeometries << fromGeosGeom ( lineGeoms[i] );
6264
+ }
6264
6265
6265
- GEOSGeom_destroy ( nodedGeometry );
6266
- GEOSGeom_destroy ( mergedLines );
6266
+ GEOSGeom_destroy ( splitGeom );
6267
6267
return 0 ;
6268
6268
}
6269
6269
0 commit comments