Coverage for pyguymer3/geo/cleanSrc/clean_LinearRing.py: 11%
9 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_LinearRing(
5 ring,
6 /,
7 *,
8 debug = __debug__,
9 prefix = ".",
10 tol = 1.0e-10,
11):
12 """Clean a LinearRing
14 This function cleans a LinearRing by removing bad points.
16 Parameters
17 ----------
18 ring : shapely.geometry.polygon.LinearRing
19 the LinearRing
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.linestring.LineString
31 the cleaned LinearRing
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 .clean_CoordinateSequence import clean_CoordinateSequence
59 # **************************************************************************
61 # Check argument ...
62 assert isinstance(ring, shapely.geometry.polygon.LinearRing), "\"ring\" is not a LinearRing"
64 # Return cleaned LinearRing ...
65 return clean_CoordinateSequence(
66 ring.coords,
67 debug = debug,
68 prefix = prefix,
69 tol = tol,
70 )