Skip to content

Commit e4cbec0

Browse files
uclarosuclaros
authored andcommitted
Quick fix for a bug in QgsGeos::reshapeLine that causes QGIS to crash because of an unhandled geos exception.
1 parent 09df4ab commit e4cbec0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/core/geometry/qgsgeos.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ static geos::unique_ptr _mergeLinestrings( const GEOSGeometry *line1, const GEOS
23822382
return nullptr;
23832383

23842384
bool intersectionAtOrigLineEndpoint =
2385-
( intersectionPoint.x() == x1 && intersectionPoint.y() == y1 ) ||
2385+
( intersectionPoint.x() == x1 && intersectionPoint.y() == y1 ) !=
23862386
( intersectionPoint.x() == x2 && intersectionPoint.y() == y2 );
23872387
bool intersectionAtReshapeLineEndpoint =
23882388
( intersectionPoint.x() == rx1 && intersectionPoint.y() == ry1 ) ||

tests/src/python/test_qgsgeometry.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,18 @@ def testReshape(self):
22712271
wkt = g.asWkt()
22722272
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
22732273

2274+
# Test reshape a polygon with a line starting or ending at the polygon's first vertex, no change expexted
2275+
g = QgsGeometry.fromWkt('Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))')
2276+
expWkt = g.asWkt()
2277+
g.reshapeGeometry(QgsLineString([QgsPoint(0, 0), QgsPoint(-1, -1)]))
2278+
assert compareWkt(g.asWkt(), expWkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
2279+
2280+
# Test reshape a polygon with a line starting or ending at the polygon's first vertex
2281+
g = QgsGeometry.fromWkt('Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))')
2282+
g.reshapeGeometry(QgsLineString([QgsPoint(0, 0), QgsPoint(0.5, 0.5), QgsPoint(0, 1)]))
2283+
expWkt = 'Polygon ((0 0, 1 0, 1 1, 0 1, 0.5 0.5, 0 0))'
2284+
assert compareWkt(g.asWkt(), expWkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
2285+
22742286
# Test reshape a line from first/last vertex
22752287
g = QgsGeometry.fromWkt('LineString (0 0, 5 0, 5 1)')
22762288
# extend start

0 commit comments

Comments
 (0)