tkrajina / srtm.py

Geo elevation data parser for "The Shuttle Radar Topography Mission" data
Apache License 2.0
240 stars 57 forks source link

NameError 'from_start_to_end' #53

Open belamu opened 2 years ago

belamu commented 2 years ago

When calling gpxelevations with the command gpxelevations osrm-Schkeuditz-FF.gpx -s -f osrm-Schkeuditz-FF-ele.gpx I get the following error traceback:

Traceback (most recent call last):
  File "/home/felix/.conda/envs/zipAlongTrack/bin/gpxelevations", line 43, in <module>
    update_gpx(gpx)
  File "/home/felix/.conda/envs/zipAlongTrack/bin/gpxelevations", line 38, in update_gpx
    geo_elevation_data.add_elevations(gpx, only_missing=not args.overwrite, smooth=args.approximate)
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/srtm/data.py", line 258, in add_elevations
    self._add_sampled_elevations(gpx)
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/srtm/data.py", line 301, in _add_sampled_elevations
    self._add_interval_elevations(gpx, min_interval_length=241)
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/srtm/data.py", line 293, in _add_interval_elevations
    gpx.add_missing_elevations()
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/gpxpy/gpx.py", line 2552, in add_missing_elevations
    self.add_missing_data(get_data_function=lambda point: point.elevation,
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/gpxpy/gpx.py", line 2539, in add_missing_data
    track.add_missing_data(get_data_function, add_missing_function)
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/gpxpy/gpx.py", line 1736, in add_missing_data
    track_segment.add_missing_data(get_data_function, add_missing_function)
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/gpxpy/gpx.py", line 1084, in add_missing_data
    distances_ratios = self._get_interval_distances_ratios(interval, start_point, track_point)
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/gpxpy/gpx.py", line 1112, in _get_interval_distances_ratios
    return [(distance / from_start_to_end) if from_start_to_end else 0
  File "/home/felix/.conda/envs/zipAlongTrack/lib/python3.10/site-packages/gpxpy/gpx.py", line 1112, in <listcomp>
    return [(distance / from_start_to_end) if from_start_to_end else 0
NameError: free variable 'from_start_to_end' referenced before assignment in enclosing scope

The gpx file is attached. The conda environment ist attached: conda-env-and-gpx-track.zip

belamu commented 2 years ago

Without -p it works but the result is malformed. Somehow the link that was copied from the original file was causing a "malformed gpx file". Seems to be unrelated.

belamu commented 2 years ago

Conclusion from truncating the file: the last two trackpoints have the same coordinates. That apparently causes the error. After removing one of them, the error is gone.

belamu commented 2 years ago

What confuses me: the error is caused by gpxpy code but when I try to parse the file attached in the first post with import gpxpy; gpxpy.parse("osrm-Schkeuditz-FF.gpx") I get an error for line 1: gpxpy.gpx.GPXXMLSyntaxException: Error parsing XML: syntax error: line 1, column 0