Reputation: 29
i'm trying to parse gpx file made by "Mission Planner". For some reason the softwere generates the gpx file of one line, which look like that:
<gpx creator="Mission Planner 1.3.48 build 1.1.6330.31130 ArduPlane V3.7.1 (22b5c415)" xmlns="http://www.topografix.com/GPX/1/1"><trk><trkseg><trkpt lat="31.7562743" lon="35.1812861"><ele>719.5</ele><time>2017-06-13T20:08:28+03:00</time><course>113.6</course><roll>-165.05</roll><pitch>1.74</pitch><mode /></trkpt><trkpt lat="31.7562703" lon="35.1812854"><ele>723.3</ele><time>2017-06-13T20:08:29+03:00</time><course>94.72</course><roll>-168.73</roll><pitch>8.55</pitch><mode /></trkpt><trkpt lat="31.7562648" lon="35.1812912"><ele>725.2</ele><time>2017-06-13T20:08:30+03:00</time><course>86.72</course><roll>-172.74</roll><pitch>4.67</pitch><mode /></trkpt> (...)
When i try to parse the gpx file with gpxpy (gpxpy-1.1.2), the track points have an empty time attributes, even though they do have have a field in the gpx file:
In [76]: a = gpx.tracks[0]
b = a.segments[0]
c = b.points[1]
d = [c.longitude, c.latitude, c.elevation, c.time]
d
Out[76]: [35.1812854, 31.7562703, 723.3, None]
obviously, that kills all the speed / duration calculations.
ideas? suggestions? + if anyone knows a parser / script that can change the gpx file to be readable, that would be nice. i'v tried to write one of my own, but the \n i insert somehow fuck up the gpx file, the gpxpy cannot parse it at all.
thx ahead, Forest.
Upvotes: 0
Views: 1751
Reputation: 408
The GPX time format you posted is not correct. Let's try it with a GPX file that has the correct time format:
<?xml version="1.0" encoding="UTF-8"?>
<gpx creator="StravaGPX" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
<metadata>
<time>2017-08-07T14:46:23Z</time>
</metadata>
<trk>
<name>Ride</name>
<type>1</type>
<trkseg>
<trkpt lat="33.6545510" lon="-117.8939470">
<ele>0.0</ele>
<time>2017-08-07T14:46:23Z</time>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:atemp>20</gpxtpx:atemp>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
As mentioned, the python code when using gpxpy is:
trax = gpx.tracks[0]
seg = trax.segments[0]
pt = seg.points[1]
print(pt.time)
Output:
2017-08-07 14:46:23+00:00
Upvotes: 1