Skip to content
Permalink
Browse files

Fix crash when calculating offset on certain single curves which beco…

…me multilinestrings when offset

(cherry picked from commit 34c217c)

Fixes #20756
  • Loading branch information
nyalldawson committed Dec 8, 2018
1 parent a4e22ee commit 933df6684bb761cc144c44cf49289cc7dc63b7a8
Showing with 10 additions and 5 deletions.
  1. +8 −5 src/core/geometry/qgsgeometry.cpp
  2. +2 −0 tests/src/python/test_qgsgeometry.py
@@ -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 ) );
}
@@ -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:

0 comments on commit 933df66

Please sign in to comment.
You can’t perform that action at this time.