Skip to content
Permalink
Browse files

Unit tests for straightDistance2d/sinuosity

  • Loading branch information
nyalldawson committed Mar 10, 2018
1 parent 6c17905 commit 41d16a8491ece94addf57774b840d3e175e91ec3
Showing with 24 additions and 0 deletions.
  1. +24 −0 tests/src/python/test_qgsgeometry.py
@@ -3525,6 +3525,30 @@ def testMergeLines(self):
exp = 'MultiLineString((0 0, 10 10),(12 2, 14 4))'
self.assertTrue(compareWkt(result, exp, 0.00001), "Merge lines: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))

def testCurveSinuosity(self):
"""
Test curve straightDistance2d() and sinuosity()
"""
linestring = QgsGeometry.fromWkt('LineString()')
self.assertEqual(linestring.constGet().straightDistance2d(), 0.0)
self.assertTrue(math.isnan(linestring.constGet().sinuosity()))
linestring = QgsGeometry.fromWkt('LineString(0 0, 10 0)')
self.assertEqual(linestring.constGet().straightDistance2d(), 10.0)
self.assertEqual(linestring.constGet().sinuosity(), 1.0)
linestring = QgsGeometry.fromWkt('LineString(0 0, 10 10, 5 0)')
self.assertAlmostEqual(linestring.constGet().straightDistance2d(), 5.0, 4)
self.assertAlmostEqual(linestring.constGet().sinuosity(), 5.06449510, 4)
linestring = QgsGeometry.fromWkt('LineString(0 0, 10 0, 10 10, 0 10, 0 0)')
self.assertEqual(linestring.constGet().straightDistance2d(), 0.0)
self.assertTrue(math.isnan(linestring.constGet().sinuosity()))

curve = QgsGeometry.fromWkt('CircularString (20 30, 50 30, 50 90)')
self.assertAlmostEqual(curve.constGet().straightDistance2d(), 67.08203932, 4)
self.assertAlmostEqual(curve.constGet().sinuosity(), 1.57079632, 4)
curve = QgsGeometry.fromWkt('CircularString (20 30, 50 30, 20 30)')
self.assertAlmostEqual(curve.constGet().straightDistance2d(), 0.0, 4)
self.assertTrue(math.isnan(curve.constGet().sinuosity()))

def testLineLocatePoint(self):
""" test QgsGeometry.lineLocatePoint() """

0 comments on commit 41d16a8

Please sign in to comment.
You can’t perform that action at this time.