public
Created

Converts a directory of GPX files into a single KML file for import into Google Fusion Tables; includes some metadata based on the file name.

  • Download Gist
build.g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import groovy.xml.MarkupBuilder
 
new MarkupBuilder().kml(xmlns : 'http://www.opengis.net/kml/2.2') {
new File(args?.size() ? args[0] : '.').eachFileMatch(~/.*\.gpx/) { file ->
new XmlParser().parse(file).trk.each { trk ->
trk.trkseg.each { trkseg ->
def geo = ""
trkseg.trkpt.each { trkpt ->
geo += "${trkpt.'@lon'},${trkpt.'@lat'}\n"
}
if (geo) {
Placemark() {
name(file.getName().substring(0, 8))
LineString {
coordinates(geo);
}
ExtendedData {
Data(name : 'mode') {
value(file.getName() =~ /car/ ? 'drive' : 'hike')
}
Data(name : 'mode_color') {
value(file.getName() =~ /car/ ? 'FF000080' : 'FFFF00FF')
}
Data(name : 'multiday') {
value(file.getName().contains('-'))
}
}
}
}
}
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.