【问题标题】:Interpolate position 5 minutes after starting from point A to B从 A 点开始到 B 点后 5 分钟内插位置
【发布时间】:2021-10-19 14:09:44
【问题描述】:

下面是使用 R 中的 osrm 包查找从“纽约世贸中心一号”到“纽约麦迪逊广场公园”的路线、旅行时间和旅行距离的示例。(我从 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")

【问题讨论】:

    标签: r sf sp osrm


    【解决方案1】:

    使用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')
    
    

    【讨论】:

    • 非常感谢@mrhellmann。但是我有超过 20,000 次行程,为每次行程创建等时线会非常昂贵。有没有有效的方法来做到这一点。
    • 您可以使用st_sample(x, type = 'regular') 对线串上的点进行采样,然后找到沿线最接近 5 分钟/总行程分钟的点(在这种情况下,它大约是沿线的一半)线)。不过,这将假设行程的速度恒定。
    猜你喜欢
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多