A high-level, "one-shot" function to start an OSRM server that automatically handles OSRM installation and graph preparation. This is the recommended function for most users to get a server running quickly with minimal steps.
Usage
osrm_start(
path,
algorithm = c("mld", "ch"),
quiet = FALSE,
verbose = FALSE,
...
)Arguments
- path
A string. Path to the input data. Can be one of:
A path to an OSM file (e.g.,
/path/to/data.osm.pbf).A path to a directory containing OSRM graph files or an OSM file.
A direct path to a final graph file (
.osrm.mldgror.osrm.hsgr).
- algorithm
A string specifying the routing algorithm to use for graph preparation, either
"mld"(Multi-Level Dijkstra, default) or"ch"(Contraction Hierarchies). This is only used whenosrm_prepare_graphis automatically called.- quiet
A logical value. If
TRUE, suppresses messages. Defaults toFALSE. Defaults toFALSE.- verbose
A logical. If
FALSE(default), suppresses detailed console output from backend commands. IfTRUE, shows all output, which is useful for debugging.- ...
Additional arguments passed on to
osrm_prepare_graph()(e.g.,overwrite = TRUE) andosrm_start_server()(e.g.,port = 5001).
Value
A processx::process object for the running server.
Details
This function is designed for convenience and automates the entire setup process. By default, it is not verbose and only prints high-level status messages.
Check for OSRM Installation: It first verifies if the
osrm-routedexecutable is available in the system'sPATH. If not, it automatically callsosrm_install()to download and install the latest stable version.Process Input Path and Prepare Graph: The function intelligently handles the
pathargument to find or create the necessary graph files. If the graph files do not exist, it automatically runsosrm_prepare_graph()to build them, which may take some time.Start Server: Once the graph files are located or prepared, it launches the
osrm-routedserver and prints a confirmation message with the server's PID and port.
For advanced users or for debugging, set verbose = TRUE to see the detailed
console output from the installation and graph preparation steps. For full
manual control, use the lower-level functions like osrm_prepare_graph() and
osrm_start_server() directly.
See also
osrm_stop(), osrm_start_server() for manual server startup.
Examples
if (FALSE) { # \dontrun{
# Get the path to the example OSM file included in the package
pbf_file <- system.file("extdata/cur.osm.pbf", package = "osrm.backend")
# Create a temporary directory to work in
temp_dir <- tempdir()
file.copy(pbf_file, temp_dir)
local_pbf <- file.path(temp_dir, "cur.osm.pbf")
# Start the server with one command.
# It will quietly install OSRM and prepare the graph if needed.
osrm_process <- osrm_start(local_pbf)
# Stop the server when done.
osrm_stop()
# To see all backend logs during setup, use verbose = TRUE
osrm_process_verbose <- osrm_start(local_pbf, verbose = TRUE)
osrm_stop()
} # }