从A点开始到B点5分钟后插值位置
Interpolate position 5 minutes after starting from point A to B
下面是一个使用 osrm
包在 R 中查找从 'One World Trade Center, NYC' 到 'Madison Square Park, NYC' 的路线、旅行时间和旅行距离的示例。(我从 Road Routing in R 学到的).这里的行车时间是10.37分钟。
问。如何在 5 分钟后插值并找到位置。
library(sf)
library(dplyr)
library(tidygeocoder)
library(osrm)
# 1. One World Trade Center, NYC
# 2. Madison Square Park, NYC
adresses <- c("285 Fulton St, New York, NY 10007",
"11 Madison Ave, New York, NY 10010")
# geocode the two addresses & transform to {sf} data structure
data <- tidygeocoder::geo(adresses, method = "osm") %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
osroute <- osrm::osrmRoute(loc = data,
returnclass = "sf")
summary(osroute)
library(leaflet)
leaflet(data = data) %>%
addProviderTiles("CartoDB.Positron") %>%
addMarkers(label = ~address) %>%
addPolylines(data = osroute,
label = "OSRM engine",
color = "red")
使用osrm::osrmIsochrone()
函数求五分钟行程多边形,然后求路线与多边形相交的点。
它看起来像是在 Hudson 和 Varick 之间的克拉克森街。
library(sf)
library(dplyr)
library(tidygeocoder)
library(osrm)
# 1. One World Trade Center, NYC
# 2. Madison Square Park, NYC
adresses <- c("285 Fulton St, New York, NY 10007",
"11 Madison Ave, New York, NY 10010")
# geocode the two addresses & transform to {sf} data structure
data <- tidygeocoder::geo(adresses, method = "osm") %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
# get route from 285 fulton to 11 madison
osroute <- osrmRoute(src = data[1,], dst = data[2,], returnclass = 'sf')
# five minute isochrone from 285 fulton
five_min_isochrone <- osrmIsochrone(data[1,], breaks = 5, returnclass = 'sf')
# isochrone has to be cast to MULTILINESTRING to find intersection as a point
intersection <- five_min_isochrone %>%
st_cast('MULTILINESTRING') %>%
st_intersection(osroute)
library(leaflet)
leaflet(data = data) %>%
addProviderTiles("CartoDB.Positron") %>%
addMarkers(label = ~address) %>%
addPolylines(data = osroute,
label = "OSRM engine",
color = "red") %>%
addPolygons(data = five_min_isochrone) %>%
addMarkers(data = intersection,
label = '5 minute distance')
下面是一个使用 osrm
包在 R 中查找从 'One World Trade Center, NYC' 到 'Madison Square Park, NYC' 的路线、旅行时间和旅行距离的示例。(我从 Road Routing in R 学到的).这里的行车时间是10.37分钟。
问。如何在 5 分钟后插值并找到位置。
library(sf)
library(dplyr)
library(tidygeocoder)
library(osrm)
# 1. One World Trade Center, NYC
# 2. Madison Square Park, NYC
adresses <- c("285 Fulton St, New York, NY 10007",
"11 Madison Ave, New York, NY 10010")
# geocode the two addresses & transform to {sf} data structure
data <- tidygeocoder::geo(adresses, method = "osm") %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
osroute <- osrm::osrmRoute(loc = data,
returnclass = "sf")
summary(osroute)
library(leaflet)
leaflet(data = data) %>%
addProviderTiles("CartoDB.Positron") %>%
addMarkers(label = ~address) %>%
addPolylines(data = osroute,
label = "OSRM engine",
color = "red")
使用osrm::osrmIsochrone()
函数求五分钟行程多边形,然后求路线与多边形相交的点。
它看起来像是在 Hudson 和 Varick 之间的克拉克森街。
library(sf)
library(dplyr)
library(tidygeocoder)
library(osrm)
# 1. One World Trade Center, NYC
# 2. Madison Square Park, NYC
adresses <- c("285 Fulton St, New York, NY 10007",
"11 Madison Ave, New York, NY 10010")
# geocode the two addresses & transform to {sf} data structure
data <- tidygeocoder::geo(adresses, method = "osm") %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
# get route from 285 fulton to 11 madison
osroute <- osrmRoute(src = data[1,], dst = data[2,], returnclass = 'sf')
# five minute isochrone from 285 fulton
five_min_isochrone <- osrmIsochrone(data[1,], breaks = 5, returnclass = 'sf')
# isochrone has to be cast to MULTILINESTRING to find intersection as a point
intersection <- five_min_isochrone %>%
st_cast('MULTILINESTRING') %>%
st_intersection(osroute)
library(leaflet)
leaflet(data = data) %>%
addProviderTiles("CartoDB.Positron") %>%
addMarkers(label = ~address) %>%
addPolylines(data = osroute,
label = "OSRM engine",
color = "red") %>%
addPolygons(data = five_min_isochrone) %>%
addMarkers(data = intersection,
label = '5 minute distance')