Skip to content
Permalink
Browse files

Fix removing whole ring by progressively deleting nodes (fix #13099)

  • Loading branch information
nyalldawson committed Sep 9, 2015
1 parent 806da2d commit acd8f26a914e20fdb60cfde778d7150fdda34aff
Showing with 28 additions and 3 deletions.
  1. +18 −2 src/core/geometry/qgscurvepolygonv2.cpp
  2. +10 −1 tests/src/python/test_qgsgeometry.py
@@ -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 )
{
@@ -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
@@ -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)")

0 comments on commit acd8f26

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