Coverage for pyguymer3/geo/check.py: 3%
34 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 check(
5 shape,
6 /,
7 *,
8 prefix = ".",
9):
10 """Check a shape
12 This function checks if a shape is valid.
14 Parameters
15 ----------
16 shape : shapely.coords.CoordinateSequence, shapely.geometry.point.Point, shapely.geometry.multipoint.MultiPoint, shapely.geometry.polygon.LinearRing, shapely.geometry.linestring.LineString, shapely.geometry.multilinestring.MultiLineString, shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon, shapely.geometry.collection.GeometryCollection
17 the shape
18 prefix : str, optional
19 change the name of the output debugging CSVs
21 Notes
22 -----
23 According to the `Shapely documentation for the function
24 shapely.geometry.polygon.orient()
25 <https://shapely.readthedocs.io/en/stable/manual.html#shapely.geometry.polygon.orient>`_ :
27 "A sign of 1.0 means that the coordinates of the product's exterior ring
28 will be oriented counter-clockwise."
30 Copyright 2017 Thomas Guymer [1]_
32 References
33 ----------
34 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
35 """
37 # Import special modules ...
38 try:
39 import shapely
40 import shapely.geometry
41 except:
42 raise Exception("\"shapely\" is not installed; run \"pip install --user Shapely\"") from None
44 # Import sub-functions ...
45 from .checkSrc import check_CoordinateSequence
46 from .checkSrc import check_GeometryCollection
47 from .checkSrc import check_LinearRing
48 from .checkSrc import check_LineString
49 from .checkSrc import check_MultiLineString
50 from .checkSrc import check_MultiPoint
51 from .checkSrc import check_MultiPolygon
52 from .checkSrc import check_Point
53 from .checkSrc import check_Polygon
55 # **************************************************************************
57 # Check if it is a CoordinateSequence and return it checked ...
58 if isinstance(shape, shapely.coords.CoordinateSequence):
59 return check_CoordinateSequence(
60 shape,
61 )
63 # Check if it is a Point and return it checked ...
64 if isinstance(shape, shapely.geometry.point.Point):
65 return check_Point(
66 shape,
67 prefix = prefix,
68 )
70 # Check if it is a MultiPoint and return it checked ...
71 if isinstance(shape, shapely.geometry.multipoint.MultiPoint):
72 return check_MultiPoint(
73 shape,
74 prefix = prefix,
75 )
77 # Check if it is a LinearRing and return it checked ...
78 if isinstance(shape, shapely.geometry.polygon.LinearRing):
79 return check_LinearRing(
80 shape,
81 prefix = prefix,
82 )
84 # Check if it is a LineString and return it checked ...
85 if isinstance(shape, shapely.geometry.linestring.LineString):
86 return check_LineString(
87 shape,
88 prefix = prefix,
89 )
91 # Check if it is a MultiLineString and return it checked ...
92 if isinstance(shape, shapely.geometry.multilinestring.MultiLineString):
93 return check_MultiLineString(
94 shape,
95 prefix = prefix,
96 )
98 # Check if it is a Polygon and return it checked ...
99 if isinstance(shape, shapely.geometry.polygon.Polygon):
100 return check_Polygon(
101 shape,
102 prefix = prefix,
103 )
105 # Check if it is a MultiPolygon and return it checked ...
106 if isinstance(shape, shapely.geometry.multipolygon.MultiPolygon):
107 return check_MultiPolygon(
108 shape,
109 prefix = prefix,
110 )
112 # Check if it is a GeometryCollection and return it checked ...
113 if isinstance(shape, shapely.geometry.collection.GeometryCollection):
114 return check_GeometryCollection(
115 shape,
116 prefix = prefix,
117 )
119 # Crash ...
120 raise TypeError(f"\"shape\" is an unexpected type ({repr(type(shape))})") from None