Skip to content

Instantly share code, notes, and snippets.

@scottpdawson
Created February 2, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottpdawson/2ad6a56e756f3bf028fed77f7152e741 to your computer and use it in GitHub Desktop.
Save scottpdawson/2ad6a56e756f3bf028fed77f7152e741 to your computer and use it in GitHub Desktop.
library(plotKML)
# Find GPX files using a pattern
files <- dir(pattern = "\\.gpx")
# Consolidate routes in one drata frame
index <- c()
latitude <- c()
longitude <- c()
for (i in 1:length(files)) {
route <- readGPX(files[i])
location <- route$tracks[[1]][[1]]
index <- c(index, rep(i, dim(location)[1]))
latitude <- c(latitude, location$lat)
longitude <- c(longitude, location$lon)
}
routes <- data.frame(cbind(index, latitude, longitude))
# Map the routes
ids <- unique(index)
plot(routes$longitude, routes$latitude, type="n", axes=FALSE, xlab="", ylab="", main="", asp=1)
for (i in 1:length(ids)) {
currRoute <- subset(routes, index==ids[i])
lines(currRoute$longitude, currRoute$latitude, col="#53116820")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment