Coverage for pyguymer3/geo/fillinSrc/fillin_MultiPolygon.py: 5%

19 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def fillin_MultiPolygon( 

5 multipoly, 

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 MultiPolygon 

18 

19 This function reads in a MultiPolygon, made up of Polygons (with an exterior 

20 and any number of interiors), that exists on the surface of the Earth and 

21 returns a MultiPolygon of the same MultiPolygon filled in by a constant 

22 distance: either in degrees in Euclidean space; or in metres in Geodesic 

23 space. 

24 

25 Parameters 

26 ---------- 

27 multipoly : shapely.geometry.multipolygon.MultiPolygon 

28 the MultiPolygon 

29 fill : float 

30 the Euclidean or Geodesic distance to fill in between each point within 

31 the shape by (in degrees or metres) 

32 debug : bool, optional 

33 print debug messages 

34 eps : float, optional 

35 the tolerance of the Vincenty formula iterations 

36 fillSpace : str, optional 

37 the geometric space to perform the filling in (either "EuclideanSpace" 

38 or "GeodesicSpace") 

39 nIter : int, optional 

40 the maximum number of iterations (particularly the Vincenty formula) 

41 prefix : str, optional 

42 change the name of the output debugging CSVs 

43 ramLimit : int, optional 

44 the maximum RAM usage of each "large" array (in bytes) 

45 tol : float, optional 

46 the Euclidean distance that defines two points as being the same (in 

47 degrees) 

48 

49 Returns 

50 ------- 

51 fills : shapely.geometry.multipolygon.MultiPolygon 

52 the filled in MultiPolygon 

53 

54 Notes 

55 ----- 

56 Copyright 2017 Thomas Guymer [1]_ 

57 

58 References 

59 ---------- 

60 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3 

61 """ 

62 

63 # Import special modules ... 

64 try: 

65 import shapely 

66 import shapely.geometry 

67 import shapely.ops 

68 except: 

69 raise Exception("\"shapely\" is not installed; run \"pip install --user Shapely\"") from None 

70 

71 # Import sub-functions ... 

72 from ..check import check 

73 from .fillin_Polygon import fillin_Polygon 

74 

75 # ************************************************************************** 

76 

77 # Check argument ... 

78 assert isinstance(multipoly, shapely.geometry.multipolygon.MultiPolygon), "\"multipoly\" is not a MultiPolygon" 

79 if debug: 

80 check(multipoly, prefix = prefix) 

81 

82 # Initialize list ... 

83 polys = [] 

84 

85 # Loop over Polygons ... 

86 for poly in multipoly.geoms: 

87 # Append filled in Polygon to list ... 

88 polys.append( 

89 fillin_Polygon( 

90 poly, 

91 fill, 

92 debug = debug, 

93 eps = eps, 

94 fillSpace = fillSpace, 

95 nIter = nIter, 

96 prefix = prefix, 

97 ramLimit = ramLimit, 

98 tol = tol, 

99 ) 

100 ) 

101 

102 # Convert list of Polygons to a (unified) MultiPolygon ... 

103 fills = shapely.ops.unary_union(polys) 

104 if debug: 

105 check(fills, prefix = prefix) 

106 

107 # Return answer ... 

108 return fills