Skip to content

Commit cbd29e5

Browse files
committedJan 4, 2016
Merge pull request #2632 from mhugent/nodetool_remove_lines
Remove all vertices if removing second to last line point / fourth to last ring point
2 parents 164739f + 375ae60 commit cbd29e5

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed
 

‎src/core/geometry/qgscurvepolygonv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ bool QgsCurvePolygonV2::deleteVertex( const QgsVertexId& vId )
702702

703703
QgsCurveV2* ring = vId.ring == 0 ? mExteriorRing : mInteriorRings.at( vId.ring - 1 );
704704
int n = ring->numPoints();
705-
if ( n <= 2 )
705+
if ( n <= 4 )
706706
{
707707
//no points will be left in ring, so remove whole ring
708708
if ( vId.ring == 0 )

‎src/core/geometry/qgslinestringv2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,12 @@ bool QgsLineStringV2::deleteVertex( const QgsVertexId& position )
644644
{
645645
mM.remove( position.vertex );
646646
}
647+
648+
if ( numPoints() == 1 )
649+
{
650+
clear();
651+
}
652+
647653
mBoundingBox = QgsRectangle(); //set bounding box invalid
648654
return true;
649655
}

‎tests/src/core/testqgsgeometry.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,14 +1612,12 @@ void TestQgsGeometry::lineStringV2()
16121612
QCOMPARE( l26.numPoints(), 2 );
16131613
QCOMPARE( l26.pointN( 0 ), QgsPointV2( QgsWKBTypes::PointZM, 1, 2, 2, 3 ) );
16141614
QCOMPARE( l26.pointN( 1 ), QgsPointV2( QgsWKBTypes::PointZM, 21, 22, 6, 7 ) );
1615-
QVERIFY( l26.deleteVertex( QgsVertexId( 0, 0, 0 ) ) );
1616-
QCOMPARE( l26.numPoints(), 1 );
1617-
QCOMPARE( l26.pointN( 0 ), QgsPointV2( QgsWKBTypes::PointZM, 21, 22, 6, 7 ) );
1615+
//removing the second to last vertex removes both remaining vertices
16181616
QVERIFY( l26.deleteVertex( QgsVertexId( 0, 0, 0 ) ) );
16191617
QCOMPARE( l26.numPoints(), 0 );
1618+
QVERIFY( !l26.deleteVertex( QgsVertexId( 0, 0, 0 ) ) );
16201619
QVERIFY( l26.isEmpty() );
16211620

1622-
16231621
//reversed
16241622
QgsLineStringV2 l27;
16251623
QScopedPointer< QgsLineStringV2 > reversed( l27.reversed() );
@@ -2090,6 +2088,12 @@ void TestQgsGeometry::lineStringV2()
20902088
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 0 ) ), 2.35619, 0.00001 ) );
20912089
QVERIFY( qgsDoubleNear( l38.vertexAngle( QgsVertexId( 0, 0, 6 ) ), 2.35619, 0.00001 ) );
20922090

2091+
//removing the second to last vertex should remove the whole line
2092+
QgsLineStringV2 l39;
2093+
l39.setPoints( QList<QgsPointV2>() << QgsPointV2( 0, 0 ) << QgsPointV2( 1, 1 ) );
2094+
QVERIFY( l39.numPoints() == 2 );
2095+
l39.deleteVertex( QgsVertexId( 0, 0, 1 ) );
2096+
QVERIFY( l39.numPoints() == 0 );
20932097
}
20942098

20952099
void TestQgsGeometry::polygonV2()
@@ -2806,6 +2810,14 @@ void TestQgsGeometry::polygonV2()
28062810
expectedGML3prec3 += QString( "<interior xmlns=\"gml\"><LinearRing xmlns=\"gml\"><coordinates xmlns=\"gml\">0.667,0.667 0.667,1.333 1.333,1.333 1.333,0.667 0.667,0.667</coordinates></LinearRing></interior></Polygon>" );
28072811
QCOMPARE( elemToString( exportPolygonFloat.asGML3( doc, 3 ) ), expectedGML3prec3 );
28082812

2813+
//removing the fourth to last vertex removes the whole ring
2814+
QgsPolygonV2 p20;
2815+
QgsLineStringV2* p20ExteriorRing = new QgsLineStringV2();
2816+
p20ExteriorRing->setPoints( QList<QgsPointV2>() << QgsPointV2( 0, 0 ) << QgsPointV2( 1, 0 ) << QgsPointV2( 1, 1 ) << QgsPointV2( 0, 0 ) );
2817+
p20.setExteriorRing( p20ExteriorRing );
2818+
QVERIFY( p20.exteriorRing() );
2819+
p20.deleteVertex( QgsVertexId( 0, 0, 2 ) );
2820+
QVERIFY( !p20.exteriorRing() );
28092821
}
28102822

28112823
void TestQgsGeometry::fromQgsPoint()

‎tests/src/python/test_qgsgeometry.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ def testDeleteVertex(self):
10201020
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
10211021

10221022
polyline = QgsGeometry.fromWkt("MultiLineString ((0 0, 1 0, 1 1, 2 1,2 0),(3 0, 3 1, 5 1, 5 0, 6 0))")
1023-
for i in range(5):
1023+
for i in range(4):
10241024
assert polyline.deleteVertex(5), "Delete vertex 5 failed"
10251025
expwkt = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0))"
10261026
wkt = polyline.exportToWkt()
@@ -1074,7 +1074,7 @@ def testDeleteVertex(self):
10741074
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
10751075

10761076
polygon = QgsGeometry.fromWkt("MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))")
1077-
for i in range(6):
1077+
for i in range(4):
10781078
assert polygon.deleteVertex(0), "Delete vertex 0 failed"
10791079

10801080
expwkt = "MultiPolygon (((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))"
@@ -1091,15 +1091,15 @@ def testDeleteVertex(self):
10911091
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))")
10921092
# 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
10931093

1094-
for i in range(4):
1094+
for i in range(2):
10951095
assert polygon.deleteVertex(16), "Delete vertex 16 failed" % i
10961096

10971097
expwkt = "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),(7 1, 8 1, 8 2, 7 2, 7 1))"
10981098
wkt = polygon.exportToWkt()
10991099
assert compareWkt(expwkt, wkt), "Expected:\n%s\nGot:\n%s\n" % (expwkt, wkt)
11001100

11011101
for i in range(3):
1102-
for j in range(4):
1102+
for j in range(2):
11031103
assert polygon.deleteVertex(5), "Delete vertex 5 failed" % i
11041104

11051105
expwkt = "Polygon ((0 0, 9 0, 9 3, 0 3, 0 0))"
@@ -1108,7 +1108,7 @@ def testDeleteVertex(self):
11081108

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

11141114
expwkt = "Polygon ((1 1, 2 1, 2 2, 1 2, 1 1))"

0 commit comments

Comments
 (0)
Please sign in to comment.