GithubHelp home page GithubHelp logo

Route issues about gpxpy HOT 7 CLOSED

pramach avatar pramach commented on July 19, 2024
Route issues

from gpxpy.

Comments (7)

tkrajina avatar tkrajina commented on July 19, 2024

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.

pramach avatar pramach commented on July 19, 2024

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.

tkrajina avatar tkrajina commented on July 19, 2024

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.

pramach avatar pramach commented on July 19, 2024

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.

pramach avatar pramach commented on July 19, 2024

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.

tkrajina avatar tkrajina commented on July 19, 2024

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.

pramach avatar pramach commented on July 19, 2024

You are absolutely right.
Thanks a lot.
Sorry for disturbing and thanks for the great library.

from gpxpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.