Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# 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