r - 从 A 点开始到 B 点后 5 分钟内插位置
问题描述
下面是使用 R 中的包查找从“纽约世贸中心一号”到“纽约麦迪逊广场公园”的路线、旅行时间和旅行距离的示例osrm
。(我从 R 中的 Road Routing中学到了它)。这里的旅行时间是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()
函数找到五分钟行驶距离多边形,然后找到路线与多边形相交的点。
它看起来像在哈德逊和瓦里克之间的克拉克森街。
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')
推荐阅读
- macos - OpenMP CMake 苹果
- django - 当我有“卷”时,Docker Compose 不起作用,否则它会起作用。为什么?
- mysql - 连接到 vps 上的 mysql 服务器
- r - 计算 R 中 DNA 多序列比对的熵
- java - 如何将 JSON 文档反序列化为 Jackson 中的预处理 bean?
- apache-ranger - Kafka Ranger SSL 集成问题
- openssl - 将 DER 格式的证书和密钥合并到一个文件中
- javascript - 合并或组合两个 onEdit 触发器函数
- javascript - Angular 9:如何根据下拉值动态添加行
- windows - localStack 在 Windows 10 上的 docker 中启动,但无法通过 localhost 连接