Skip to content

Instantly share code, notes, and snippets.

@maptastik
Created December 10, 2018 02:31
Show Gist options
  • Save maptastik/7643fba7d3fd5def58b1ee6346598028 to your computer and use it in GitHub Desktop.
Save maptastik/7643fba7d3fd5def58b1ee6346598028 to your computer and use it in GitHub Desktop.

Add features from several GPX files in a directory to a GeoPackage

This is motivated by the fact that Runkeeper exports all your GPS data to individual GPX files. These GPX files contain 5 different tables:

  1. route_points
  2. routes
  3. track_points
  4. tracks
  5. waypoints

track_points and tracks seem to be the only tables that ever contain features and are the ones I'm most interested in. What would be really nice is to have all the individual GPX files merged into a single GeoPackage. We can do this with ogr2ogr

Setup

I downloaded all my data from Runkeeper. This comes in a zipped directory. I unzipped the directory and was left with a folder of each individual GPX file. There were also a couple CSV files with additional data, but dealing with those is not really important here.

In the directory with all my GPX files I created a new directory called output using the commmand line:

mkdir output

I then cut and pasted the first GPX file into the output directory. I opened up the OSGEO4W shell in my data directory and ran the following command:

ogr2ogr -f GPKG output/name_of_file.gpx output/rides.gpkg

This created a new Geopackage, output/rides.gpkg, with tables containing features from that one GPX file added to the output file. I have hundreds of these. They need to be added to output/rides.gpkg. So for that, I ran the following:

for %f (*.gpkg) do ogr2ogr -update -append -f GPKG %f output/rides.gpkg

It took a while, but in the end, all the GPX files were added to a single GeoPackage!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment