towards batch download
This commit is contained in:
@@ -1,23 +1,33 @@
|
||||
import re
|
||||
|
||||
|
||||
def format_coord(latitude: float, longitude: float) -> str:
|
||||
def component_to_str(value: float, pos_letter: str, neg_letter: str) -> str:
|
||||
"""Convert a coordinate value to a string with a hemisphere indicator."""
|
||||
hemi = pos_letter if value >= 0 else neg_letter
|
||||
abs_val = abs(value)
|
||||
degrees = int(abs_val)
|
||||
fraction = int(round((abs_val - degrees) * 100)) # .25 becomes 25
|
||||
return f"{hemi}{degrees:02d}{fraction:02d}"
|
||||
|
||||
|
||||
def latitude_to_str(latitude: float) -> str:
|
||||
"""Convert a latitude value to a string with a hemisphere indicator."""
|
||||
return component_to_str(latitude, "N", "S")
|
||||
|
||||
|
||||
def longitude_to_str(latitude: float) -> str:
|
||||
"""Convert a longitude value to a string with a hemisphere indicator."""
|
||||
return component_to_str(latitude, "E", "W")
|
||||
|
||||
|
||||
def coordinate_to_str(latitude: float, longitude: float) -> str:
|
||||
"""Format latitude and longitude into a string with hemisphere indicators."""
|
||||
|
||||
def to_str(value: float, pos_letter: str, neg_letter: str) -> str:
|
||||
"""Convert a coordinate value to a string with hemisphere indicator."""
|
||||
hemi = pos_letter if value >= 0 else neg_letter
|
||||
abs_val = abs(value)
|
||||
degrees = int(abs_val)
|
||||
fraction = int(round((abs_val - degrees) * 100)) # .25 becomes 25
|
||||
return f"{hemi}{degrees:02d}{fraction:02d}"
|
||||
|
||||
lat_str = to_str(latitude, "N", "S")
|
||||
lon_str = to_str(longitude, "E", "W")
|
||||
lat_str = latitude_to_str(latitude)
|
||||
lon_str = longitude_to_str(longitude)
|
||||
return f"{lat_str}{lon_str}"
|
||||
|
||||
|
||||
def parse_coord(coord: str) -> tuple[float, float]:
|
||||
def parse_coordinate_str(coord: str) -> tuple[float, float]:
|
||||
"""
|
||||
Parse a formatted coordinate string (e.g. 'N5225E0040' or 'S1350W12200')
|
||||
back into (latitude, longitude) float values.
|
||||
|
||||
Reference in New Issue
Block a user