Skip to content

Instantly share code, notes, and snippets.

@syncom
Last active November 21, 2017 17:57
Show Gist options
  • Save syncom/8b71344c8be66899928c3407966aa1bd to your computer and use it in GitHub Desktop.
Save syncom/8b71344c8be66899928c3407966aa1bd to your computer and use it in GitHub Desktop.
How to combine GPX files into one (for Strava)

How to combine GPX files into one (for Strava)

I use strava.com (https://strava.com) for my activity tracking. From time to time, I need to combine multiple activities into one for a better data management. Here is how I do it.

  1. First, in the page of the individual activity, download the data in GPX format by choosing the "Export GPX" menu. (GPX, or GPS exchange format, is an XML file format for storing coordinate data.) Order the downloaded activity data in time sequence. Suppose we now have three files, "1.gpx", "2.gpx", and "3.gpx" to join, where "1.gpx" is the earlist activity, and "3.gpx" is the latest activity.

  2. Open "*.gpx" with a text editor. Look for the XML tag ''. This is the parent of all the '' GPS coordinate samples (points). We need to extract all '' from all the GPX files to combine, and put them, in order, under the '' section. Do this by appending all the '' entries from "2.gpx" and "3.gpx" to that of "1.gpx", under the '' tag. Save the combined file as "combined.gpx".

  3. Delete the activities corresponding to "1/2/3.gpx" on Strava (otherwise it will report error "duplicated activity"). Upload the file "combined.gpx" manually to Strava. Edit the title and other meta information.

For the sake of completeness, this is the structure of Strava's GPX XML:

<gpx>
 <metadata>
 ...
 </metadata>
 <trk>
  <name>Activity Name</name>
  <trkseg>
   <trkpt ...>
   ...
   </trkpt>
   ...
   <trkpt ...>
   ...
   </trkpt>
  </trkseg>
 </trk>
</gpx>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment