Route issues
pramach opened this issue · 7 comments
Hi
When working with Routes (e.g. from Garmin Basecamp), some important information are not accessible, e.g. like the trp:TransportationMode, the (planned) trp:DepartureTime or the trp:CalculationMode.
As per example:
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wptx1="http://www.garmin.com/xmlschemas/WaypointExtension/v1"
xmlns:gpxtrx="http://www.garmin.com/xmlschemas/GpxExtensions/v3"
xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"
xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3"
xmlns:trp="http://www.garmin.com/xmlschemas/TripExtensions/v1"
xmlns:adv="http://www.garmin.com/xmlschemas/AdventuresExtensions/v1"
xmlns:prs="http://www.garmin.com/xmlschemas/PressureExtension/v1"
xmlns:tmd="http://www.garmin.com/xmlschemas/TripMetaDataExtensions/v1"
xmlns:vptm="http://www.garmin.com/xmlschemas/ViaPointTransportationModeExtensions/v1"
xmlns:ctx="http://www.garmin.com/xmlschemas/CreationTimeExtension/v1"
xmlns:gpxacc="http://www.garmin.com/xmlschemas/AccelerationExtension/v1"
xmlns:gpxpx="http://www.garmin.com/xmlschemas/PowerExtension/v1"
xmlns:vidx1="http://www.garmin.com/xmlschemas/VideoExtension/v1"
creator="Garmin Desktop App" version="1.1"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1
http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd
http://www.garmin.com/xmlschemas/TrackPointExtension/v1
http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd
http://www.garmin.com/xmlschemas/GpxExtensions/v3
http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd
http://www.garmin.com/xmlschemas/ActivityExtension/v1
http://www8.garmin.com/xmlschemas/ActivityExtensionv1.xsd
http://www.garmin.com/xmlschemas/AdventuresExtensions/v1
http://www8.garmin.com/xmlschemas/AdventuresExtensionv1.xsd
http://www.garmin.com/xmlschemas/PressureExtension/v1
http://www.garmin.com/xmlschemas/PressureExtensionv1.xsd
http://www.garmin.com/xmlschemas/TripExtensions/v1
http://www.garmin.com/xmlschemas/TripExtensionsv1.xsd
http://www.garmin.com/xmlschemas/TripMetaDataExtensions/v1
http://www.garmin.com/xmlschemas/TripMetaDataExtensionsv1.xsd
http://www.garmin.com/xmlschemas/ViaPointTransportationModeExtensions/v1
http://www.garmin.com/xmlschemas/ViaPointTransportationModeExtensionsv1.xsd
http://www.garmin.com/xmlschemas/CreationTimeExtension/v1
http://www.garmin.com/xmlschemas/CreationTimeExtensionsv1.xsd
http://www.garmin.com/xmlschemas/AccelerationExtension/v1
http://www.garmin.com/xmlschemas/AccelerationExtensionv1.xsd
http://www.garmin.com/xmlschemas/PowerExtension/v1
http://www.garmin.com/xmlschemas/PowerExtensionv1.xsd
http://www.garmin.com/xmlschemas/VideoExtension/v1
http://www.garmin.com/xmlschemas/VideoExtensionv1.xsd">
<metadata>
<link href="http://www.garmin.com">
<text>Garmin International</text>
</link>
<time>2021-10-17T15:36:44Z</time>
<bounds maxlat="55.294610979035497" maxlon="7.596380710601807" minlat="47.545213010162115" minlon="-10.379269123077393"/>
</metadata>
...
<rte>
<name>GBR Hull - Liverpool - 307 km</name>
<extensions>
<gpxx:RouteExtension>
<gpxx:IsAutoNamed>false</gpxx:IsAutoNamed>
<gpxx:DisplayColor>Magenta</gpxx:DisplayColor>
</gpxx:RouteExtension>
<trp:Trip>
<trp:TransportationMode>Motorcycling</trp:TransportationMode>
</trp:Trip>
</extensions>
<rtept lat="53.743479866534472" lon="-0.273923529312015">
<time>2021-10-11T06:45:48Z</time>
<name>Rotterdam - Hull Ferry</name>
<sym>Ferry</sym>
<extensions>
<trp:ViaPoint>
<trp:DepartureTime>2021-10-06T23:00:39Z</trp:DepartureTime>
<trp:CalculationMode>Shorter Distance</trp:CalculationMode>
<trp:ElevationMode>Standard</trp:ElevationMode>
</trp:ViaPoint>
<gpxx:RoutePointExtension>
...
</gpxx:RoutePointExtension>
</extensions>
</rtept>
...
Using Gpxpy 1.4.2 installed via pip on python 3.9 on OSX BigSur
Is there any possibility to get this Trip information too ?
An full example file can be provided on request.
They are accessible, but they are not stored in default gpx fields because it's not part of the gpx standard. It's stored in extensions.
From the documentation:
gpx.py preserves GPX extensions. They are stored as ElementTree DOM objects.
gpx.routes[0].points[0].extension
...
Hi
Thanks for fast reply, but from the debugger:
point = {GPXRoutePoint}[rtept{Rotterdam - Hull Ferry}:53.74347986653447,-0.273923529312015@None]
...
extensions = {list: 2} [<Element '{http://www.garmin.com/xmlschemas/TripExtensions/v1}ViaPoint' at 0x7ff00cc63ef0>,
<Element '{http://www.garmin.com/xmlschemas/GpxExtensions/v3}RoutePointExtension' at 0x7ff0269ad090>]
0 = {Element: 3} <Element '{http://www.garmin.com/xmlschemas/TripExtensions/v1}ViaPoint' at 0x7ff00cc63ef0>
attrib = {dict: 0} {}
len = {int} 0
tag = {str} '{http://www.garmin.com/xmlschemas/TripExtensions/v1}ViaPoint'
tail = {str} '\n '
text = {str} '\n '
1 = {Element: 1207} <Element '{http://www.garmin.com/xmlschemas/GpxExtensions/v3}RoutePointExtension'
at 0x7ff0269ad090>
attrib = {dict: 0} {}
len = {int} 0
tag = {str} '{http://www.garmin.com/xmlschemas/GpxExtensions/v3}RoutePointExtension'
tail = {str} '\n '
text = {str} '\n '
len = {int} 2
geoid_height = {NoneType} None
....
name = (str) 'Rotterdam - Hull Ferry'
Not sure what's wrong, but here's a script I made for testing this:
g = gpxpy.parse(gpx) # gpx is your file
print(g.routes[0].points[0].extensions)
e = g.routes[0].points[0].extensions[0]
print(len(e))
node = e.getchildren()[1]
print(node.text)
The output is:
$ python q.py (v1.4.2)
[<Element {http://www.garmin.com/xmlschemas/TripExtensions/v1}ViaPoint at 0x105850bc0>, <Element {http://www.garmin.com/xmlschemas/GpxExtensions/v3}RoutePointExtension at 0x105850b80>]
3
Shorter Distance
$ python --version
Python 3.9.6
Thanks again
When running your test code, I get
[<Element '{http://www.garmin.com/xmlschemas/TripExtensions/v1}ViaPoint' at 0x7fa1e29f47c0>, <Element '{http://www.garmin.com/xmlschemas/GpxExtensions/v3}RoutePointExtension' at 0x7fa1c85bbe00>]
3
Traceback (most recent call last):
File "/main.py", line 131, in button_click_action
LoadTourData.load_tour_data(self)
File "/modules/load_tour_data.py", line 27, in load_tour_data
LoadTourData.load_tour_gpx(self, _selected_file)
File "/modules/load_tour_data.py", line 94, in load_tour_gpx
node = e.getchildren()[1]
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'`
I will do some further tests.
Route Test.TXT
That's my test file, just rename as GPX.
Looks like that none of the extensions has a children.
My code looks like:
` gpx_file = open('Route.Test.GPX', 'r')
gpx = gpxpy.parse(gpx_file)
if len(gpx.routes) == 0:
return None
print(gpx.version)
print(gpx.routes[0].points[0].extensions[0])
e = gpx.routes[0].points[0].extensions[0]
print(len(e))
for node in e.getchildren():
print(node.text)`
Output is:
1.1
<Element '{http://www.garmin.com/xmlschemas/TripExtensions/v1}ViaPoint' at 0x7fc2e54c14a0>
3
Traceback (most recent call last):
... File "/modules/load_tour_data.py", line 94, in load_tour_gpx
for node in e.getchildren():
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'
That error doesn't say that there are no children, just that Element
has no getchildren()
method. But note that the third line says 3
and that's len(e)
. So there are 3 children nodes, you just need to iterate through them (without getchildren
).
g = gpxpy.parse(gpx)
print(g.routes[0].points[0].extensions)
e = g.routes[0].points[0].extensions[0]
print(len(e))
for node in e:
print(node.text)
You are absolutely right.
Thanks a lot.
Sorry for disturbing and thanks for the great library.