Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a whole bunch of GPX files that I need to load into qgis and loading them one at a time using the GPS plugin is a bit painful. It will not allow one to select multiple files -- is there another way?

I did find this: Automating batch load of multiple GPX files into PostGIS but I need to figure out a lot more about postgis and gdal before trying that approach.

BTW I am using Mac version of QGIS -- just realised that this may be OS related

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Using Add Vector layer you can select multiple files by mouseclicking (at least on Windows), but you have to select for each GPX file what layer you want to add (most probably "tracks").

I guess this could be a good idea for a selfmade plugin, but I have not yet found the time to do that.

share|improve this answer
    
Ah! yes that works. The small catch is that you still need to select between track, waypoint, route, etc. with no indication of which gpx file you are referring to. Still beats going throught all the menus for each file. Also the file names are not reflected in the layer names. –  Russell Fulton Apr 6 '13 at 7:14
    
True, but you still get the filename as tooltip if you hover over with the mouse. I use that step only temporarily to add the geometries with copy and paste to my spatialite db. –  Andre Joost Apr 6 '13 at 7:59
add comment

I know that this has already been answered .. but I couldn't use the answer and kept coming back to this question on every google search I did. So I made a mini python program to make a bunch of .gpx files into one big file. Thus getting around the problem of loading multiple files. Hopefully this helps someone else.

Once you have your new gpx file load it through the GPXtools plugin.

Copy and paste into a PLAIN text file. This code assumes you have python (2.x) installed. Made for Ubuntu, but should work on Windows or Mac

#!/usr/bin/env python
"""
INSTRUCTIONS:
    1. Open a terminal (Linux, Mac) or command prompt (Windows).
    2. Type in "python <the name of this file> <the name of the folder containing
        you gpx files to combine>" 'Naturally withought quotes ;|'
    3. Visit said folder and look for a file called "CombinedGPX.gpx"
    4. Post if this doesn't work and/or maybe update this program so it does.
"""
# This program will combind all gpx files in a given location into one large file.
# NOTE: the metadata of the first file (this is arbitrary and decided by the OS)
# is kept, all other metadata is forgotten.

# Possible additions .. make program execute from drag and drop **later
#chmod +x <filename>
#!/usr/bin/env bash
#python <source_file.py> "$1"

import sys
import glob

# Get location from user
# This input should be in the form: $ python <gpxcombiner.py> <GPXFolder/>
# NOTE: the second argument MUST end with a "/"

gpxdir = sys.argv[1]
gpxfiles = glob.glob(gpxdir + "*.gpx")
bigGPX = gpxdir + 'CombindedGPX.gpx'

# Remove precombined GPX file so you don't get an infintely expanding file
try:
    gpxfiles.remove(bigGPX)
except ValueError: # Ignore this if file doesn't exist
    pass

print 
print
print "Directory contains: " + str(len(gpxfiles)) + " .gpx files to be amalgamated."

def split_file(filename, body_start_split='</metadata>', body_end_split='</gpx>'):
    data = filename.read()
    start_body = data.find(body_start_split) + len(body_start_split)
    end_body = data.find(body_end_split)
    header = data[:start_body]
    body = data[start_body:end_body]
    footer = data[end_body:]
    return header, body, footer

first_file, gpxfiles = gpxfiles[0], gpxfiles[1:]
with open(first_file, 'r') as infile:
    header, body, footer = split_file(infile)

    with open(bigGPX, 'w') as outfile:
        outfile.write(header)
        outfile.write(body)

        for fname in gpxfiles:
            with open(fname, 'r') as infile:
                header, body, null = split_file(infile)

            outfile.write(body)
        outfile.write(footer)

print bigGPX + " created, contains combined data."
print
print
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.