Created
May 3, 2017 15:49
-
-
Save noqqe/5a780a2132b781a01bb0debed7765ab9 to your computer and use it in GitHub Desktop.
Visualize gpx tracks from a folder on a picture from google maps.
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
library(plotKML) | |
library(maps) | |
library(ggmap) | |
# Settings | |
activities_folder = "/Users/noqqe/Downloads/activities/" | |
center_map_on = "Plech" | |
zoom_depth = 9 # 1 - 21 | |
routes_color = "#FF000022" | |
# Get list of files | |
setwd(activities_folder) | |
files <- dir(pattern = "\\Ride.gpx") | |
# Initialize vectors | |
index <- c() | |
latitude <- c() | |
longitude <- c() | |
# Parse all files | |
for (i in 1:length(files)) { | |
route <- readGPX(files[i]) | |
location <- route$tracks[[1]][[1]] | |
# build up vectors of all coordinates | |
index <- c(index, rep(i, dim(location)[1])) | |
latitude <- c(latitude, location$lat) | |
longitude <- c(longitude, location$lon) | |
} | |
# Combine the three vectors into one data frame | |
routes <- data.frame(cbind(index, latitude, longitude)) | |
# Get a google map centered on target with appropriate zoom (1 - 21) | |
nbgmap <- qmap(location = center_map_on, zoom = zoom_depth) | |
# map routes data onto the google map | |
nbgmap + geom_path(aes(x = longitude, y = latitude, group = factor(index)), | |
colour = routes_color, data = routes, alpha=0.7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment