Coverage for pyguymer3/geo/ll2mer.py: 4%

28 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 ll2mer( 

5 shape1, 

6 /, 

7 *, 

8 debug = __debug__, 

9 prefix = ".", 

10 tol = 1.0e-10, 

11): 

12 """Transform from Longitudes/Latitudes to Mercator fractions 

13 

14 This function reads in a shape whose coordinates are Longitudes/Latitudes 

15 and returns a shape whose coordinates are fractions on the Mercator 

16 projection. 

17 

18 Parameters 

19 ---------- 

20 shape1 : 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 

21 the shape 

22 debug : bool, optional 

23 print debug messages 

24 prefix : str, optional 

25 change the name of the output debugging CSVs 

26 tol : float, optional 

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

28 degrees) 

29 

30 Returns 

31 ------- 

32 shape2 : 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 

33 the transformed shape 

34 

35 Notes 

36 ----- 

37 Copyright 2017 Thomas Guymer [1]_ 

38 

39 References 

40 ---------- 

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

42 """ 

43 

44 

45 # Import special modules ... 

46 try: 

47 import shapely 

48 import shapely.geometry 

49 except: 

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

51 

52 # Import sub-functions ... 

53 from .ll2merSrc import ll2mer_LinearRing 

54 from .ll2merSrc import ll2mer_LineString 

55 from .ll2merSrc import ll2mer_MultiLineString 

56 from .ll2merSrc import ll2mer_MultiPoint 

57 from .ll2merSrc import ll2mer_MultiPolygon 

58 from .ll2merSrc import ll2mer_Point 

59 from .ll2merSrc import ll2mer_Polygon 

60 

61 # ************************************************************************** 

62 

63 # Check if it is a Point and return it transformed ... 

64 if isinstance(shape1, shapely.geometry.point.Point): 

65 return ll2mer_Point( 

66 shape1, 

67 debug = debug, 

68 prefix = prefix, 

69 ) 

70 

71 # Check if it is a MultiPoint and return it transformed ... 

72 if isinstance(shape1, shapely.geometry.multipoint.MultiPoint): 

73 return ll2mer_MultiPoint( 

74 shape1, 

75 debug = debug, 

76 prefix = prefix, 

77 ) 

78 

79 # Check if it is a LinearRing and return it transformed ... 

80 if isinstance(shape1, shapely.geometry.polygon.LinearRing): 

81 return ll2mer_LinearRing( 

82 shape1, 

83 debug = debug, 

84 prefix = prefix, 

85 ) 

86 

87 # Check if it is a LineString and return it transformed ... 

88 if isinstance(shape1, shapely.geometry.linestring.LineString): 

89 return ll2mer_LineString( 

90 shape1, 

91 debug = debug, 

92 prefix = prefix, 

93 ) 

94 

95 # Check if it is a MultiLineString and return it transformed ... 

96 if isinstance(shape1, shapely.geometry.multilinestring.MultiLineString): 

97 return ll2mer_MultiLineString( 

98 shape1, 

99 debug = debug, 

100 prefix = prefix, 

101 ) 

102 

103 # Check if it is a Polygon and return it transformed ... 

104 if isinstance(shape1, shapely.geometry.polygon.Polygon): 

105 return ll2mer_Polygon( 

106 shape1, 

107 debug = debug, 

108 prefix = prefix, 

109 tol = tol, 

110 ) 

111 

112 # Check if it is a MultiPolygon and return it transformed ... 

113 if isinstance(shape1, shapely.geometry.multipolygon.MultiPolygon): 

114 return ll2mer_MultiPolygon( 

115 shape1, 

116 debug = debug, 

117 prefix = prefix, 

118 tol = tol, 

119 ) 

120 

121 # Crash ... 

122 raise TypeError(f"\"shape1\" is an unexpected type ({repr(type(shape1))})") from None