Coverage for pyguymer3/geo/fillin.py: 52%
25 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 fillin(
5 shape,
6 fill,
7 /,
8 *,
9 debug = __debug__,
10 eps = 1.0e-12,
11 fillSpace = "EuclideanSpace",
12 nIter = 100,
13 prefix = ".",
14 ramLimit = 1073741824,
15 tol = 1.0e-10,
16):
17 """Fill in a shape
19 This function reads in a shape that exists on the surface of the Earth and
20 returns the same shape filled in by a constant distance: either in degrees
21 in Euclidean space; or in metres in Geodesic space.
23 Parameters
24 ----------
25 shape : shapely.coords.CoordinateSequence, shapely.geometry.polygon.LinearRing, shapely.geometry.linestring.LineString, shapely.geometry.multilinestring.MultiLineString, shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon
26 the shape
27 fill : float
28 the Euclidean or Geodesic distance to fill in between each point within
29 the shape by (in degrees or metres)
30 debug : bool, optional
31 print debug messages
32 eps : float, optional
33 the tolerance of the Vincenty formula iterations
34 fillSpace : str, optional
35 the geometric space to perform the filling in (either "EuclideanSpace"
36 or "GeodesicSpace")
37 nIter : int, optional
38 the maximum number of iterations (particularly the Vincenty formula)
39 prefix : str, optional
40 change the name of the output debugging CSVs
41 ramLimit : int, optional
42 the maximum RAM usage of each "large" array (in bytes)
43 tol : float, optional
44 the Euclidean distance that defines two points as being the same (in
45 degrees)
47 Returns
48 -------
49 fills : shapely.coords.CoordinateSequence, shapely.geometry.polygon.LinearRing, shapely.geometry.linestring.LineString, shapely.geometry.multilinestring.MultiLineString, shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon
50 the filled in shape
52 Notes
53 -----
54 Copyright 2017 Thomas Guymer [1]_
56 References
57 ----------
58 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
59 """
61 # Import special modules ...
62 try:
63 import shapely
64 import shapely.geometry
65 except:
66 raise Exception("\"shapely\" is not installed; run \"pip install --user Shapely\"") from None
68 # Import sub-functions ...
69 from .fillinSrc import fillin_CoordinateSequence
70 from .fillinSrc import fillin_LinearRing
71 from .fillinSrc import fillin_LineString
72 from .fillinSrc import fillin_MultiLineString
73 from .fillinSrc import fillin_MultiPolygon
74 from .fillinSrc import fillin_Polygon
76 # **************************************************************************
78 # Check if it is a CoordinateSequence and return it filled ...
79 if isinstance(shape, shapely.coords.CoordinateSequence):
80 return fillin_CoordinateSequence(
81 shape,
82 fill,
83 debug = debug,
84 eps = eps,
85 fillSpace = fillSpace,
86 nIter = nIter,
87 prefix = prefix,
88 ramLimit = ramLimit,
89 )
91 # Check if it is a LinearRing and return it filled ...
92 if isinstance(shape, shapely.geometry.polygon.LinearRing):
93 return fillin_LinearRing(
94 shape,
95 fill,
96 debug = debug,
97 eps = eps,
98 fillSpace = fillSpace,
99 nIter = nIter,
100 prefix = prefix,
101 ramLimit = ramLimit,
102 )
104 # Check if it is a LineString and return it filled ...
105 if isinstance(shape, shapely.geometry.linestring.LineString):
106 return fillin_LineString(
107 shape,
108 fill,
109 debug = debug,
110 eps = eps,
111 fillSpace = fillSpace,
112 nIter = nIter,
113 prefix = prefix,
114 ramLimit = ramLimit,
115 )
117 # Check if it is a MultiLineString and return it filled ...
118 if isinstance(shape, shapely.geometry.multilinestring.MultiLineString):
119 return fillin_MultiLineString(
120 shape,
121 fill,
122 debug = debug,
123 eps = eps,
124 fillSpace = fillSpace,
125 nIter = nIter,
126 prefix = prefix,
127 ramLimit = ramLimit,
128 )
130 # Check if it is a Polygon and return it filled ...
131 if isinstance(shape, shapely.geometry.polygon.Polygon):
132 return fillin_Polygon(
133 shape,
134 fill,
135 debug = debug,
136 eps = eps,
137 fillSpace = fillSpace,
138 nIter = nIter,
139 prefix = prefix,
140 ramLimit = ramLimit,
141 tol = tol,
142 )
144 # Check if it is a MultiPolygon and return it filled ...
145 if isinstance(shape, shapely.geometry.multipolygon.MultiPolygon):
146 return fillin_MultiPolygon(
147 shape,
148 fill,
149 debug = debug,
150 eps = eps,
151 fillSpace = fillSpace,
152 nIter = nIter,
153 prefix = prefix,
154 ramLimit = ramLimit,
155 tol = tol,
156 )
158 # Crash ...
159 raise TypeError(f"\"shape\" is an unexpected type ({repr(type(shape))})") from None