Closed pramach closed 2 years ago
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.
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:
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.