## Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
## Routing: OSRM - http://project-osrm.org/
## Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
Start the server with osrm_start() function pointing to
the temporary directory created above. It will automatically check if
OSRM Backend binaries are installed, and if not, it will install the
latest version, it will also automatically prepare the routing graph
from the OSM PBF file if not already done and start the server. If any
of the steps are unnecessary, it will skip them, so running this
funciton will not lead to re-downloading of OSRM binaries or
re-processing of the OSM PBF file if already done.
Tip: You can check if server is running with
osrm_servers():# A tibble: 1 × 7 id pid port algorithm started_at alive has_handle <chr> <int> <int> <chr> <dttm> <lgl> <lgl> 1 osrm-28034-5001-20251103122904.133 28034 5001 MLD 2025-11-03 00:00:00 TRUE TRUEYou can kill the server with
osrm_stop()orosrm_stop_all()if you have started several servers.
Load some spatial data from the OSM PBF file to sample points for routing and plot the street network:
To use {osrm} package with the local server, you have to
set the osrm.server option to point to the local server
URL. The default port that osrm_start() uses is
5001, so the URL will be
http://localhost:5001/. Then you can use any
{osrm} function as usual, here we calculate a route between
the two sampled points:
options("osrm.server" = "http://localhost:5001/")
route <- osrm::osrmRoute(loc = sampled_points)
routeSimple feature collection with 1 feature and 4 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: -49.27156 ymin: -25.43082 xmax: -49.25396 ymax: -25.42358
Geodetic CRS: WGS 84
src dst duration distance geometry
3786_503 3786 503 5.55 2.6324 LINESTRING (-49.25534 -25.4...