Trail Notes

How to Merge GPX Files

Several files in, one file out. The only real decision is whether the gap between two recordings stays a gap.

Edit Reading time: 6 minutes Updated By the GPX Analyzer project

How Do You Merge GPX Files?

Load them into a GPX merger and download one file. In the free GPX Merger, drop two or more .gpx files onto the page, choose whether the tracks should become one track or stay separate, and click Download Merged GPX. The files are put in order of start time, and every point is copied unchanged with its timestamp, elevation, and sensor data. The one decision that matters is how the tracks are joined: as one track with a segment for each recording, which keeps the gap between two days as a gap; as one continuous line, which draws straight across it; or as separate tracks in a single file. A GPX file is plain text, so two files can also be merged by hand in a text editor, or with GPSBabel on the command line.

Why Merge at All?

Two sandy desert trails coming in from different directions and joining into a single trail that runs on toward distant mountains

  • A trip recorded as several files. One file per day, and you want the whole route as one line with one total.
  • A recording that was interrupted. The device restarted, the battery was changed, or the app was closed, and the ride came out in two or three pieces.
  • A track and its waypoints in different files. The route from one source and the water, camps, and fuel stops from another.
  • Several trails for one device. A weekend's worth of options loaded as a single file.

Tracks and Segments: The Choice That Matters

A GPX file holds tracks, and each track holds one or more segments. A segment is an unbroken run of points; a new segment means the recording stopped and started again. How the merged file uses the two decides what apps make of it.

ResultWhat is in the fileChoose it when
One track, a segment per recordingA single named track. The place one recording ended and the next began stays a gapThe pieces are one journey: a multi-day trip, a ride recorded in parts. Totals match the sum of the originals
One continuous lineA single track with a single segment. A straight line joins the end of each recording to the start of the nextA device, app, or site shows only the first segment or splits an activity at each one. The straight lines count toward the distance
Separate tracksEvery track as it was, with its own name and descriptionThe tracks are different things: three trail options, four stages, a set to load on a device

If you are unsure, use one track with a segment per recording. It is the reading most apps handle well, and nothing is invented: no line is drawn where you did not go. How to Split, Trim, and Cut GPX Tracks covers the same choice from the other direction.

Method 1: In Your Browser

  1. Open the GPX Merger and drop your files on it, or click to select several at once. Each is listed with its tracks, points, start time, and distance, and drawn on a map in its own color.
  2. Choose how to merge: One Track, One Continuous Line, or Keep Tracks Separate.
  3. Check the order. Tracks are sorted by start time. If a file has no timestamps, or you want your own order, untick Order by start time and move the files with the arrows.
  4. Read the joins. The Result lists the distance and the time between each pair of recordings, and flags any that overlap.
  5. Download. Your original files are never modified, and nothing is uploaded.

The merger copies each point out of its file as text, so timestamps, decimals, heart rate, and any other data a point carries come out exactly as they went in. Waypoints and routes are merged too, and a waypoint that appears in more than one file with the same name and position is written once.

Method 2: By Hand in a Text Editor

For two small files this takes a minute. Open both in a plain text editor. In the second file, copy everything from its first <trk> to its last </trk>. Paste it into the first file just above the closing </gpx>.

<gpx version="1.1" creator="..." xmlns="http://www.topografix.com/GPX/1/1">
  <wpt lat="..." lon="..."> ... </wpt>      waypoints first
  <trk> ... day one ... </trk>
  <trk> ... day two ... </trk>            pasted here
</gpx>

Four things go wrong when merging by hand:

  • Two headers. The merged file needs one <gpx> opening tag and one </gpx> at the very end. Copying a whole file into another leaves two of each.
  • The wrong order. GPX wants waypoints first, then routes, then tracks. Waypoints pasted after a track make the file invalid.
  • Missing extension declarations. If the pasted points carry heart rate or other extension data, the short prefix on those tags, such as gpxtpx: or ns3:, has to be declared in the opening <gpx> tag. Copy the matching xmlns: attribute from the second file's header.
  • The same prefix meaning two things. Files from different exports can use ns3: for different kinds of data. Declaring it once breaks one of them. This is the case a merging tool handles for you.

Check the result in the GPX Validator before loading it anywhere. If the file will not open, How to Fix a Corrupted GPX File explains the errors.

Method 3: GPSBabel

For a folder of files, or a job you repeat, the open-source GPSBabel utility merges on the command line. Give it each input with its own -f:

gpsbabel -i gpx -f day1.gpx -f day2.gpx -f day3.gpx -o gpx -F trip.gpx

The tracks arrive as separate tracks in the order given. GPSBabel rewrites the file as it goes, so check afterward that the sensor data you care about is still there.

Before You Merge

  • Trim the junk first. The drive to the trailhead and the hour parked at lunch are easier to remove from the single files. Use the GPX Editor.
  • Watch for overlapping recordings. Two devices on the same ride produce two tracks of the same hours. Merged into one continuous line their timestamps run backward, which some apps reject. Keep them as segments or as separate tracks, or merge only one.
  • Mind the size. Five days at one point a second is a large file. If the result has more points than a device accepts, see How to Reduce GPX File Size.

Frequently Asked Questions

How do I combine GPX tracks into one continuous track?

Choose One Continuous Line in the merger. Every point goes into a single segment, in time order. Expect a straight line wherever one recording ended and the next began, and expect the distance to include it.

Does merging lose any data?

Not from the points. In the GPX Merger every point keeps its coordinates, elevation, time, and extension data. What is not carried over is file-level detail such as author and links, and, when tracks are joined into one, the original tracks' own names and descriptions.

How many files can I merge?

Up to 50 in the merger, 25 MB each and 60 MB together. You can also merge the tracks inside a single file.

Why does my merged track have a straight line across the map?

Either the file was merged as one continuous line, or the app you are viewing it in connects segments on its own. Merge as one track with a segment per recording, and check the file in the GPX Analyzer, which never draws across a gap.

Can I merge a route with a track?

They can share a file, and the merger keeps both. They are not joined into one line, because a route and a track are different things: one is a plan and the other a record. To turn a track into a route, use GPX Track to Route.

Does the order of the files matter?

For tracks with timestamps, no: they are sorted by start time. For tracks without, and for waypoints and routes, the order of the list is the order in the file.

Related Tools and Guides