Coverage for pyguymer3/geo/cleanSrc/clean_LineString.py: 11%

9 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def clean_LineString( 

5 line, 

6 /, 

7 *, 

8 debug = __debug__, 

9 prefix = ".", 

10 tol = 1.0e-10, 

11): 

12 """Clean a LineString 

13 

14 This function cleans a LineString by removing bad points. 

15 

16 Parameters 

17 ---------- 

18 line : shapely.geometry.linestring.LineString 

19 the LineString 

20 debug : bool, optional 

21 print debug messages 

22 prefix : str, optional 

23 change the name of the output debugging CSVs 

24 tol : float, optional 

25 the Euclidean distance that defines two points as being the same (in 

26 degrees) 

27 

28 Returns 

29 ------- 

30 cleans : shapely.geometry.linestring.LineString 

31 the cleaned LineString 

32 

33 Notes 

34 ----- 

35 According to the `Shapely documentation for the function 

36 shapely.geometry.polygon.orient() 

37 <https://shapely.readthedocs.io/en/stable/manual.html#shapely.geometry.polygon.orient>`_ : 

38 

39 "A sign of 1.0 means that the coordinates of the product's exterior ring 

40 will be oriented counter-clockwise." 

41 

42 Copyright 2017 Thomas Guymer [1]_ 

43 

44 References 

45 ---------- 

46 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3 

47 """ 

48 

49 # Import special modules ... 

50 try: 

51 import shapely 

52 import shapely.geometry 

53 except: 

54 raise Exception("\"shapely\" is not installed; run \"pip install --user Shapely\"") from None 

55 

56 # Import sub-functions ... 

57 from .clean_CoordinateSequence import clean_CoordinateSequence 

58 

59 # ************************************************************************** 

60 

61 # Check argument ... 

62 assert isinstance(line, shapely.geometry.linestring.LineString), "\"line\" is not a LineString" 

63 

64 # Return cleaned LineString ... 

65 return clean_CoordinateSequence( 

66 line.coords, 

67 debug = debug, 

68 prefix = prefix, 

69 tol = tol, 

70 )