Skip to content

Commit

Permalink
Fix removing whole ring by progressively deleting nodes (fix #13099)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 9, 2015
1 parent 806da2d commit acd8f26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/core/geometry/qgscurvepolygonv2.cpp
Expand Up @@ -626,10 +626,26 @@ bool QgsCurvePolygonV2::deleteVertex( const QgsVertexId& vId )

QgsCurveV2* ring = vId.ring == 0 ? mExteriorRing : mInteriorRings[vId.ring - 1];
int n = ring->numPoints();
if ( n <= 4 )
if ( n <= 2 )
{
return false;
//no points will be left in ring, so remove whole ring
if ( vId.ring == 0 )
{
delete mExteriorRing;
mExteriorRing = 0;
if ( !mInteriorRings.isEmpty() )
{
mExteriorRing = mInteriorRings.takeFirst();
}
}
else
{
removeInteriorRing( vId.ring - 1 );
}
mBoundingBox = QgsRectangle();
return true;
}

bool success = ring->deleteVertex( vId );
if ( success )
{
Expand Down
11 changes: 10 additions & 1 deletion tests/src/python/test_qgsgeometry.py
Expand Up @@ -979,7 +979,7 @@ def testDeleteVertex(self):
# | |
# 0-+-+-+-+---+-+-+-1
polygon = QgsGeometry.fromWkt("Polygon ((0 0, 9 0, 9 3, 0 3, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1),(3 1, 4 1, 4 2, 3 2, 3 1),(5 1, 6 1, 6 2, 5 2, 5 1),(7 1, 8 1, 8 2, 7 2, 7 1))")
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

for i in range(4):
assert polygon.deleteVertex(16), "Delete vertex 16 failed" % i
Expand All @@ -996,6 +996,15 @@ def testDeleteVertex(self):
wkt = polygon.exportToWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

#Remove whole outer ring, inner ring should become outer
polygon = QgsGeometry.fromWkt("Polygon ((0 0, 9 0, 9 3, 0 3, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1))")
for i in range(4):
assert polygon.deleteVertex(0), "Delete vertex 16 failed" % i

expwkt = "Polygon ((1 1, 2 1, 2 2, 1 2, 1 1))"
wkt = polygon.exportToWkt()
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)

def testInsertVertex(self):
linestring = QgsGeometry.fromWkt("LineString(1 0, 2 0)")

Expand Down

0 comments on commit acd8f26

Please sign in to comment.