Skip to content

Instantly share code, notes, and snippets.

@c089
Created June 24, 2012 14:08
Show Gist options
  • Save c089/2983349 to your computer and use it in GitHub Desktop.
Save c089/2983349 to your computer and use it in GitHub Desktop.
GPX Merger
// Will write the tracks of all .gpx files in the current working directory
// to /tmp/output.gpx. I used this to bulk import my cardio trainer .gpx files
// into endomondo, because they don't offer bulk import.
// You will have to ensure tha you don't exceed the 10MB limit yourself (I created
// three batches of ~4MB each which seemed to import fine, although I triggered an
// 500 on their side after the import succeeded...
class GpxMerge {
public static void main(String[] args) {
String workingDir = System.getProperty('user.dir')
XmlParser parser = new XmlParser()
def outputRoot = null // will use root of first file
new File(workingDir).eachFileMatch(~/.*\.gpx/) { File input ->
def inputRoot = parser.parse(input)
if (!outputRoot) {
outputRoot = inputRoot
}
else {
outputRoot.append(inputRoot.trk)
}
}
File outputFile = new File("/tmp/output.gpx")
new XmlNodePrinter(new PrintWriter(outputFile), '').print(outputRoot)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment