tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
987 stars 223 forks source link

Write speed in to_xml() #69

Closed FlorianWilhelm closed 7 years ago

FlorianWilhelm commented 7 years ago

When I read in a gpx file, add speeds for the first and last point of each segment, run add_missing_speeds() the speed for each point gets set. Now running to_xml() generates an XML file which lacks the speed information although speed is an optional field in the GPX format. Was this forgotten in the to_xml() function?

tkrajina commented 7 years ago

speed is an optional field in GPX 1.0, but it isn't in 1.1 (you can run make analyze-xsd to retrieve xsd files and pretty-print the xsd structure).

to_xml() will try to write the GPX with the original version. But you can force 1.0 with .to_xml(version='1.0'). Do you still have this bug with 1.0?

FlorianWilhelm commented 7 years ago

Okay, sorry, this is really strange that speed is no longer defined in version 1.1. What if you have a speed sensor coupled to your GPS sensor and want to save this more accurate data somehow? Is it possible to have speed somehow as a valid extension? There is an tag defined, right?

tkrajina commented 7 years ago

I know, and a lot of the complexity in gpxpy 1.0+ comes because of the gpx 1.0/1.1 inconsistencies.

Anyway, you can always use GPXTrackPoint.extensions. The current extensions API is not ideal, because extensions in gpxpy is a dictionary, but in GPX it can contain any XML (and maps aren't a perfect one-to-one representations to any XML chunk). But for simple values, like your speed, it will work.

FlorianWilhelm commented 7 years ago

okay, so I guess this issue can be closed now since gpx 1.1 lacks the attribute speed and the workaround is to save it as an extension. Still, I am quite unsatisfied and hopefully gpx 1.2 will reintroduce speed as optional attribute directly in the standard. I heard some people argue that speed is not really necessary since it is just the derivation of place by time but this is not so accurate actually for gps. Nowadays it is no problem to connect your bikecycle's tachometer and save the actual way more accurate speed to each gps measurement. With the help of the famous Kalman filter it is then even possible to get even more precise information about the current state using two different sensors that give readings for the current speed.