@@ -3384,6 +3384,106 @@ def testDeleteVertices(self):
33843384 wkt = curvepolygon.asWkt()
33853385 assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
33863386
3387+ # curvepolygon3
3388+ curvepolygonwkt = "CurvePolygon (CompoundCurve (CircularString (3 19, 0 22, 3 25, 6 28, 9 25),( 9 25, 14 20, 19 25 ),CircularString (19 25, 22 28, 25 25, 28 22, 25 19),(25 19, 20 14, 25 9),CircularString (25 9, 28 6, 25 3, 22 0, 19 3),(19 3, 14 8, 9 3),CircularString (9 3, 6 0, 3 3, 0 6, 3 9),(3 9, 8 14, 3 19) ))))"
3389+
3390+ # passing all the vertices should not crash and the entire geometry should be cleared
3391+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3392+ assert curvepolygon.deleteVertices(
3393+ [
3394+ 0,
3395+ 1,
3396+ 2,
3397+ 3,
3398+ 4,
3399+ 5,
3400+ 6,
3401+ 7,
3402+ 8,
3403+ 9,
3404+ 10,
3405+ 11,
3406+ 12,
3407+ 13,
3408+ 14,
3409+ 15,
3410+ 16,
3411+ 17,
3412+ 18,
3413+ 19,
3414+ 20,
3415+ 21,
3416+ 22,
3417+ 23,
3418+ 24,
3419+ ]
3420+ ), "Delete vertices [0, 1, 2, 3, 4] failed"
3421+ expwkt = "CurvePolygon EMPTY"
3422+ wkt = curvepolygon.asWkt()
3423+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3424+
3425+ # test deleting single circularstring
3426+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3427+ assert curvepolygon.deleteVertices(
3428+ [0, 1, 2, 3, 4]
3429+ ), "Delete vertices [0, 1, 2, 3, 4] failed"
3430+ expwkt = "CurvePolygon (CompoundCurve ((14 20, 19 25),CircularString (19 25, 22 28, 25 25, 28 22, 25 19),(25 19, 20 14, 25 9),CircularString (25 9, 28 6, 25 3, 22 0, 19 3),(19 3, 14 8, 9 3),CircularString (9 3, 6 0, 3 3, 0 6, 3 9),(3 9, 8 14, 3 19, 14 20)))"
3431+ wkt = curvepolygon.asWkt()
3432+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3433+
3434+ # test deleting circularstrings on opposing sides
3435+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3436+ assert curvepolygon.deleteVertices(
3437+ [0, 1, 2, 3, 4, 12, 13, 14, 15, 16]
3438+ ), "Delete vertices [0, 1, 2, 3, 4, 12, 13, 14, 15, 16] failed"
3439+ expwkt = "CurvePolygon (CompoundCurve ((14 20, 19 25),CircularString (19 25, 22 28, 25 25, 28 22, 25 19),(25 19, 20 14, 14 8, 9 3),CircularString (9 3, 6 0, 3 3, 0 6, 3 9),(3 9, 8 14, 3 19, 14 20)))"
3440+ wkt = curvepolygon.asWkt()
3441+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3442+
3443+ # delete all but first circularstring
3444+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3445+ assert curvepolygon.deleteVertices(
3446+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
3447+ ), "Delete vertices [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] failed"
3448+ expwkt = "CurvePolygon (CompoundCurve ((14 8, 9 3),CircularString (9 3, 6 0, 3 3, 0 6, 3 9),(3 9, 8 14, 3 19, 14 8)))"
3449+ wkt = curvepolygon.asWkt()
3450+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3451+
3452+ # test deleting all but last arm
3453+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3454+ assert curvepolygon.deleteVertices(
3455+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
3456+ ), "Delete vertices [0, 1, 2, 3, 4, 12, 13, 14, 15, 16] failed"
3457+ expwkt = "CurvePolygon (CompoundCurve ((14 8, 9 3),CircularString (9 3, 6 0, 3 3, 0 6, 3 9),(3 9, 8 14, 3 19, 14 8)))"
3458+ wkt = curvepolygon.asWkt()
3459+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3460+
3461+ # test deleting first and last circularstring along with their connecting lines
3462+ # we are checking if the ring is properly closed after vertices are deleted
3463+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3464+ assert curvepolygon.deleteVertices(
3465+ [0, 1, 2, 3, 4, 18, 19, 20, 21, 22, 23, 24]
3466+ ), "Delete vertices [0, 1, 2, 3, 4, 18, 19, 20, 21, 22, 23, 24] failed"
3467+ expwkt = "CurvePolygon (CompoundCurve ((14 20, 19 25),CircularString (19 25, 22 28, 25 25, 28 22, 25 19),(25 19, 20 14, 25 9),CircularString (25 9, 28 6, 25 3, 22 0, 19 3),(19 3, 14 8, 14 20)))"
3468+ wkt = curvepolygon.asWkt()
3469+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3470+
3471+ # deletion of first/last point works differently if compound curve, the ring should be properly closed
3472+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3473+ assert curvepolygon.deleteVertices([0, 24]), "Delete vertices [0, 24] failed"
3474+ expwkt = "CurvePolygon (CompoundCurve (CircularString (3 25, 6 28, 9 25),( 9 25, 14 20, 19 25 ),CircularString (19 25, 22 28, 25 25, 28 22, 25 19),(25 19, 20 14, 25 9),CircularString (25 9, 28 6, 25 3, 22 0, 19 3),(19 3, 14 8, 9 3),CircularString (9 3, 6 0, 3 3, 0 6, 3 9),(3 9, 8 14, 3 25)))"
3475+ wkt = curvepolygon.asWkt()
3476+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3477+
3478+ # test deletion of line connection between first and last circularstrings
3479+ # connecting line is made out of 3 points, after removing 2 of them
3480+ # circularstrings should not merge, but be joined with a line connecting the start/end points
3481+ curvepolygon = QgsGeometry.fromWkt(curvepolygonwkt)
3482+ assert curvepolygon.deleteVertices([24, 23]), "Delete vertices [24, 23] failed"
3483+ expwkt = "CurvePolygon (CompoundCurve (CircularString (3 19, 0 22, 3 25, 6 28, 9 25),(9 25, 14 20, 19 25),CircularString (19 25, 22 28, 25 25, 28 22, 25 19),(25 19, 20 14, 25 9),CircularString (25 9, 28 6, 25 3, 22 0, 19 3),(19 3, 14 8, 9 3),CircularString (9 3, 6 0, 3 3, 0 6, 3 9),(3 9, 3 19)))"
3484+ wkt = curvepolygon.asWkt()
3485+ assert compareWkt(expwkt, wkt), f"Expected:\n{expwkt}\nGot:\n{wkt}\n"
3486+
33873487 def testInsertVertex(self):
33883488 linestring = QgsGeometry.fromWkt("LineString(1 0, 2 0)")
33893489
0 commit comments