Skip to content

Commit e92dc26

Browse files
committedMay 17, 2016
Followup feeeaf0, add unit tests
1 parent feeeaf0 commit e92dc26

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎tests/src/python/test_qgsgeometry.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,31 @@ def testReshape(self):
16481648
wkt = g.exportToWkt()
16491649
assert compareWkt(expWkt, wkt), "testReshape failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)
16501650

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\nGot:\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\nGot:\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\nGot:\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\nGot:\n%s\n" % (expWkt, wkt)
1675+
16511676
def testConvertToMultiType(self):
16521677
""" Test converting geometries to multi type """
16531678
point = QgsGeometry.fromWkt('Point (1 2)')

0 commit comments

Comments
 (0)
Failed to load comments.