A simple python script to merge GPX files within a target directory
Sometimes we would like to merge all the tracks, track segments and track points across different GPS Exchange Format (GPX) files. You may want to do this to consolidate GPS data generated by your GPS devices. Merging all your GPX files into a single one allows you to easily visualize the spatial information as one single map layer on a mapping software.
Note that this algorithm
- Preserves tracks. i.e. it does not merge different tracks under one
- Filters off track points which are not timestamped
- Orders track points chronologically under their track segment
Here's an example to run the script with all available options
python GPXMerge.py -i ./target -o target_merged.gpx -s 30
Longform | Shortform | Optional | Description |
---|---|---|---|
--input |
-i |
NO | Input directory path containing GPX files to be merged |
--output |
-o |
YES | Output path for the merged GPX file. Defaults to be ./[input directory]_merged.gpx |
--skip-interval |
-s |
YES | The interval in track segment at which the track points are taken. |
The reason to have a skip interval is to provide user control over the granularity of the merged data. Some GPS devices provide 1Hz data which may be too fine-grained for certain tasks.