Skip to content

Commit

Permalink
[processing] Fix "Split with lines" algorithm can get stuck in
Browse files Browse the repository at this point in the history
an endless loop if geos difference result is numerically unstable

Amend the test to determine whether a split occurred from an exact
topological test to instead test with a very small tolerance. This
avoids us flagging that a split has occurred when the actual results
have only varied by a insignificant amount due to precision of
the GEOS difference op.

This fixes a hang which can otherwise result where we keep splitting
the same pair of lines and think that a change is occurring every
time.
  • Loading branch information
nyalldawson committed Oct 15, 2020
1 parent bf319fd commit 05645b3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/analysis/processing/qgsalgorithmsplitwithlines.cpp
Expand Up @@ -209,12 +209,14 @@ QVariantMap QgsSplitWithLinesAlgorithm::processAlgorithm( const QVariantMap &par

// splitGeometry: If there are several intersections
// between geometry and splitLine, only the first one is considered.
if ( result == QgsGeometry::Success ) // split occurred
if ( result == QgsGeometry::Success )
{
if ( inGeom.isGeosEqual( before ) )
// sometimes the resultant geometry has changed from the input, but only because of numerical precision issues.
// and is effectively indistinguishable from the input. By testing the Hausdorff distance is less than this threshold
// we are checking that the maximum "change" between the result and the input is actually significant enough to be meaningful...
if ( inGeom.hausdorffDistance( before ) < 1e-12 )
{
// bug in splitGeometry: sometimes it returns 0 but
// the geometry is unchanged
// effectively no change!!
outGeoms.append( inGeom );
}
else
Expand Down

0 comments on commit 05645b3

Please sign in to comment.