mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-21 06:47:42 +00:00
Autogenerated type safety parameterisation of all methods
This commit is contained in:
+14
-10
@@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
from math import floor, isnan
|
||||
@@ -14,7 +16,7 @@ TRANSFORMER_IRISH_GRID_TO_WGS84 = Transformer.from_crs("EPSG:29903", "EPSG:4326"
|
||||
TRANSFORMER_CI_UTM_GRID_TO_WGS84 = Transformer.from_crs("+proj=utm +zone=30 +ellps=WGS84", "EPSG:4326")
|
||||
|
||||
|
||||
def lat_lon_to_cq_zone(lat, lon):
|
||||
def lat_lon_to_cq_zone(lat: float, lon: float) -> int | None:
|
||||
"""Finds out which CQ zone a lat/lon point is in."""
|
||||
|
||||
if DATA_STORE.cq_zone_data is not None:
|
||||
@@ -36,7 +38,7 @@ def lat_lon_to_cq_zone(lat, lon):
|
||||
return None
|
||||
|
||||
|
||||
def lat_lon_to_itu_zone(lat, lon):
|
||||
def lat_lon_to_itu_zone(lat: float, lon: float) -> int | None:
|
||||
"""Finds out which ITU zone a lat/lon point is in."""
|
||||
|
||||
if DATA_STORE.itu_zone_data is not None:
|
||||
@@ -58,7 +60,7 @@ def lat_lon_to_itu_zone(lat, lon):
|
||||
return None
|
||||
|
||||
|
||||
def lat_lon_for_grid_centre(grid):
|
||||
def lat_lon_for_grid_centre(grid: str) -> list[float] | None:
|
||||
"""Convert a Maidenhead grid reference of arbitrary precision to the lat/long of the centre point of the square.
|
||||
Returns None if the grid format is invalid."""
|
||||
|
||||
@@ -69,7 +71,7 @@ def lat_lon_for_grid_centre(grid):
|
||||
return None
|
||||
|
||||
|
||||
def lat_lon_for_grid_sw_corner(grid):
|
||||
def lat_lon_for_grid_sw_corner(grid: str) -> list[float] | None:
|
||||
"""Convert a Maidenhead grid reference of arbitrary precision to the lat/long of the southwest corner of the square.
|
||||
Returns None if the grid format is invalid."""
|
||||
|
||||
@@ -80,7 +82,7 @@ def lat_lon_for_grid_sw_corner(grid):
|
||||
return None
|
||||
|
||||
|
||||
def lat_lon_for_grid_ne_corner(grid):
|
||||
def lat_lon_for_grid_ne_corner(grid: str) -> list[float] | None:
|
||||
"""Convert a Maidenhead grid reference of arbitrary precision to the lat/long of the northeast corner of the square.
|
||||
Returns None if the grid format is invalid."""
|
||||
|
||||
@@ -91,7 +93,9 @@ def lat_lon_for_grid_ne_corner(grid):
|
||||
return None
|
||||
|
||||
|
||||
def lat_lon_for_grid_sw_corner_plus_size(grid):
|
||||
def lat_lon_for_grid_sw_corner_plus_size(
|
||||
grid: str,
|
||||
) -> tuple[float, float, float, float] | tuple[None, None, None, None]:
|
||||
"""Convert a Maidenhead grid reference of arbitrary precision to lat/long, including in the result the size of the
|
||||
lowest grid square. This is a utility method used by the main methods that return the centre, southwest, and
|
||||
northeast coordinates of a grid square.
|
||||
@@ -162,7 +166,7 @@ def lat_lon_for_grid_sw_corner_plus_size(grid):
|
||||
return lat, lon, lat_cell_size, lon_cell_size
|
||||
|
||||
|
||||
def wab_wai_square_to_lat_lon(ref):
|
||||
def wab_wai_square_to_lat_lon(ref: str) -> tuple[float, float] | None:
|
||||
"""Convert a Worked All Britain or Worked All Ireland reference to a lat/lon point."""
|
||||
|
||||
# First check we have a valid grid square, and based on what it looks like, use either the Ordnance Survey, Irish,
|
||||
@@ -178,7 +182,7 @@ def wab_wai_square_to_lat_lon(ref):
|
||||
return None
|
||||
|
||||
|
||||
def os_grid_square_to_lat_lon(ref):
|
||||
def os_grid_square_to_lat_lon(ref: str) -> tuple[float, float]:
|
||||
"""Get a lat/lon point for the centre of an Ordnance Survey grid square"""
|
||||
|
||||
# Convert the letters into multipliers for the 500km squares and 100km squares
|
||||
@@ -209,7 +213,7 @@ def os_grid_square_to_lat_lon(ref):
|
||||
return lat, lon
|
||||
|
||||
|
||||
def irish_grid_square_to_lat_lon(ref):
|
||||
def irish_grid_square_to_lat_lon(ref: str) -> tuple[float, float]:
|
||||
"""Get a lat/lon point for the centre of an Irish Grid square."""
|
||||
|
||||
# Convert the letters into multipliers for the 100km squares
|
||||
@@ -237,7 +241,7 @@ def irish_grid_square_to_lat_lon(ref):
|
||||
return lat, lon
|
||||
|
||||
|
||||
def utm_grid_square_to_lat_lon(ref):
|
||||
def utm_grid_square_to_lat_lon(ref: str) -> tuple[float, float]:
|
||||
"""Get a lat/lon point for the centre of a UTM grid square (supports only squares WA & WV for the Channel Islands, nothing else implemented)"""
|
||||
|
||||
# Take the numeric parts of the grid square and multiply by 10000 to get metres from the corner of the letter-based grid square
|
||||
|
||||
Reference in New Issue
Block a user