mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-03-15 12:24:29 +00:00
Bulk convert comments above classes/functions/methods into proper docstrings
This commit is contained in:
@@ -18,8 +18,10 @@ for idx in cq_zone_data.index:
|
||||
for idx in itu_zone_data.index:
|
||||
prepare(itu_zone_data.at[idx, 'geometry'])
|
||||
|
||||
# Finds out which CQ zone a lat/lon point is in.
|
||||
|
||||
def lat_lon_to_cq_zone(lat, lon):
|
||||
"""Finds out which CQ zone a lat/lon point is in."""
|
||||
|
||||
lon = ((lon + 180) % 360) - 180
|
||||
for index, row in cq_zone_data.iterrows():
|
||||
polygon = Polygon(row["geometry"])
|
||||
@@ -38,8 +40,9 @@ def lat_lon_to_cq_zone(lat, lon):
|
||||
return None
|
||||
|
||||
|
||||
# Finds out which ITU zone a lat/lon point is in.
|
||||
def lat_lon_to_itu_zone(lat, lon):
|
||||
"""Finds out which ITU zone a lat/lon point is in."""
|
||||
|
||||
lon = ((lon + 180) % 360) - 180
|
||||
for index, row in itu_zone_data.iterrows():
|
||||
polygon = Polygon(row["geometry"])
|
||||
@@ -58,9 +61,10 @@ def lat_lon_to_itu_zone(lat, lon):
|
||||
return 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.
|
||||
def lat_lon_for_grid_centre(grid):
|
||||
"""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."""
|
||||
|
||||
lat, lon, lat_cell_size, lon_cell_size = lat_lon_for_grid_sw_corner_plus_size(grid)
|
||||
if lat is not None and lon is not None and lat_cell_size is not None and lon_cell_size is not None:
|
||||
return [lat + lat_cell_size / 2.0, lon + lon_cell_size / 2.0]
|
||||
@@ -68,18 +72,21 @@ def lat_lon_for_grid_centre(grid):
|
||||
return 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.
|
||||
def lat_lon_for_grid_sw_corner(grid):
|
||||
"""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."""
|
||||
|
||||
lat, lon, lat_cell_size, lon_cell_size = lat_lon_for_grid_sw_corner_plus_size(grid)
|
||||
if lat is not None and lon is not None:
|
||||
return [lat, lon]
|
||||
else:
|
||||
return 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.
|
||||
|
||||
def lat_lon_for_grid_ne_corner(grid):
|
||||
"""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."""
|
||||
|
||||
lat, lon, lat_cell_size, lon_cell_size = lat_lon_for_grid_sw_corner_plus_size(grid)
|
||||
if lat is not None and lon is not None and lat_cell_size is not None and lon_cell_size is not None:
|
||||
return [lat + lat_cell_size, lon + lon_cell_size]
|
||||
@@ -87,11 +94,12 @@ def lat_lon_for_grid_ne_corner(grid):
|
||||
return 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.
|
||||
# The return type is always a tuple of size 4. The elements in it are None if the grid format is invalid.
|
||||
def lat_lon_for_grid_sw_corner_plus_size(grid):
|
||||
"""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.
|
||||
The return type is always a tuple of size 4. The elements in it are None if the grid format is invalid."""
|
||||
|
||||
# Make sure we are in upper case so our maths works. Case is arbitrary for Maidenhead references
|
||||
grid = grid.upper()
|
||||
|
||||
@@ -157,8 +165,9 @@ def lat_lon_for_grid_sw_corner_plus_size(grid):
|
||||
return lat, lon, lat_cell_size, lon_cell_size
|
||||
|
||||
|
||||
# Convert a Worked All Britain or Worked All Ireland reference to a lat/lon point.
|
||||
def wab_wai_square_to_lat_lon(ref):
|
||||
"""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,
|
||||
# or UTM grid systems to perform the conversion.
|
||||
if re.match(r"^[HNOST][ABCDEFGHJKLMNOPQRSTUVWXYZ][0-9]{2}$", ref):
|
||||
@@ -172,8 +181,9 @@ def wab_wai_square_to_lat_lon(ref):
|
||||
return None
|
||||
|
||||
|
||||
# Get a lat/lon point for the centre of an Ordnance Survey grid square
|
||||
def os_grid_square_to_lat_lon(ref):
|
||||
"""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
|
||||
offset_500km_multiplier = ord(ref[0]) - 65
|
||||
offset_100km_multiplier = ord(ref[1]) - 65
|
||||
@@ -202,8 +212,9 @@ def os_grid_square_to_lat_lon(ref):
|
||||
return lat, lon
|
||||
|
||||
|
||||
# Get a lat/lon point for the centre of an Irish Grid square.
|
||||
def irish_grid_square_to_lat_lon(ref):
|
||||
"""Get a lat/lon point for the centre of an Irish Grid square."""
|
||||
|
||||
# Convert the letters into multipliers for the 100km squares
|
||||
offset_100km_multiplier = ord(ref[0]) - 65
|
||||
|
||||
@@ -229,8 +240,9 @@ def irish_grid_square_to_lat_lon(ref):
|
||||
return lat, lon
|
||||
|
||||
|
||||
# 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)
|
||||
def utm_grid_square_to_lat_lon(ref):
|
||||
"""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
|
||||
easting = int(ref[2]) * 10000
|
||||
northing = int(ref[3]) * 10000
|
||||
|
||||
Reference in New Issue
Block a user