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

Elevation gain/loss computation should ignore points with no elevation data (instead of assuming 0) #110

Closed andre92160 closed 3 years ago

andre92160 commented 3 years ago

Hello, I use leaflet-gpx and I have an issue: get_distance() doesn't give allways the good result:

I join a zipped folder with my script and some gpx to visualize the issue.

get_distance() gives the good distance (12 km) for the track SSS.gpx. I changed a bit this track and added some waypoints, which gives SSS_wpt.gpx. get_distance() gives now 18 km, which is wrong.

I loaded SSS_wpt.gpx in Visorando or VisuGpx: they both give the good result: 12 km.

I tried to remove all the waypoints, which gives SSS_wpt2.gpx but get_distance() gives allways a bad result: 18 km.

In fact elevation_gain() and elevation_loss() give also the good results for SSS.gpx and bad results with SSS_wpt.gpx.

NB: To visualize a track (for example SSS.gpx), you need to type: carte.html?track=gpx/SSS.gpx

Regards, André

folder_issue.zip

andre92160 commented 3 years ago

The problem is related with the elements ele of the gpx file as it can be seen from the two join gpx files test.zip It's the same track in the two files. The computed distance (260 m) is correct for test.gpx but not in test2.gpx (11 km). The difference is that in test2.gpx I've deleted some ele elements (which give the elevation of the point).

It seems the elevation is estimated per default to zero when ele is not present; so there could be a big elevation gain (or loss). And this elevation difference is used to compute the distance.

Elevation should be ignored when ele is not present and computed only between 2 points having an ele element. I suppose it's what Visorando and other applications do, as they give the good result.

Thanks for your work, André

mpetazzoni commented 3 years ago

It's difficult to compute a good and accurate distance from a GPX without a much more complex algorithm. I can look into the elevation gain/loss thing though.