Skip to content

Instantly share code, notes, and snippets.

@sulami
Created March 21, 2022 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sulami/8ce31a928d9ae33910af383f1b97e4ee to your computer and use it in GitHub Desktop.
Save sulami/8ce31a928d9ae33910af383f1b97e4ee to your computer and use it in GitHub Desktop.
"""
Fixes erroneous elevations in GPX tracks.
"""
import sys
import gpxpy
import gpxpy.gpx
file_name = sys.argv[1]
with open(file_name, 'r') as fp:
gpx = gpxpy.parse(fp)
for track in gpx.tracks:
track.extensions = []
for segment in track.segments:
last_elevation = segment.points[0].elevation
for point in segment.points:
diff = abs(point.elevation - last_elevation)
if diff > 100:
print('Fixing elevation of', point.elevation, 'to', last_elevation)
point.elevation = last_elevation
last_elevation = point.elevation
# Gaia's XML extensions trip up the import.
with open(file_name, 'w') as fp:
fp.write(gpx.to_xml())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment