2
Gridlocator
Sebastian edited this page 2021-05-06 21:34:19 +00:00
Proof of concept build from https://en.wikipedia.org/wiki/Maidenhead_Locator_System
#!/usr/bin/env python3
FIELD_SYMBOLS = "ABCDEFGHIJKLMNOPQR"
SUBSQUARE_SYMBOLS = "abcdefghijklmnopqrstuvwx"
def main():
lat = 49.425711
long = 7.756694
locator = ""
false_east = long + 180.0
if false_east > 360:
false_east -= 360
long_field = int(false_east / 20)
long_rest = false_east - long_field * 20
locator += FIELD_SYMBOLS[long_field]
false_north = lat + 90.0
if false_north > 180:
false_north -= 180
lat_field = int(false_north / 10)
lat_rest = false_north - lat_field * 10
locator += FIELD_SYMBOLS[lat_field]
long_square = int(long_rest / 2)
long_rest -= long_square * 2
locator += str(long_square)
lat_square = int(lat_rest)
lat_rest -= lat_square
locator += str(lat_square)
long_subsquare = int(long_rest / 2 * 24)
locator += SUBSQUARE_SYMBOLS[long_subsquare]
lat_subsquare = int(lat_rest * 24)
locator += SUBSQUARE_SYMBOLS[lat_subsquare]
print(locator)
if __name__ == '__main__':
main()