Coverage for pyguymer3/geo/bufferSrc/buffer_LinearRing.py: 75%
12 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 buffer_LinearRing(
5 ring,
6 dist,
7 /,
8 *,
9 debug = __debug__,
10 eps = 1.0e-12,
11 fill = 1.0,
12 fillSpace = "EuclideanSpace",
13 nAng = 9,
14 nIter = 100,
15 prefix = ".",
16 ramLimit = 1073741824,
17 simp = 0.1,
18 tol = 1.0e-10,
19):
20 """Buffer a LinearRing
22 This function reads in a LinearRing that exists on the surface of the Earth
23 and returns a [Multi]Polygon of the same LinearRing buffered by a constant
24 distance (in metres).
26 Parameters
27 ----------
28 ring : shapely.geometry.polygon.LinearRing
29 the LinearRing
30 dist : float
31 the Geodesic distance to buffer each point within the LinearRing by (in
32 metres)
33 debug : bool, optional
34 print debug messages
35 eps : float, optional
36 the tolerance of the Vincenty formula iterations
37 fill : float, optional
38 the Euclidean or Geodesic distance to fill in between each point within
39 the shapes by (in degrees or metres)
40 fillSpace : str, optional
41 the geometric space to perform the filling in (either "EuclideanSpace"
42 or "GeodesicSpace")
43 nAng : int, optional
44 the number of angles around each point within the LinearRing that are
45 calculated when buffering
46 nIter : int, optional
47 the maximum number of iterations (particularly the Vincenty formula)
48 prefix : str, optional
49 change the name of the output debugging CSVs
50 ramLimit : int, optional
51 the maximum RAM usage of each "large" array (in bytes)
52 simp : float, optional
53 how much intermediary [Multi]Polygons are simplified by; negative values
54 disable simplification (in degrees)
55 tol : float, optional
56 the Euclidean distance that defines two points as being the same (in
57 degrees)
59 Returns
60 -------
61 buffs : shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon
62 the buffered LinearRing
64 Notes
65 -----
66 According to the `Shapely documentation for the method object.buffer()
67 <https://shapely.readthedocs.io/en/stable/manual.html#object.buffer>`_ :
69 "Passed a distance of 0, buffer() can sometimes be used to "clean"
70 self-touching or self-crossing polygons such as the classic "bowtie".
71 Users have reported that very small distance values sometimes produce
72 cleaner results than 0. Your mileage may vary when cleaning surfaces."
74 According to the `Shapely documentation for the function
75 shapely.geometry.polygon.orient()
76 <https://shapely.readthedocs.io/en/stable/manual.html#shapely.geometry.polygon.orient>`_ :
78 "A sign of 1.0 means that the coordinates of the product's exterior ring
79 will be oriented counter-clockwise."
81 Copyright 2017 Thomas Guymer [1]_
83 References
84 ----------
85 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
86 """
88 # Import special modules ...
89 try:
90 import shapely
91 import shapely.geometry
92 except:
93 raise Exception("\"shapely\" is not installed; run \"pip install --user Shapely\"") from None
95 # Import sub-functions ...
96 from ..check import check
97 from .buffer_CoordinateSequence import buffer_CoordinateSequence
99 # **************************************************************************
101 # Check argument ...
102 assert isinstance(ring, shapely.geometry.polygon.LinearRing), "\"ring\" is not a LinearRing"
103 if debug:
104 check(ring, prefix = prefix)
106 # Return buffered LinearRing ...
107 return buffer_CoordinateSequence(
108 ring.coords,
109 dist,
110 debug = debug,
111 eps = eps,
112 fill = fill,
113 fillSpace = fillSpace,
114 nAng = nAng,
115 nIter = nIter,
116 prefix = prefix,
117 ramLimit = ramLimit,
118 simp = simp,
119 tol = tol,
120 )