-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotGPX.R
More file actions
29 lines (24 loc) · 819 Bytes
/
PlotGPX.R
File metadata and controls
29 lines (24 loc) · 819 Bytes
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
library(plotKML)
# GPX files downloaded from Garmin Connect, Strava etc..
# Tell R where your GPX files are
setwd("~/<where_you_keep_your_files>")
files <- dir(pattern = "\\.gpx")
# Consolidate routes in one data 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="#00000020")
}