我试图解析" Mission Planner"制作的gpx文件。由于某种原因,softwere生成一行的gpx文件,如下所示:
<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> (...)
当我尝试使用gpxpy(gpxpy-1.1.2)解析gpx文件时,跟踪点有一个空的时间属性,即使它们在gpx文件中有一个字段:
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]
显然,这会杀死所有的速度/持续时间计算。
想法?建议? +如果有人知道可以将gpx文件更改为可读的解析器/脚本,那就太好了。我试图写一个我自己的,但是\ n我插入某种方式搞砸了gpx文件,gpxpy根本无法解析它。
提前, 林。答案 0 :(得分:0)
您发布的GPX时间格式不正确。让我们使用具有正确时间格式的GPX文件进行尝试:
for
如前所述,使用gpxpy时的python代码为:
<?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>
输出:
trax = gpx.tracks[0]
seg = trax.segments[0]
pt = seg.points[1]
print(pt.time)