| osrm_start | R Documentation |
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.
osrm_start(
path,
algorithm = c("mld", "ch"),
force_rebuild = FALSE,
show_progress = TRUE,
quiet = FALSE,
verbose = FALSE,
...
)
path |
A string. Path to the input data. Can be one of:
|
algorithm |
A string specifying the routing algorithm to use for graph
preparation, either |
force_rebuild |
A logical value. If |
show_progress |
A logical value. If |
quiet |
A logical value. If |
verbose |
A logical. If |
... |
Additional arguments passed on to |
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-routed
executable is available in the system's PATH. If not, it automatically
calls osrm_install() to download and install the latest stable version.
Process Input Path and Prepare Graph: The function intelligently
handles the path argument to find or create the necessary graph files.
If the graph files do not exist, it automatically runs osrm_prepare_graph()
to build them, which may take some time.
Start Server: Once the graph files are located or prepared, it
launches the osrm-routed server 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.
An OSRM job process (an osrm_server object inheriting from
processx::process) for the running server.
osrm_stop(), osrm_start_server() for manual server startup.
if (identical(Sys.getenv("OSRM_EXAMPLES"), "true")) {
install_dir <- osrm_install(
version = "latest",
path_action = "session",
quiet = TRUE
)
# copy example OSM PBF into a temporary workspace to avoid polluting pkg data
pbf_path <- system.file("extdata/cur.osm.pbf", package = "osrm.backend")
osrm_dir <- file.path(tempdir(), paste0("osrm-", Sys.getpid()))
dir.create(osrm_dir, recursive = TRUE)
local_pbf <- file.path(osrm_dir, "cur.osm.pbf")
file.copy(from = pbf_path, to = local_pbf, overwrite = TRUE)
# 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()
osrm_uninstall(
dest_dir = install_dir,
clear_path = TRUE,
force = TRUE,
quiet = TRUE
)
unlink(osrm_dir, recursive = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.