mpetazzoni / leaflet-gpx

A GPX track plugin for Leaflet.js
http://mpetazzoni.github.io/leaflet-gpx
BSD 2-Clause "Simplified" License
550 stars 119 forks source link

get_elevation_gain #166

Closed nicopere closed 1 month ago

nicopere commented 1 month ago

Hello,

Related to that issue but not convinced by the end of it, hence I am proposing it anew.

In my understanding, get_elevation_gain() is basically computing the difference in registered altitude from point to point and adding only the positive ones. I can't understand why this relatively simple computation is giving such discrepancies on the very same gpx file (comparing with gpx.studio in my case).

One example (among others):

These tracks (bicycle in Brittany) have numerous short elevations so I suspect some sort of rounding error...

Currently using leaflet-gpx 1.7.0.

Nicolas

mpetazzoni commented 1 month ago

I think it's likely gpx.studio uses a smarter algorithm, with some slight smoothing over a few consecutive points, to mitigate the possible jitter in altitude measurements by GPS – especially on higher recording rates like 1Hz.

ChrilleSchappe commented 1 month ago

Computing the elevation gain is a equivalent with the "Coastline Paradox" - so there is no well defined right value!

mpetazzoni commented 1 month ago

@ChrilleSchappe Exactly. That's why I didn't bother implementing a more "clever" algorithm here – whatever I chose it would be wrong. So I provide the simplest "here's the sum of all positive deltas".

nicopere commented 1 month ago

Thanks guys for your clever answers. In the meanwhile I came across this where the problem is nicely explained for the unaware (like me ;-). Not sure though this is the same numerical issue as computing the length of the (fractal) coastline of, say, Brittany. What is strange: the discrepancy actually increases when replacing GPS measurements by gpx.studio's DEM (my GPS data were smoother!). I will look into the code of gpx.studio to get an idea of their algorithm (not documented otherwise). Cheers, Nicolas