9
我正在使用ggmap路由函數來計算和顯示使用D.C. Capital Bikeshare數據的數百條路線。我成功地通過一個小問題來解決這個問題,路線並不遵循道路,特別是彎曲的道路(見下面的屏幕截圖)。有沒有辦法讓我的代碼遍歷所有更詳細的路徑?如何獲取ggmap路徑數據以跟蹤道路路徑
library(tidyverse)
library(ggmap)
# Example dataset
feb_14 <- read.csv('https://raw.githubusercontent.com/smitty1788/Personal-Website/master/dl/CaBi_Feb_2017.csv', stringsAsFactors = FALSE)
# Subset first 300 rows, keep start and end Lat/Long strings
start<-c(feb_14[1:300, 14])
dest<-c(feb_14[1:300, 15])
# df of individual routes
routes <- tibble(
start,
dest)
# Function to calculate route
calculationroute <- function(startingpoint, stoppoint) {
route(from = startingpoint,
to = stoppoint,
mode = 'bicycling',
structure = "route")}
# Calculate route path for all individual trips
calculatedroutes <- mapply(calculationroute,
startingpoint = routes$start,
stoppoint = routes$dest,
SIMPLIFY = FALSE)
# Unlist and merge in single dataframe
do.call(rbind.data.frame, lapply(names(calculatedroutes), function(x) {
cbind.data.frame(route=x, calculatedroutes[[x]], stringsAsFactors=FALSE)
})) -> long_routes
# create map with routes
basicmap <- get_map(location = 'washingtondc',
zoom = 13,
maptype = "toner-background",
source = "google",
color = "bw")
basicmap <- ggmap(basicmap)
basicmap + geom_path(data=long_routes,
aes(x=lon, y=lat, group=route), color = "red",
size=1, alpha = .4, lineend = "round")
嘗試用'輸出= 「所有」''裏面路線( from = startingpoint, to = stoppoint, mode ='bicycling', structure =「route」,output =「all」)' – SymbolixAU
這會導致do.call(rbind ...引發此錯誤。函數(...,row.name s = NULL,check.rows = FALSE,check.names = TRUE,: 參數意味着不同的行數:1,0 –
Mapzen的Valhalla是一個web服務,可以提供從點到點的路由,包括路由的GeoJSON。 https://mapzen.com/blog/valhalla-intro/。 GeoJSONio軟件包顯然可以使用它。 –