@@ -1648,6 +1648,31 @@ def testReshape(self):
1648
1648
wkt = g .exportToWkt ()
1649
1649
assert compareWkt (expWkt , wkt ), "testReshape failed: mismatch Expected:\n %s\n Got:\n %s\n " % (expWkt , wkt )
1650
1650
1651
+ # Test reshape a line from first/last vertex
1652
+ g = QgsGeometry .fromWkt ('LineString (0 0, 5 0, 5 1)' )
1653
+ # extend start
1654
+ self .assertEqual (g .reshapeGeometry ([QgsPoint (0 , 0 ), QgsPoint (- 1 , 0 )]), 0 )
1655
+ expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1)'
1656
+ wkt = g .exportToWkt ()
1657
+ assert compareWkt (expWkt , wkt ), "testReshape failed: mismatch Expected:\n %s\n Got:\n %s\n " % (expWkt , wkt )
1658
+ # extend end
1659
+ self .assertEqual (g .reshapeGeometry ([QgsPoint (5 , 1 ), QgsPoint (10 , 1 ), QgsPoint (10 , 2 )]), 0 )
1660
+ expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1, 10 1, 10 2)'
1661
+ wkt = g .exportToWkt ()
1662
+ assert compareWkt (expWkt , wkt ), "testReshape failed: mismatch Expected:\n %s\n Got:\n %s\n " % (expWkt , wkt )
1663
+ # test with reversed lines
1664
+ g = QgsGeometry .fromWkt ('LineString (0 0, 5 0, 5 1)' )
1665
+ # extend start
1666
+ self .assertEqual (g .reshapeGeometry ([QgsPoint (- 1 , 0 ), QgsPoint (0 , 0 )]), 0 )
1667
+ expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1)'
1668
+ wkt = g .exportToWkt ()
1669
+ assert compareWkt (expWkt , wkt ), "testReshape failed: mismatch Expected:\n %s\n Got:\n %s\n " % (expWkt , wkt )
1670
+ # extend end
1671
+ self .assertEqual (g .reshapeGeometry ([QgsPoint (10 , 2 ), QgsPoint (10 , 1 ), QgsPoint (5 , 1 )]), 0 )
1672
+ expWkt = 'LineString (-1 0, 0 0, 5 0, 5 1, 10 1, 10 2)'
1673
+ wkt = g .exportToWkt ()
1674
+ assert compareWkt (expWkt , wkt ), "testReshape failed: mismatch Expected:\n %s\n Got:\n %s\n " % (expWkt , wkt )
1675
+
1651
1676
def testConvertToMultiType (self ):
1652
1677
""" Test converting geometries to multi type """
1653
1678
point = QgsGeometry .fromWkt ('Point (1 2)' )
0 commit comments