Skip to content

Commit c90870d

Browse files
committed
Better approach to split lines. Fixes bug #4618
1 parent e635f04 commit c90870d

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/core/qgsgeometry.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6225,45 +6225,45 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry
62256225
return 1;
62266226
}
62276227

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 )
62316231
{
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;
62406233
}
62416234

6242-
QVector<GEOSGeometry*> testedGeometries;
6235+
GEOSGeometry* splitGeom = GEOSDifference( mGeos, splitLine );
6236+
QVector<GEOSGeometry*> lineGeoms;
62436237

6244-
for ( int i = 0; i < GEOSGetNumGeometries( mergedLines ); i++ )
6238+
int splitType = GEOSGeomTypeId( splitGeom );
6239+
if ( splitType == GEOS_MULTILINESTRING )
62456240
{
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 )
62486243
{
6249-
testedGeometries << GEOSGeom_clone( testing );
6244+
lineGeoms << GEOSGeom_clone( GEOSGetGeometryN( splitGeom, i ) );
62506245
}
62516246
}
6247+
else
6248+
{
6249+
lineGeoms << GEOSGeom_clone( splitGeom );
6250+
}
62526251

6253-
mergeGeometriesMultiTypeSplit( testedGeometries );
6252+
mergeGeometriesMultiTypeSplit( lineGeoms );
62546253

6255-
if ( testedGeometries.size() > 0 )
6254+
if ( lineGeoms.size() > 0 )
62566255
{
62576256
GEOSGeom_destroy( mGeos );
6258-
mGeos = testedGeometries[0];
6257+
mGeos = lineGeoms[0];
62596258
mDirtyWkb = true;
62606259
}
62616260

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+
}
62646265

6265-
GEOSGeom_destroy( nodedGeometry );
6266-
GEOSGeom_destroy( mergedLines );
6266+
GEOSGeom_destroy( splitGeom );
62676267
return 0;
62686268
}
62696269

0 commit comments

Comments
 (0)