Created
November 15, 2013 06:03
-
-
Save ejain/7479848 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('-')) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment