Skip to content

Commit 933df66

Browse files
committedDec 8, 2018
Fix crash when calculating offset on certain single curves which become multilinestrings when offset
(cherry picked from commit 34c217c) Fixes #20756
1 parent a4e22ee commit 933df66

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,12 +1805,15 @@ QgsGeometry QgsGeometry::offsetCurve( double distance, int segments, JoinStyle j
18051805
return result;
18061806
}
18071807

1808-
const QgsCurve::Orientation newOrientation = qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() )->orientation();
1809-
if ( newOrientation != prevOrientation )
1808+
if ( const QgsCurve *offsetCurve = qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() ) )
18101809
{
1811-
// GEOS has flipped line orientation, flip it back
1812-
std::unique_ptr< QgsAbstractGeometry > flipped( qgsgeometry_cast< const QgsCurve * >( offsetGeom.get() )->reversed() );
1813-
offsetGeom = std::move( flipped );
1810+
const QgsCurve::Orientation newOrientation = offsetCurve->orientation();
1811+
if ( newOrientation != prevOrientation )
1812+
{
1813+
// GEOS has flipped line orientation, flip it back
1814+
std::unique_ptr< QgsAbstractGeometry > flipped( offsetCurve->reversed() );
1815+
offsetGeom = std::move( flipped );
1816+
}
18141817
}
18151818
return QgsGeometry( std::move( offsetGeom ) );
18161819
}

‎tests/src/python/test_qgsgeometry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4601,6 +4601,8 @@ def testOffsetCurve(self):
46014601
["LINESTRING (0 0, 0 100, 100 100)", -1, "LineString (1 0, 1 99, 100 99)"],
46024602
["LINESTRING (100 100, 0 100, 0 0)", 1, "LineString (100 99, 1 99, 1 0)"],
46034603
["LINESTRING (100 100, 0 100, 0 0)", -1, "LineString (100 101, -1 101, -1 0)"],
4604+
# linestring which becomes multilinestring -- the actual offset curve calculated by GEOS looks bad, but we shouldn't crash here
4605+
["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))"],
46044606
["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))"]
46054607
]
46064608
for t in tests:

0 commit comments

Comments
 (0)
Please sign in to comment.