Created
March 21, 2022 08:49
-
-
Save sulami/8ce31a928d9ae33910af383f1b97e4ee to your computer and use it in GitHub Desktop.
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
""" | |
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