Coverage for pyguymer3/geo/cleanSrc/clean_MultiLineString.py: 6%
16 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def clean_MultiLineString(
5 multiline,
6 /,
7 *,
8 debug = __debug__,
9 prefix = ".",
10 tol = 1.0e-10,
11):
12 """Clean a MultiLineString
14 This function cleans a MultiLineString by removing bad points.
16 Parameters
17 ----------
18 line : shapely.geometry.multilinestring.MultiLineString
19 the MultiLineString
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)
28 Returns
29 -------
30 cleans : shapely.geometry.multilinestring.MultiLineString
31 the cleaned MultiLineString
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>`_ :
39 "A sign of 1.0 means that the coordinates of the product's exterior ring
40 will be oriented counter-clockwise."
42 Copyright 2017 Thomas Guymer [1]_
44 References
45 ----------
46 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
47 """
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
56 # Import sub-functions ...
57 from ..check import check
58 from .clean_LineString import clean_LineString
60 # **************************************************************************
62 # Check argument ...
63 assert isinstance(multiline, shapely.geometry.multilinestring.MultiLineString), "\"multiline\" is not a MultiLineString"
65 # Initialize list ...
66 lines = []
68 # Loop over LineStrings ...
69 for line in multiline.geoms:
70 # Append cleaned LineString to list ...
71 lines.append(
72 clean_LineString(
73 line,
74 debug = debug,
75 prefix = prefix,
76 tol = tol,
77 )
78 )
80 # Convert list of LineStrings to a MultiLineString ...
81 cleans = shapely.geometry.multilinestring.MultiLineString(lines)
82 if debug:
83 check(cleans, prefix = prefix)
85 # Return answer ...
86 return cleans