sgraaf / gpx

A python package that brings support for reading, writing and converting GPX files.
https://gpx.readthedocs.io/en/stable/
Other
11 stars 3 forks source link

AttributeError: 'Waypoint' object has no attribute 'lat'. #19

Closed larsks closed 2 weeks ago

larsks commented 2 weeks ago

This looks like a typo:

>>> wpt = gpx.Waypoint()
>>> wpt.latitude = 52.123
>>> wpt.longitude = 4.123
>>> g.waypoints.append(wpt)
>>> print(g.to_string())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../.venv/lib/python3.12/site-packages/gpx/gpx.py", line 300, in to_string
    gpx = self._build()
          ^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/gpx/gpx.py", line 234, in _build
    gpx.append(_waypoint._build())
               ^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.12/site-packages/gpx/waypoint.py", line 179, in _build
    waypoint.set("lat", str(self.lat))
                            ^^^^^^^^
AttributeError: 'Waypoint' object has no attribute 'lat'. Did you mean: 'sat'?
sgraaf commented 2 weeks ago

Hi, thank you for using gpx and reaching out! 😃

This it not a typo, at least not on our end. The actual property names for latitude and longitude are lat and lon, respectively. For reference, check out the API reference on the Waypoint object.

The code snippet below works as advertised:

>>> from gpx import GPX, Waypoint
>>> g = GPX()
>>> wpt = Waypoint()
>>> wpt.lat = 52.123
>>> wpt.lon = 4.123
>>> g.waypoints.append(wpt)
>>> print(g.to_string())
<gpx version="1.1" creator="PyGPX">
  <wpt lat="52.123" lon="4.123"/>
</gpx>
larsks commented 2 weeks ago

I think there's clearly a bug. That example was copy-and-pasted straight from the README. I did not just sit down and make up attribute names in my head.

larsks commented 2 weeks ago

I'm happy to open a new document bug if you would prefer.