Cast for two

Sunday, June 22, 2014

Parsing Strava GPX file with python minidom

GPX is more and more becoming the lingua franca for storing cycling rides. Basically it is a list of points, called track points, with satellite positions (latitude and longitude) decorated with extra information (elevation, heartrate, cadence, power or temperature). A track (<trk>), has one or more segments (<trkseg>) with a list of trackpoints (<trkpt>)

<trk>
    <name>Track Name</name>
    <trkseg>
      <trkpt lat="50.653007542714477" lon="5.558940963819623" />
Lots of track point...
      <trkpt lat="50.653007542714477" lon="5.558940963819623" />
    </trkseg>
</trk>
Sometimes elevation is also included for every trackpoint:
<trk>
    <name>Track Name</name>
    <trkseg>
      <trkpt lat="50.653007542714477" lon="5.558940963819623" >
      <ele>60.0</ele>
      </trkpt>
Lots of track point...
      <trkpt lat="50.653007542714477" lon="5.558940963819623" >
      <ele>60.0</ele>
      </trkpt>
   </trkseg>
</trk>
Those GPX files can be used as tracks that you can follow. You can copy those file to the New File directory on your Garmin and you can select them to follow. If
<ele> … </ele>
elements are included you will see how the height evolves in front of you.
If you download the GPX file from a ride you rode with a bike computer that registers cadence and heartrate, the file will look like this: You can see the whole file here: https://gist.github.com/cast42/727f48a0358fa67e60fb
The elevation element is part of the standard GPS specification as defined by the XML schema provided hre: http://www.topografix.com/gpx.asp The heartrate and cadence are stored using trackpoint extensions as specfied here: http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd
Here is a simple Python example to parse a Strava GPX file with extensions using minidom: It is required that cadence and heartrate are added to every trackpoint but temperature is optional.