Skip to content

Instantly share code, notes, and snippets.

@tomstorey
Last active January 10, 2022 19:16
Show Gist options
  • Save tomstorey/1d58499755a8765a34b3aaebb28cee7a to your computer and use it in GitHub Desktop.
Save tomstorey/1d58499755a8765a34b3aaebb28cee7a to your computer and use it in GitHub Desktop.
A simple Python3 script convert a list of POIs into a .ov2 file for loading e.g. onto a GPS satnav.
import struct
pois = [
('McLaren', 51.34314, -0.54252),
('Williams', 51.61672, -1.41096),
('Alpine', 51.92018, -1.38986),
('Haas', 52.06374, -1.31433),
('Mercedes', 52.02262, -1.1495),
('Aston Martin', 52.07592, -1.0296),
('Red Bull', 52.00815, -0.6929),
]
def main() -> None:
with open('pois.ov2', 'w+b') as file:
for poi in pois:
lat = poi[1]
lon = poi[2]
name = poi[0]
print(name)
print('lat', lat)
print('lon', lon)
lat = int(lat * 100000)
lon = int(lon * 100000)
lat_bytes = struct.pack('<l', lat)
lon_bytes = struct.pack('<l', lon)
name_bytes = bytes(name, encoding='utf8')
rec_len = struct.pack('<l', 1 + 4 + 4 + 4 + len(name) + 1)
rec = b'\x02' + rec_len + lon_bytes + lat_bytes + name_bytes + b'\x00'
# print(rec)
print()
file.write(rec)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment