Skip to content

Commit

Permalink
Merge pull request #9250 from uclaros/fix_reshape_bug
Browse files Browse the repository at this point in the history
Quick fix for a bug in QgsGeos::reshapeLine that causes QGIS to crash…
  • Loading branch information
m-kuhn authored Mar 21, 2019
2 parents 0f20c13 + d620ddd commit efc7e87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ static geos::unique_ptr _mergeLinestrings( const GEOSGeometry *line1, const GEOS
return nullptr;

bool intersectionAtOrigLineEndpoint =
( intersectionPoint.x() == x1 && intersectionPoint.y() == y1 ) ||
( intersectionPoint.x() == x1 && intersectionPoint.y() == y1 ) !=
( intersectionPoint.x() == x2 && intersectionPoint.y() == y2 );
bool intersectionAtReshapeLineEndpoint =
( intersectionPoint.x() == rx1 && intersectionPoint.y() == ry1 ) ||
Expand Down
12 changes: 12 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,18 @@ def testReshape(self):
wkt = g.asWkt()
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)

# Test reshape a polygon with a line starting or ending at the polygon's first vertex, no change expexted
g = QgsGeometry.fromWkt('Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))')
expWkt = g.asWkt()
g.reshapeGeometry(QgsLineString([QgsPoint(0, 0), QgsPoint(-1, -1)]))
self.assertTrue(compareWkt(g.asWkt(), expWkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt))

# Test reshape a polygon with a line starting or ending at the polygon's first vertex
g = QgsGeometry.fromWkt('Polygon ((0 0, 1 0, 1 1, 0 1, 0 0))')
self.assertEqual(g.reshapeGeometry(QgsLineString([QgsPoint(0, 0), QgsPoint(0.5, 0.5), QgsPoint(0, 1)])), QgsGeometry.Success)
expWkt = 'Polygon ((0 0, 1 0, 1 1, 0 1, 0.5 0.5, 0 0))'
self.assertTrue(compareWkt(g.asWkt(), expWkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt))

# Test reshape a line from first/last vertex
g = QgsGeometry.fromWkt('LineString (0 0, 5 0, 5 1)')
# extend start
Expand Down

0 comments on commit efc7e87

Please sign in to comment.