Comments (7)
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
...
from gpxpy.
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'
from gpxpy.
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
from gpxpy.
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.
from gpxpy.
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'
from gpxpy.
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)
from gpxpy.
You are absolutely right.
Thanks a lot.
Sorry for disturbing and thanks for the great library.
from gpxpy.
Related Issues (20)
- metadata error in bounds HOT 1
- Force stdlib etree instead of lxml? HOT 1
- Uphill Downhill are not accurate HOT 2
- GPX parsing not working with extension HOT 2
- NameError: free variable 'from_start_to_end' referenced before assignment in enclosing scope HOT 1
- Setup.py method is being deprecated in python package
- Confusion!
- Wrong distance? 10.4 km instead of 7.6 km HOT 1
- Save nsmap of GPX in GPXTrack, GPXTrackSegment and GPXTrackPoint
- GPX track all messed up HOT 1
- Tag a release to ship improvements since 1.5.0 HOT 1
- TypeError in gpxfield since 1.6.0 release HOT 1
- Changes Backported To 1.5.0 HOT 2
- Typo in __repr__ of SimpleTZ HOT 1
- [newbie] Wrong return type on GPXTrackSegment.get_duration() HOT 1
- create CI testing scripts HOT 1
- feature request: include distance_from_start in NearestLocationsData class HOT 1
- Is Header malformed
- Check for GPX root node on parse HOT 1
- Custom attributes in `to_xml` not escaped properly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gpxpy.