Leaflet.Elevation icon indicating copy to clipboard operation
Leaflet.Elevation copied to clipboard

Error when displaying tracks with partially missing elevation data

Open electriclarry opened this issue 8 years ago • 1 comments

I got some GPX files here, where elevation data for a few single points is missing. This leads to a display error in the elevation chart where the lines indicating the elevation drop below 0 on the y-axis.

leaflet elevation bad-display (Example pic found here.)

In order to fix this error, I added a check that makes sure, that elevation data is available before adding a point to the chart to the _addGPXdata function. Tested it with version 0.0.2 and 0.0.4.

Update: Just realized, that @opoto created a fork that includes something very similar the below changes.

The new _addGPXdata function in leaflet.elevation-0.0.4-src.js around line 580 looks like this:

     /*
     * Parsing function for GPX data as used by https://github.com/mpetazzoni/leaflet-gpx
     */
    _addGPXdata: function(coords) {
        var opts = this.options;
        if (coords) {
            var data = this._data || [];
            var dist = this._dist || 0;
            var ele = this._maxElevation || 0;
            for (var i = 0; i < coords.length; i++)
	   {
                var s = coords[i];
                var e = coords[i ? i - 1 : 0];
                var newdist = opts.imperial ? s.distanceTo(e) * this.__mileFactor : s.distanceTo(e);
                dist = dist + Math.round(newdist / 1000 * 100000) / 100000;
                ele = ele < s.meta.ele ? s.meta.ele : ele;
		//only add points with valid elevation data
		if(s.meta.ele != null)
		{
	                data.push({
	                    dist: dist,
	                    altitude: opts.imperial ? s.meta.ele * this.__footFactor : s.meta.ele,
	                    x: s.lng,
	                    y: s.lat,
	                    latlng: s
	                });
		}

            }
            this._dist = dist;
            this._data = data;
            ele = opts.imperial ? ele * this.__footFactor : ele;
            this._maxElevation = ele;
        }
    },

electriclarry avatar Dec 02 '16 00:12 electriclarry

See also PR #84 that shows missing elevation values as gaps by using a d3 defined accessor function.

Ignoring data points with missing elevation as proposed here and in #60 has some drawbacks:

  • throws error when there is no elevation data at all (5)
  • diagram "zooms" (x axis cropped) to part with elevation when missing at start or end, which can be misleading (3, 4)
  • interpolates missing values, which can be misleading and not match reality (2)

Comparison:

master #60 (opoto) #84 (nrenner)
Plunker Plunker Plunker
image image image

Diagrams shown are variants of the same elevation profile with missing values at different positions:

  1. original
  2. middle (left of second segment)
  3. left
  4. right
  5. all missing

nrenner avatar Feb 01 '20 12:02 nrenner