Created
October 3, 2024 11:40
-
-
Save Willem3141/0d92440a1c7ad7fed956c49cd950b6d4 to your computer and use it in GitHub Desktop.
Convert Trekarta .mtrack files to GPX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To generate Track_pb2.py: | |
# * get app/src/main/java/mobi/maptrek/io/Track.proto from the Trekarta repo | |
# * run `protoc --python_out=. Track.proto` | |
from datetime import datetime | |
import Track_pb2 | |
import sys | |
track = Track_pb2.Track() | |
with open(sys.argv[1], 'rb') as proto: | |
track.ParseFromString(proto.read()) | |
print('<gpx>') | |
print('<trk>') | |
print('<name>' + track.name + '</name>') | |
print('<trkseg>') | |
for point in track.points: | |
print('<trkpt lat="' + str(point.latitude_e6 / 1e6) + '" lon="' + str(point.longitude_e6 / 1e6) + '">') | |
print('<ele>' + str(point.altitude) + '</ele>') | |
print('<time>' + datetime.fromtimestamp(point.timestamp / 1000).isoformat() + '</time>') | |
print('<hdop>' + str(point.accuracy) + '</hdop>') | |
print('</trkpt>') | |
print('</trkseg>') | |
print('</trk>') | |
print('</gpx>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment