Skip to content

Commit

Permalink
Fix crash when calculating offset on certain single curves which beco…
Browse files Browse the repository at this point in the history
…me multilinestrings when offset

(cherry picked from commit 34c217c)

Fixes #20756
  • Loading branch information
nyalldawson committed Dec 8, 2018
1 parent a4e22ee commit 933df66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1805,12 +1805,15 @@ QgsGeometry QgsGeometry::offsetCurve( double distance, int segments, JoinStyle j
return result;
}

const QgsCurve::Orientation newOrientation = qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() )->orientation();
if ( newOrientation != prevOrientation )
if ( const QgsCurve *offsetCurve = qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() ) )
{
// GEOS has flipped line orientation, flip it back
std::unique_ptr< QgsAbstractGeometry > flipped( qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() )->reversed() );
offsetGeom = std::move( flipped );
const QgsCurve::Orientation newOrientation = offsetCurve->orientation();
if ( newOrientation != prevOrientation )
{
// GEOS has flipped line orientation, flip it back
std::unique_ptr< QgsAbstractGeometry > flipped( offsetCurve->reversed() );
offsetGeom = std::move( flipped );
}
}
return QgsGeometry( std::move( offsetGeom ) );
}
Expand Down
2 changes: 2 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -4601,6 +4601,8 @@ def testOffsetCurve(self):
["LINESTRING (0 0, 0 100, 100 100)", -1, "LineString (1 0, 1 99, 100 99)"],
["LINESTRING (100 100, 0 100, 0 0)", 1, "LineString (100 99, 1 99, 1 0)"],
["LINESTRING (100 100, 0 100, 0 0)", -1, "LineString (100 101, -1 101, -1 0)"],
# linestring which becomes multilinestring -- the actual offset curve calculated by GEOS looks bad, but we shouldn't crash here
["LINESTRING (259329.820 5928370.79, 259324.337 5928371.758, 259319.678 5928372.33, 259317.064 5928372.498 )", 100, "MultiLineString ((259313.3 5928272.5, 259312.5 5928272.6),(259312.4 5928272.3, 259309.5 5928272.8, 259307.5 5928273.1))"],
["MULTILINESTRING ((0 0, 0 100, 100 100),(100 100, 0 100, 0 0))", 1, "MultiLineString ((-1 0, -1 101, 100 101),(100 99, 1 99, 1 0))"]
]
for t in tests:
Expand Down

0 comments on commit 933df66

Please sign in to comment.