How to bulk import gpx files to QGIS and merge into a single shapefile?

Use the ogr2ogr command line tool, that is distributed with QGIS. In Windows, open the OSGeo4W Shell from the QGIS program group and enter

for %p in (path_to_gpx_files\*ride*.gpx) do ogr2ogr path_for_output\gpx.shp -append %p track_points -fieldTypeToString DateTime

The equivalent command in a Unix bash shell would be

for file in path_to_gpx_files/*ride*.gpx; do ogr2ogr path_for_output/gpx.shp -append "${file}" track_points -fieldTypeToString DateTime; done

Make sure the output file (gpx.shp) doesn't exist before, then ogr2ogr will produce one single shapefile from all gpx files with "ride" in it. There are some notes about the ogr gpx driver at http://www.gdal.org/drv_gpx.html .


I know this is late but it might help others one day. There is a QGIS plugin called Batch GPS Importer which I explained more in this answer.

The latest version can filter out files using prefix and suffix text. Batch GPS Importer

I hope it helps.


You can import multiple GPX files at a time, although you will be prompted each and every file for the data layer you want. With over 400 traces that's not going to be fun.

You might want to look at ogr2ogr. This is the Swiss-Army-Knife of geo file conversions, it will convert almost any geoformat into any other compatible (vector/raster) geoformat.

an ogr2ogr call looks something like

ogr2ogr -f "ESRI Shapefile" example.shp example.gpx

You can call it programatically (e.g. from a python script, .bat file or bash script) to iterate over each ride*.gpx and convert it to a shapefile, for example.

Having said that, I couldn't get this to work on a couple of random gpx traces I downloaded from OpenStreetMap (ogrinfo didn't like them either, although QGIS loaded them). But I was able to open GPX files from another source.

Try running

ogrinfo example.gpx tracks

and see if you get any useful output. If you get a list of drivers, it's failed.

Your mileage may vary, it's worth a go.

Note that each shapefile will end up with its own directory, so if you don't want the hassle of writing code, you could try CSV instead.. see this blog post.

To do the merging, you could (using code) copy all the shapefiles into a single directory, then use the Vector > Data Management tools > Merge shapefiles into one

If you're fond of the hexbin style you illustrated, you might like to look at the MMQgis plugin. This allows hexagonal grids to be created, which you can then use to do the 'points in polygon' analysis.

Tags:

Gpx

Qgis