@@ -3525,6 +3525,30 @@ def testMergeLines(self):
3525
3525
exp = 'MultiLineString((0 0, 10 10),(12 2, 14 4))'
3526
3526
self .assertTrue (compareWkt (result , exp , 0.00001 ), "Merge lines: mismatch Expected:\n {}\n Got:\n {}\n " .format (exp , result ))
3527
3527
3528
+ def testCurveSinuosity (self ):
3529
+ """
3530
+ Test curve straightDistance2d() and sinuosity()
3531
+ """
3532
+ linestring = QgsGeometry .fromWkt ('LineString()' )
3533
+ self .assertEqual (linestring .constGet ().straightDistance2d (), 0.0 )
3534
+ self .assertTrue (math .isnan (linestring .constGet ().sinuosity ()))
3535
+ linestring = QgsGeometry .fromWkt ('LineString(0 0, 10 0)' )
3536
+ self .assertEqual (linestring .constGet ().straightDistance2d (), 10.0 )
3537
+ self .assertEqual (linestring .constGet ().sinuosity (), 1.0 )
3538
+ linestring = QgsGeometry .fromWkt ('LineString(0 0, 10 10, 5 0)' )
3539
+ self .assertAlmostEqual (linestring .constGet ().straightDistance2d (), 5.0 , 4 )
3540
+ self .assertAlmostEqual (linestring .constGet ().sinuosity (), 5.06449510 , 4 )
3541
+ linestring = QgsGeometry .fromWkt ('LineString(0 0, 10 0, 10 10, 0 10, 0 0)' )
3542
+ self .assertEqual (linestring .constGet ().straightDistance2d (), 0.0 )
3543
+ self .assertTrue (math .isnan (linestring .constGet ().sinuosity ()))
3544
+
3545
+ curve = QgsGeometry .fromWkt ('CircularString (20 30, 50 30, 50 90)' )
3546
+ self .assertAlmostEqual (curve .constGet ().straightDistance2d (), 67.08203932 , 4 )
3547
+ self .assertAlmostEqual (curve .constGet ().sinuosity (), 1.57079632 , 4 )
3548
+ curve = QgsGeometry .fromWkt ('CircularString (20 30, 50 30, 20 30)' )
3549
+ self .assertAlmostEqual (curve .constGet ().straightDistance2d (), 0.0 , 4 )
3550
+ self .assertTrue (math .isnan (curve .constGet ().sinuosity ()))
3551
+
3528
3552
def testLineLocatePoint (self ):
3529
3553
""" test QgsGeometry.lineLocatePoint() """
3530
3554
0 commit comments