osrm

:twisted_rightwards_arrows: Shortest Paths and Travel Time from OpenStreetMap with R

Github星跟踪图

osrm R package

Version

Travis-CI Build Status

Interface Between R and the OpenStreetMap-Based Routing Service OSRM

Description

OSRM is a routing service based on OpenStreetMap data. See http://project-osrm.org/ for more information. This package allows to compute distances (travel time and kilometric distance) between points and travel time matrices.

This package relies on the usage of a running OSRM service (tested with v5.22.0 of OSRM).

You can run your own instance of OSRM following guidelines provided here: https://github.com/Project-OSRM/osrm-backend.
The simplest solution is probably the one based on docker containers.

To set the OSRM server, use the osrm.server option: options(osrm.server = "http://address.of.the.server/").
To set the profile ("driving" is set by default and it is the only profile available on the demo server), use the osrm.profile option: options(osrm.profile = "name.of.the.profile").
The "driving" profile is set by default and it is the only profile available on the demo server. Other possible profiles are "walk" and "bike".
A typical setup, corresponding to the Docker example, would be:
options(osrm.server = "http://0.0.0.0:5000/", osrm.profile = "driving")

:warning: You must be careful using the OSRM demo server:

"The demo server usage is restricted to reasonable, non-commercial use-cases. We provide no guarantees wrt. uptime, latency, or data updates."

Features

  • osrmTable Get travel time matrices between points.

  • osrmRoute Get the shortest path between two points.

  • osrmTrip Get the travel geometry between multiple unordered points.

  • osrmIsochrone Get polygons of isochrones.

Demo

osrmTable

library(osrm)
data("berlin")
# Travel time matrix
distA <- osrmTable(loc = apotheke.sf[1:5,])
distA$durations
```, 440338666, 538057637, 977657079, 3770254015, 364363337, :----------, ---------:, ---------:, ---------:, ----------:, ---------:, 440338666, 0.0, 24.2, 48.0, 26.9, 15.0, 538057637, 27.1, 0.0, 44.2, 16.4, 22.6, 977657079, 47.6, 41.7, 0.0, 35.0, 36.2, 3770254015, 28.7, 16.9, 34.6, 0.0, 17.0, 364363337, 15.4, 20.7, 34.4, 15.9, 0.0, ### `osrmRoute`

```r
library(osrm)
library(sf)
library(cartography)
data("berlin")
route <- osrmRoute(src = apotheke.sf[74,], dst = apotheke.sf[55,],
                   overview = "full", returnclass = "sf")
# Display the path
osm <- getTiles(x = route, crop = TRUE, type = "osm", zoom = 13)
tilesLayer(osm)
plot(st_geometry(route), lwd = 4, add = TRUE)
plot(st_geometry(route), lwd = 1, col = "white", add = TRUE)
plot(st_geometry(apotheke.sf[c(74,55),]), pch = 20, col = "red", add = TRUE)

osrmTrip

library(osrm)
library(sf)
library(cartography)
data("berlin")
# Get a trip with a SpatialPointsDataFrame
trips <- osrmTrip(loc = apotheke.sf[10:20,], returnclass="sf")
trip <- trips$trip
osm2 <- getTiles(x = trip, crop = TRUE, type = "cartolight", zoom = 11)
tilesLayer(x = osm2)
plot(st_geometry(trip), col = "black", lwd = 4, add = TRUE )
plot(st_geometry(trip), col = c("red", "white"), lwd = 1, add=TRUE)
plot(st_geometry(apotheke.sf[10:20,]), pch = 21, bg = "red", cex = 1.5, add=TRUE)

osrmIsochrone

library(osrm)
library(sf)
library(cartography)
data("berlin")
iso <- osrmIsochrone(loc = apotheke.sf[87,], returnclass="sf",
                     breaks = seq(from = 0, to = 14, by = 2), res = 50)
osm3 <- getTiles(x = iso, crop = FALSE, type = "osm", zoom = 12)
tilesLayer(x = osm3)
bks <- sort(c(unique(iso$min), max(iso$max)))
cols <- paste0(carto.pal("turquoise.pal", n1 = length(bks)-1), 80)
choroLayer(x = iso, var = "center", breaks = bks,
           border = NA, col = cols,
           legend.pos = "topleft",legend.frame = TRUE,
           legend.title.txt = "Isochrones\n(min)",
           add = TRUE)
plot(st_geometry(apotheke.sf[87,]), pch = 21, bg = "red", 
     cex = 1.5, add=TRUE)

Installation

  • Development version on GitHub
remotes::install_github("rCarto/osrm")
  • Stable version on CRAN
install.packages("osrm")

Community Guidelines

One can contribute to the package through pull requests and report issues or ask questions here.

主要指标

概览
名称与所有者riatelab/osrm
主编程语言R
编程语言R (语言数: 2)
平台
许可证GNU General Public License v3.0
所有者活动
创建于2015-09-11 07:39:33
推送于2025-05-12 09:44:53
最后一次提交2025-05-12 11:36:06
发布数16
最新版本名称v4.2.0 (发布于 )
第一版名称v1.0 (发布于 )
用户参与
星数242
关注者数8
派生数34
提交数356
已启用问题?
问题数120
打开的问题数1
拉请求数12
打开的拉请求数0
关闭的拉请求数3
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?