### Run Node.js Example Source: https://github.com/project-osrm/osrm-backend/blob/master/example/README.md Execute the Node.js example program. Ensure you are in the example directory. ```bash cd example/ node example.js ``` -------------------------------- ### Build and Run C++ Example Source: https://github.com/project-osrm/osrm-backend/blob/master/example/README.md Build and execute the C++ example program after installing the main OSRM project. This requires CMake. ```bash cd example/ mkdir build && cd build/ cmake .. cmake --build . ./osrm-example ../test/data/mld/monaco.osrm ``` -------------------------------- ### Build OSRM Library Example Application Source: https://github.com/project-osrm/osrm-backend/wiki/Library-API Steps to build the example C++ application for the OSRM library after installation. This involves creating a build directory, configuring with CMake, and building the project. ```bash mkdir build cd build cmake .. cmake --build . ``` -------------------------------- ### Complete Profile Integration with Raster Data Source: https://github.com/project-osrm/osrm-backend/wiki/Integrating-third-party-raster-data This example demonstrates a complete `source_function` and `segment_function` setup, including environment variable loading, coordinate precision adjustment, bounds checking, and calculating slope-based penalties for segment weights and durations. ```lua api_version = 1 properties.force_split_edges = true local LON_MIN=tonumber(os.getenv("LON_MIN")) local LON_MAX=tonumber(os.getenv("LON_MAX")) local LAT_MIN=tonumber(os.getenv("LAT_MIN")) local LAT_MAX=tonumber(os.getenv("LAT_MAX")) function source_function() raster_source = sources:load( os.getenv("RASTER_SOURCE_PATH"), LON_MIN, LON_MAX, LAT_MIN, LAT_MAX, tonumber(os.getenv("NROWS")), tonumber(os.getenv("NCOLS"))) LON_MIN = LON_MIN * constants.precision LON_MAX = LON_MAX * constants.precision LAT_MIN = LAT_MIN * constants.precision LAT_MAX = LAT_MAX * constants.precision end function segment_function (segment) local out_of_bounds = false if segment.source.lon < LON_MIN or segment.source.lon > LON_MAX or segment.source.lat < LAT_MIN or segment.source.lat > LAT_MAX or segment.target.lon < LON_MIN or segment.target.lon > LON_MAX or segment.target.lat < LAT_MIN or segment.target.lat > LAT_MAX then out_of_bounds = true end if out_of_bounds == false then local sourceData = sources:interpolate(raster_source, segment.source.lon, segment.source.lat) local targetData = sources:interpolate(raster_source, segment.target.lon, segment.target.lat) local elev_delta = targetData.datum - sourceData.datum local slope = 0 local penalize = 0 if distance ~= 0 and targetData.datum > 0 and sourceData.datum > 0 then slope = elev_delta / segment.distance end -- these types of heuristics are fairly arbitrary and take some trial and error if slope > 0.08 then penalize = 0.6 end if slope ~= 0 then segment.weight = segment.weight * (1 - penalize) -- a very rought estimate of duration of the edge so that the time estimate is more accurate segment.duration = segment.duration * (1+slope) end end end ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/project-osrm/osrm-backend/blob/master/example/README.md Install required npm packages for the Node.js example. This should be done after building the main OSRM project. ```bash npm install ``` -------------------------------- ### CH Pipeline Quickstart Source: https://github.com/project-osrm/osrm-backend/wiki/Running-OSRM Quickstart commands for the CH pipeline, including data download, extraction, contraction, and running the routed server. ```bash cd osrm-backend wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf osrm-extract berlin-latest.osm.pbf -p profiles/car.lua osrm-contract berlin-latest.osrm osrm-routed berlin-latest.osrm ``` -------------------------------- ### Install Node.js Bindings (From Source) Source: https://github.com/project-osrm/osrm-backend/blob/master/README.md Forces the installation of OSRM Node.js bindings by building them from source. ```bash npm install --build-from-source ``` -------------------------------- ### MLD Pipeline Quickstart Source: https://github.com/project-osrm/osrm-backend/wiki/Running-OSRM Quickstart commands for the MLD pipeline, including data download, extraction, partitioning, customization, and running the routed server. ```bash cd osrm-backend wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf osrm-extract berlin-latest.osm.pbf osrm-partition berlin-latest.osrm osrm-customize berlin-latest.osrm osrm-routed --algorithm=MLD berlin-latest.osrm ``` -------------------------------- ### Install vcpkg Libraries for OSRM Source: https://github.com/project-osrm/osrm-backend/wiki/Windows-Compilation Install necessary libraries like lua, tbb, bzip2, libzip, and boost using vcpkg. Ensure all boost libraries are installed to prevent compilation errors. ```bash vcpkg install lua:x64-windows vcpkg install tbb:x64-windows vcpkg install bzip2:x64-windows vcpkg install libzip:x64-windows vcpkg install boost:x64-windows ``` -------------------------------- ### Example OSRM API Query Source: https://github.com/project-osrm/osrm-backend/wiki/Demo-server This is an example of a GET request to the OSRM demo server for a route query in Berlin. It specifies the route, coordinates, and various parameters like geometries, alternatives, and steps. ```http https://router.project-osrm.org/route/v1/driving/13.414167165756226,52.52167215019524;13.4197763,52.5003103?geometries=geojson&alternatives=true&steps=true&generate_hints=false ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/python/development.md Installs pre-commit hooks to ensure code quality and consistency before committing changes. ```bash pre-commit install ``` -------------------------------- ### Install OSRM Source: https://github.com/project-osrm/osrm-backend/wiki/Building-OSRM After configuring and building, use this command to install OSRM system-wide, typically requiring superuser privileges. ```bash sudo cmake --build . --target install ``` -------------------------------- ### STXXL Configuration Example Source: https://github.com/project-osrm/osrm-backend/wiki/Running-OSRM Example configuration line for the STXXL library, specifying a disk file, its capacity, and access method. This file should be named '.stxxl' or set via the STXXLCFG environment variable. ```cfg disk=/path/to/stxxl,250000,syscall ``` -------------------------------- ### Run OSRM Library Example Application Source: https://github.com/project-osrm/osrm-backend/wiki/Library-API How to execute the built OSRM C++ example application. It requires a pre-processed OSRM data file (e.g., monaco.osrm) as a command-line argument. ```bash ./osrm-backend monaco.osrm ``` -------------------------------- ### Table Service Example Options Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Illustrates how to specify sources and destinations for the table service using indices. ```text sources=0;5;7&destinations=5;1;4;2;3;6 ``` -------------------------------- ### Install System Dependencies on Fedora/RHEL/Rocky/AlmaLinux Source: https://github.com/project-osrm/osrm-backend/blob/master/src/python/README.md Install the required system dependencies for building osrm-bindings from source on Fedora, RHEL, Rocky Linux, or AlmaLinux. ```bash sudo dnf install -y \ cmake gcc-c++ git pkgconf-pkg-config \ boost-devel bzip2-devel lua-devel \ tbb-devel libxml2-devel libzip-devel ``` -------------------------------- ### Install osrm-bindings from Source Source: https://github.com/project-osrm/osrm-backend/blob/master/src/python/README.md Install the osrm-bindings package from a source distribution. This method requires CPython 3.10+ and the necessary C++ toolchain and OSRM native dependencies. ```bash pip install . ``` -------------------------------- ### Install Shapefile Library Source: https://github.com/project-osrm/osrm-backend/wiki/Check-conditional-restrictions Install the Shapefile library, a dependency for `osrm-extract-conditionals`. ```bash sudo apt install libshp-dev ``` -------------------------------- ### Install System Dependencies on Debian/Ubuntu Source: https://github.com/project-osrm/osrm-backend/blob/master/src/python/README.md Install the required system dependencies for building osrm-bindings from source on Debian or Ubuntu systems. ```bash sudo apt-get install -y \ cmake g++ git pkg-config \ libboost-all-dev libbz2-dev liblua5.4-dev \ libtbb-dev libxml2-dev libzip-dev ``` -------------------------------- ### Run Node.js Example with Custom Thread Pool Size Source: https://github.com/project-osrm/osrm-backend/blob/master/example/README.md Run the Node.js example with a specified thread pool size by setting the UV_THREADPOOL_SIZE environment variable. This can impact performance. ```bash UV_THREADPOOL_SIZE=16 node example.js ``` -------------------------------- ### Install osrm-bindings using pip Source: https://github.com/project-osrm/osrm-backend/blob/master/src/python/README.md Install the osrm-bindings package from PyPI. This command is suitable for most users, especially those with Python 3.12 or later. ```bash pip install osrm-bindings ``` -------------------------------- ### Install OSRM Build Tools Source: https://github.com/project-osrm/osrm-backend/wiki/Check-conditional-restrictions Configure OSRM with `BUILD_TOOLS=ON` and compile `osrm-extract-conditionals` if you need to build it from source. ```bash cmake -DBUILD_TOOLS=ON .. make osrm-extract-conditionals ``` -------------------------------- ### Compile and Install OSRM Binaries Source: https://github.com/project-osrm/osrm-backend/blob/master/README.md Configures, builds, and installs OSRM binaries using CMake presets for Linux. ```bash cmake --preset ci-linux cmake --build --preset ci-linux sudo cmake --install build ``` -------------------------------- ### Install System Dependencies on macOS Source: https://github.com/project-osrm/osrm-backend/blob/master/src/python/README.md Install the required system dependencies for building osrm-bindings from source on macOS using Homebrew. ```bash brew install cmake lua tbb boost@1.90 brew link boost@1.90 ``` -------------------------------- ### Fetch Vector Tile Example Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md This example demonstrates how to fetch a vector tile for a specific location and zoom level using curl. Ensure the URL is correct for your OSRM instance. ```bash # This fetches a Z=13 tile for downtown San Francisco: curl 'http://router.project-osrm.org/tile/v1/car/tile(1310,3166,13).mvt' ``` -------------------------------- ### Start OSRM Frontend with Docker Source: https://github.com/project-osrm/osrm-backend/blob/master/README.md Starts the OSRM frontend Docker container, making a user-friendly interface available on port 9966. ```bash docker run -p 9966:9966 osrm/osrm-frontend ``` -------------------------------- ### Install OSRM Executables Source: https://github.com/project-osrm/osrm-backend/blob/master/CMakeLists.txt Installs the main OSRM executables to the 'bin' directory. These are the command-line tools for OSRM operations. ```cmake install(TARGETS osrm-extract DESTINATION bin) install(TARGETS osrm-partition DESTINATION bin) install(TARGETS osrm-customize DESTINATION bin) install(TARGETS osrm-contract DESTINATION bin) install(TARGETS osrm-datastore DESTINATION bin) install(TARGETS osrm-routed DESTINATION bin) ``` -------------------------------- ### Install cibuildwheel Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/python/development.md Installs the cibuildwheel package, which is used for building Python wheels in isolated environments. ```bash pip install cibuildwheel ``` -------------------------------- ### Example Test Case Structure Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/testing.md Illustrates a typical test case structure using a Given-When-Then format. This example shows how to define grid size, node map, and expected routing results, including waypoints, route, and turns. ```gherkin Given a grid size of 5 m Given the node map """ a - b - - - - - - c \ d - - - - - e """ When I route I should get | waypoints | route | turns | | a,e | abc,bde,bde | depart,turn slight right,arrive| ``` ```gherkin Given a grid size of 5 m Given the node map """ a - b - - - - - - c \ d - - - - - e """ When I route I should get | waypoints | route | turns | | a,e | abc,bde,bde | depart,turn right,arrive| ``` -------------------------------- ### Nearest Service Example Request Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Example cURL command to query the Nearest service for three snapped locations with specified bearings. ```bash # Querying nearest three snapped locations of `13.388860,52.517037` with a bearing between `20° - 340°`. curl 'http://router.project-osrm.org/nearest/v1/driving/13.388860,52.517037?number=3&bearings=0,20' ``` -------------------------------- ### Raster Data ASCII Format Example Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/profiles.md The input data for raster loading must be an ASCII file with rows of integers. This example shows the expected format. ```text 0 0 0 0 0 0 0 250 0 0 250 500 0 0 0 250 0 0 0 0 ``` -------------------------------- ### Install OSRM Bindings (Source Build) Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/python/development.md Installs OSRM bindings from source, necessary for Python versions older than 3.12, specific architectures (aarch64, arm64), or platforms without pre-built wheels. This method compiles the full OSRM C++ library and can take a significant amount of time. ```bash pip install osrm-bindings --no-binary osrm-bindings ``` -------------------------------- ### Example Route Service Request Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Example cURL command to query the route service for a route between three coordinates in Berlin, with overview geometry disabled. ```bash # Query on Berlin with three coordinates and no overview geometry returned: curl 'http://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?overview=false' ``` -------------------------------- ### Trip Service Example Request (Basic Round Trip) Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Example cURL request for a round trip in Berlin with three stops. The default options for source and destination are used. ```bash # Round trip in Berlin with three stops: curl 'http://router.project-osrm.org/trip/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219' ``` -------------------------------- ### Install OSRM Bindings (Development) Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/python/development.md Installs OSRM bindings in editable mode with development dependencies. This is recommended for active development on the OSRM Python bindings. ```bash git clone https://github.com/Project-OSRM/osrm-backend cd osrm-backend pip install -e ".[dev]" ``` -------------------------------- ### Trip Service Example Request (Specific Start/End) Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Example cURL request for a round trip with four stops, explicitly setting the source to the first coordinate and the destination to the last. ```bash # Round trip in Berlin with four stops, starting at the first stop, ending at the last: curl 'http://router.project-osrm.org/trip/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219;13.418555,52.523215?source=first&destination=last' ``` -------------------------------- ### Load Raster Data in OSRM Setup Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/profiles.md Use `raster:load()` in your `setup` function to load raster data and store the source in your configuration hash. This is useful for factoring in data like elevation into route calculations. ```lua function setup() return { raster_source = raster:load( "rastersource.asc", -- file to load 0, -- longitude min 0.1, -- longitude max 0, -- latitude min 0.1, -- latitude max 5, -- number of rows 4 -- number of columns ) } end ``` -------------------------------- ### Editable Install with No Build Isolation Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/python/development.md Use this command for an editable install that reuses the build directory across runs, speeding up subsequent builds. Ensure config flags remain identical. ```bash pip install -e . --no-build-isolation ``` ```powershell $env:CMAKE_ARGS = "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static-md" pip install -e . --no-build-isolation ``` -------------------------------- ### Install vcpkg and Integrate Source: https://github.com/project-osrm/osrm-backend/wiki/Windows-Compilation Clone the vcpkg repository, run the bootstrap script, and integrate it with your build environment. This sets up the package manager for Windows. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg bootstrap-vcpkg.bat vcpkg integrate install ``` -------------------------------- ### Cucumber Scenario Example Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/testing.md An example of a Cucumber scenario for testing routing functionality, including background setup for profiles and grid size, and defining node maps and ways. ```gherkin Background: Given the profile "car" Given a grid size of 10 meters Scenario: Testbot - Straight Road Given the node map """ a b c d """ And the ways | nodes | highway | | ab | primary | | bc | primary | | cd | primary | When I route I should get | from | to | route | | a | d | ab,bc,cd,cd | ``` -------------------------------- ### Test OSRM Routing Endpoint Source: https://github.com/project-osrm/osrm-backend/blob/master/example/README.md Send a request to the OSRM routing HTTP endpoint to test its functionality. This example uses specific start and end coordinates. ```bash curl 'http://localhost:8888?start=7.419758,43.731142&end=7.419505,43.736825' ``` -------------------------------- ### Parse Routing Request URL Source: https://github.com/project-osrm/osrm-backend/wiki/Processing-Flow Example of a routing request URL sent to the OSRM backend. It specifies the start and end locations, and requests instructions and JSON output. ```http /viaroute?loc=1.0,1.0026972038088113&loc=0.9991009320637295,1.0&instructions=true&output=json ``` -------------------------------- ### Collect Deployment Files with --list-inputs Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/tools.md Example script to collect all necessary files for deploying `osrm-routed` by iterating through the output of `--list-inputs`. ```bash BASE=map for line in $(osrm-routed --list-inputs); do echo "$BASE$line" done ``` -------------------------------- ### Build osrm-bindings on Windows with vcpkg Source: https://github.com/project-osrm/osrm-backend/blob/master/src/python/README.md Example steps for building osrm-bindings on Windows using vcpkg and MSVC. This involves cloning and bootstrapping vcpkg, then configuring and building with CMake. ```powershell # Clone & bootstrap vcpkg git clone https://github.com/microsoft/vcpkg.git C:\vcpkg cd C:\vcpkg .\bootstrap-vcpkg.bat cmake --preset release cmake --build buildß ``` -------------------------------- ### Bootstrap vcpkg and Set Environment Variable Source: https://github.com/project-osrm/osrm-backend/blob/master/README.md Clones the vcpkg repository, bootstraps it, and sets the VCPKG_ROOT environment variable for dependency management. ```bash git clone https://github.com/microsoft/vcpkg.git ~/vcpkg ~/vcpkg/bootstrap-vcpkg.sh export VCPKG_ROOT=~/vcpkg ``` -------------------------------- ### Install Linux Build Dependencies Source: https://github.com/project-osrm/osrm-backend/blob/master/README.md Installs essential packages required for building OSRM from source on Linux systems. ```bash sudo apt install build-essential git cmake ninja-build pkg-config \ autoconf automake libtool curl zip unzip tar ``` -------------------------------- ### Clone and Bootstrap vcpkg Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/windows-deps.md Clone the vcpkg repository and bootstrap it to manage dependencies. Set the VCPKG_ROOT environment variable. ```bat git clone https://github.com/microsoft/vcpkg.git C:\vcpkg C:\vcpkg\bootstrap-vcpkg.bat set VCPKG_ROOT=C:\vcpkg ``` -------------------------------- ### Prepare Test Data Source: https://github.com/project-osrm/osrm-backend/blob/master/example/README.md Navigate to the test data directory and build all necessary test data. This command assumes Node.js is installed. ```bash cd test/data/ make all cd ../../ ``` -------------------------------- ### Route Service GET Endpoint Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Defines the GET endpoint for the route service. Use this to find the fastest route between coordinates. ```http GET /route/v1/{profile}/{coordinates}?alternatives={true|false|number}&steps={true|false}&geometries={polyline|polyline6|geojson}&overview={full|simplified|false}&annotations={true|false} ``` -------------------------------- ### Start OSRM Routing Server with osrm-routed Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/tools.md Launches the OSRM HTTP server to serve routing requests. Specify the base OSRM data file and configure server and data loading options. ```bash osrm-routed [options] ``` -------------------------------- ### Initialize OSRM Engine Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/python/api.md Instantiate the OSRM engine by providing the path to the dataset. Keyword arguments can be used to configure the algorithm, memory usage, and various location/result limits. ```python import osrm # From file engine = osrm.OSRM("path/to/data.osrm") # With keyword arguments engine = osrm.OSRM( storage_config="path/to/data.osrm", algorithm="CH", # or "MLD" use_shared_memory=False, max_locations_trip=3, max_locations_viaroute=3, max_locations_distance_table=3, max_locations_map_matching=3, max_results_nearest=1, max_alternatives=1, default_radius="unlimited", ) # Using shared memory (requires osrm-datastore) engine = osrm.OSRM(use_shared_memory=True) ``` -------------------------------- ### Install OSRM Libraries Source: https://github.com/project-osrm/osrm-backend/blob/master/CMakeLists.txt Installs the OSRM core libraries to the 'lib' directory. These are the shared or static libraries used by other OSRM components or applications. ```cmake install(TARGETS osrm DESTINATION lib) install(TARGETS osrm_extract DESTINATION lib) install(TARGETS osrm_partition DESTINATION lib) install(TARGETS osrm_customize DESTINATION lib) install(TARGETS osrm_update DESTINATION lib) install(TARGETS osrm_contract DESTINATION lib) install(TARGETS osrm_store DESTINATION lib) ``` -------------------------------- ### Open Frontend in Browser Source: https://github.com/project-osrm/osrm-backend/blob/master/README.md Opens the OSRM frontend in the default web browser using xdg-open. ```bash xdg-open 'http://127.0.0.1:9966' ``` -------------------------------- ### Testbot - Intersection Scenario Setup Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/testing.md Defines a node map and ways for a test scenario. This setup is used to illustrate waypoint selection behavior. ```gherkin Scenario: Testbot - Intersection Given the node map """ e b a d c """ And the ways | nodes | highway | oneway | | ab | primary | yes | | ac | primary | yes | | ad | primary | yes | | ae | primary | yes | ``` -------------------------------- ### OSRM Constructor Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/nodejs/api.md Initializes a new OSRM instance. You can provide either a path to the .osrm dataset or configuration options. ```APIDOC ## OSRM Constructor ### Description The `OSRM` method is the main constructor for creating an OSRM instance. It requires a prepared `.osrm.*` dataset. ### Parameters * `options` **([Object][2] | [String][3])** Options for creating an OSRM object or string to the `.osrm` file. (optional, default `{shared_memory:true}`) * `options.algorithm` **[String][3]?** The algorithm to use for routing. Can be 'CH', or 'MLD'. Default is 'CH'. * `options.shared_memory` **[Boolean][4]?** Connects to the persistent shared memory datastore. * `options.dataset_name` **[String][3]?** Connects to the persistent shared memory datastore defined by `--dataset_name` option when running `osrm-datastore`. * `options.memory_file` **[String][3]?** **DEPRECATED** Path to a file on disk to store the memory using mmap. * `options.mmap_memory` **[Boolean][4]?** Map on-disk files to virtual memory addresses (mmap), rather than loading into RAM. * `options.path` **[String][3]?** The path to the `.osrm` files. This is mutually exclusive with setting {options.shared_memory} to true. * `options.disable_feature_dataset` **[Array][5]?** Disables a feature dataset from being loaded into memory if not needed. Options: `ROUTE_STEPS`, `ROUTE_GEOMETRY`. * `options.max_locations_trip` **[Number][6]?** Max. locations supported in trip query (default: unlimited). * `options.max_locations_viaroute` **[Number][6]?** Max. locations supported in viaroute query (default: unlimited). * `options.max_locations_distance_table` **[Number][6]?** Max. locations supported in distance table query (default: unlimited). * `options.max_locations_map_matching` **[Number][6]?** Max. locations supported in map-matching query (default: unlimited). * `options.max_radius_map_matching` **[Number][6]?** Max. radius size supported in map matching query (default: 5). * `options.max_results_nearest` **[Number][6]?** Max. results supported in nearest query (default: unlimited). * `options.max_alternatives` **[Number][6]?** Max. number of alternatives supported in alternative routes query (default: 3). * `options.default_radius` **[Number][6]?** Default radius for queries (default: unlimited). ### Example ```javascript var osrm = new OSRM('network.osrm'); ``` ``` -------------------------------- ### Example ASCII Grid Data Format Source: https://github.com/project-osrm/osrm-backend/wiki/Integrating-third-party-raster-data This is an example of the plaintext ASCII grid data format supported by OSRM. Ensure data is in this format before loading. ```plaintext 3 4 56 66 6 7 3 4 4 56 20 3 5 6 5 3 14 1 ``` -------------------------------- ### Instantiate OSRM and Calculate Route Source: https://github.com/project-osrm/osrm-backend/blob/master/src/python/README.md This example demonstrates how to instantiate the OSRM Python object with a model file and then calculate a route between two coordinates. ```python import osrm # Instantiate osrm_py instance osrm_py = osrm.OSRM("./test/data/ch/monaco.osrm") ``` ```python # Declare Route Parameters route_params = osrm.RouteParameters( coordinates = [(7.41337, 43.72956), (7.41546, 43.73077)] ) # Pass it into the osrm_py instance res = osrm_py.Route(route_params) # Print out result output print(res["waypoints"]) print(res["routes"]) ``` -------------------------------- ### Initialize OSRM Instance Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/nodejs/api.md Instantiate an OSRM object by providing the path to a pre-compiled OSRM dataset. Ensure the dataset is prepared using the OSRM toolchain. ```javascript var osrm = new OSRM('network.osrm'); ``` -------------------------------- ### Table Service GET Endpoint Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Defines the GET endpoint for the table service. Use this to compute durations and/or distances between all pairs of supplied coordinates. ```http GET /table/v1/{profile}/{coordinates}?{sources}=[{elem}...];&{destinations}=[{elem}...]&annotations={duration|distance|duration,distance} ``` -------------------------------- ### RouteLeg Object Example with Annotations Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Represents a segment of a route between two waypoints. This example includes detailed annotations for each coordinate along the leg, with `steps=false` and `annotations=true`. ```json { "distance": 30.0, "duration": 100.0, "weight": 100.0, "steps": [], "annotation": { "distance": [5,5,10,5,5], "duration": [15,15,40,15,15], "datasources": [1,0,0,0,1], "metadata": { "datasource_names": ["traffic","lua profile","lua profile","lua profile","traffic"] }, "nodes": [49772551,49772552,49786799,49786800,49786801,49786802], "speed": [0.3, 0.3, 0.3, 0.3, 0.3] } } ``` -------------------------------- ### Nearest Service Example Response Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Example JSON response from the Nearest service, showing waypoint details including nodes, hint, distance, name, and location. ```json { "waypoints" : [ { "nodes": [ 2264199819, 0 ], "hint" : "KSoKADRYroqUBAEAEAAAABkAAAAGAAAAAAAAABhnCQCLtwAA_0vMAKlYIQM8TMwArVghAwEAAQH1a66g", "distance" : 4.152629, "name" : "Friedrichstraße", "location" : [ 13.388799, 52.517033 ] }, { "nodes": [ 2045820592, 0 ], "hint" : "KSoKADRYroqUBAEABgAAAAAAAAAAAAAAKQAAABhnCQCLtwAA7kvMAAxZIQM8TMwArVghAwAAAQH1a66g", "distance" : 11.811961, "name" : "Friedrichstraße", "location" : [ 13.388782, 52.517132 ] }, { "nodes": [ 0, 21487242 ], "hint" : "KioKgDbbDgCUBAEAAAAAABoAAAAAAAAAPAAAABlnCQCLtwAA50vMADJZIQM8TMwArVghAwAAAQH1a66g", "distance" : 15.872438, "name" : "Friedrichstraße", "location" : [ 13.388775, 52.51717 ] } ], "code" : "Ok" } ``` -------------------------------- ### Include Ordering Source: https://github.com/project-osrm/osrm-backend/wiki/Coding-Standards Includes should be ordered as: Module Header, Local/Private Headers, ../..., and System Includes. Each category must be sorted lexicographically. ```c++ #include "module_header.h" #include "local_header.h" #include "../parent_dir/header.h" #include ``` -------------------------------- ### Initialize MapLibre GL JS Map Source: https://github.com/project-osrm/osrm-backend/blob/master/example/trip.html Sets up a new MapLibre GL JS map instance with specified style, center, and zoom level. Includes adding navigation controls. ```javascript const MAX_LOCATIONS = 25; const DEFAULT_STYLE = 'https://pnorman.github.io/tilekiln-shortbread-demo/colorful.json'; const DEFAULT_CENTER = [8.682127, 50.110924]; const map = new maplibregl.Map({ container: 'map', style: DEFAULT_STYLE, center: DEFAULT_CENTER, zoom: 13, }); map.addControl(new maplibregl.NavigationControl(), 'top-left'); ``` -------------------------------- ### Install OSRM Dependencies on macOS Source: https://github.com/project-osrm/osrm-backend/wiki/Building-OSRM Install required dependencies for building OSRM on macOS using Homebrew. This includes Boost, CMake, GDAL, and other essential libraries. ```bash brew install boost git cmake libzip libxml2 lua tbb ccache pkg-config brew install GDAL ``` -------------------------------- ### Route Object Example Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/http.md Represents a complete route through waypoints. Includes total distance, duration, geometry, and a breakdown of legs between waypoints. This example uses `geometry=geojson` and `steps=false`. ```json { "distance": 90.0, "duration": 300.0, "weight": 300.0, "weight_name": "duration", "geometry": {"type": "LineString", "coordinates": [[120.0, 10.0], [120.1, 10.0], [120.2, 10.0], [120.3, 10.0]]}, "legs": [ { "distance": 30.0, "duration": 100.0, "steps": [] }, { "distance": 60.0, "duration": 200.0, "steps": [] } ] } ``` -------------------------------- ### Make a Route Query with Buffer Format Source: https://github.com/project-osrm/osrm-backend/blob/master/docs/nodejs/api.md Demonstrates how to initialize OSRM and make a route query using the 'buffer' format for the response. The response is then converted to a UTF-8 string for logging. Ensure the OSRM service is initialized with the correct network file. ```javascript var osrm = new OSRM('network.osrm'); var options = { coordinates: [ [13.36761474609375, 52.51663871100423], [13.374481201171875, 52.506191342034576] ] }; osrm.route(options, { format: "buffer" }, function(err, response) { if (err) throw err; console.log(response.toString("utf-8")); }); ```