Python GPXPy speed data is missing
Loois1995 opened this issue · 3 comments
I am trying to get data from a GPX file like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="Kurviger.de" version="1.1" xmlns:gh="https://kurviger.de/public/schema/gpx/1.1">
<metadata>
<link href="https://">
<text>text</text>
</link>
<time>2021-12-21T14:53:19Z</time>
</metadata>
<trk>
<name>data.gpx</name>
<trkseg>
<trkpt lat="55.015102" lon="15.275796"><speed>55.987000</speed><time>2021-12-21T14:53:19Z</time><desc>1</desc></trkpt>
<trkpt lat="55.015224" lon="15.275687"><speed>55.987000</speed><time>2021-12-21T14:53:19Z</time><desc>1</desc></trkpt>
<trkpt lat="55.015358" lon="15.275580"><speed>55.987000</speed><time>2021-12-21T14:53:19Z</time><desc>1</desc></trkpt>
<trkpt lat="55.015495" lon="15.275477"><speed>55.987000</speed><time>2021-12-21T14:53:19Z</time><desc>1</desc></trkpt>
</trkseg>
</trk>
</gpx>
As you can see the speed information is given in the gpx file.
To read the data (longitude, latitude, elevation and speed) if seperated the track points like this:
gpx_file = open("route.gpx", "r")
gpx = gpxpy.parse(gpx_file)
data = gpx.tracks[0].segments[0].points
The longitude, latitude, elevation are extracted correctly the speed information isnt. If i try to print it (for the first point for example but the issue can be found at all points):
print(data[0].speed)
None
will be printed.
Can anybody help?
This should be solved by invoking parse
with a version
argument set to "1.0"
.
gpx_file = open("route.gpx", "r")
gpx = gpxpy.parse(gpx_file,version="1.0")
data = gpx.tracks[0].segments[0].points
# for example
for pt in data:
print(pt.speed)
This should be solved by invoking
parse
with aversion
argument set to"1.0"
.gpx_file = open("route.gpx", "r") gpx = gpxpy.parse(gpx_file,version="1.0") data = gpx.tracks[0].segments[0].points # for example for pt in data: print(pt.speed)
Yes this works. Thank you
Exactly.
From the README says:
For example, GPX 1.0 specified a speed attribute for every track point, but that was removed in GPX 1.1. If you parse GPX 1.0 and serialize back with gpx.to_xml() everything will work fine. But if you have a GPX 1.1 object, changes in the speed attribute will be lost after gpx.to_xml(). If you want to force using 1.0, you can gpx.to_xml(version="1.0"). Another possibility is to use extensions to save the speed in GPX 1.1.