Skip to content

Commit acd8f26

Browse files
committedSep 9, 2015
Fix removing whole ring by progressively deleting nodes (fix #13099)
1 parent 806da2d commit acd8f26

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed
 

‎src/core/geometry/qgscurvepolygonv2.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,26 @@ bool QgsCurvePolygonV2::deleteVertex( const QgsVertexId& vId )
626626

627627
QgsCurveV2* ring = vId.ring == 0 ? mExteriorRing : mInteriorRings[vId.ring - 1];
628628
int n = ring->numPoints();
629-
if ( n <= 4 )
629+
if ( n <= 2 )
630630
{
631-
return false;
631+
//no points will be left in ring, so remove whole ring
632+
if ( vId.ring == 0 )
633+
{
634+
delete mExteriorRing;
635+
mExteriorRing = 0;
636+
if ( !mInteriorRings.isEmpty() )
637+
{
638+
mExteriorRing = mInteriorRings.takeFirst();
639+
}
640+
}
641+
else
642+
{
643+
removeInteriorRing( vId.ring - 1 );
644+
}
645+
mBoundingBox = QgsRectangle();
646+
return true;
632647
}
648+
633649
bool success = ring->deleteVertex( vId );
634650
if ( success )
635651
{

‎tests/src/python/test_qgsgeometry.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def testDeleteVertex(self):
979979
# | |
980980
# 0-+-+-+-+---+-+-+-1
981981
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))")
982-
# 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
982+
# 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
983983

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

999+
#Remove whole outer ring, inner ring should become outer
1000+
polygon = QgsGeometry.fromWkt("Polygon ((0 0, 9 0, 9 3, 0 3, 0 0),(1 1, 2 1, 2 2, 1 2, 1 1))")
1001+
for i in range(4):
1002+
assert polygon.deleteVertex(0), "Delete vertex 16 failed" % i
1003+
1004+
expwkt = "Polygon ((1 1, 2 1, 2 2, 1 2, 1 1))"
1005+
wkt = polygon.exportToWkt()
1006+
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
1007+
9991008
def testInsertVertex(self):
10001009
linestring = QgsGeometry.fromWkt("LineString(1 0, 2 0)")
10011010

0 commit comments

Comments
 (0)
Please sign in to comment.