[SOLVED] [GPX] Command-line app to tally elevation?

Hello,

I’m looking for a Windows command-line application that takes a GPX file, and computes the total elevation for all the tracks it contains.

Bonus: Slice the track at 50km when the elevation hits 1.000m.

For some reason, GpxPy’s gpxinfo returns nothing when I feed it a GPX file that holds infos for all track points:

pip install gpx-cmd-tools
C:\Python38-32\Lib\site-packages\gpxtools\gpxinfo.py myfile.gpx

Thank you.

Clearly, I’m doing something wrong: For the same file, www.maplorer.com says +3011m, ridewithgps.com says +3637 m, and my script says… 10,510m :stuck_out_tongue:

import gpxpy
import gpxpy.gpx
import array

gpx_file = open('myfile.gpx', 'r',encoding='utf-8')

gpx = gpxpy.parse(gpx_file)

arr = []

for track in gpx.tracks:
	if not track.name:
		track.name = "Empty name"
	print("Track ",track.name)
	for segment in track.segments:
		EL=0
		#put all trkpt in array
		for point in segment.points:
			arr.append(int(point.elevation))
		for idx, x in enumerate(arr[1:]):
			#Only include positive elevation
			if x >= arr[idx-1]:
				elevation = x - arr[idx-1]
				EL += elevation
		print(f"Total ascent: {EL}")

Is anything on this page helpful?
https://www.gpsvisualizer.com/tutorials/elevation_gain.html

E.g. they talk about applying thresholds to reduce spurious elevation gains that are really just “noise”. I don’t think you are doing that in your script, but maybe the tools you are comparing to are?

Thanks much.

GPSVisualizer certainly does apply tresholds, and I guess RideWithGPS does too since the figures are very close, and much closer to raw computation.

Pre-running the following command 1) on a file that had its altitude data replaced with those from DEM, and 2) ignoring track points that are no higher than 5m from the previous point… I get a positive elevation of 5,162m so closer to what GPSV and RwGPS give (~+3k against a raw elevation of +10k).

For those interested, here’s my updated script:

import gpxpy
import gpxpy.gpx
import array

#only include track points that are at least 5m higher than the previous point
EL_THRESHOLD = 5
INPUTFILE = 'input.gpx'

gpx_file = open(INPUTFILE, 'r',encoding='utf-8')
gpx = gpxpy.parse(gpx_file)

arr = []

for track in gpx.tracks:
	if not track.name:
		track.name = "Empty name"
	print("Track ",track.name)

	for segment in track.segments:
		EL=0

		#put all trkpt in array
		for point in segment.points:
			arr.append(int(point.elevation))
		print("Number of track points: ", len(arr))

		for idx, x in enumerate(arr[1:]):
			elevation = x - arr[idx-1]
			if elevation >= EL_THRESHOLD:
				EL += elevation
		print(f"Total ascent: {EL}")