Configs2026年7月3日·1 分钟阅读

OSRM — High-Performance Open Source Routing Engine

OSRM computes shortest paths on road networks using OpenStreetMap data, delivering sub-second route calculations for driving, cycling, and walking.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
OSRM Overview
先审查命令
npx -y tokrepo@latest install 30d7ed39-767a-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

OSRM (Open Source Routing Machine) is a C++ routing engine that computes fastest paths on road networks derived from OpenStreetMap. It preprocesses map data into a compact graph representation, enabling sub-second responses for route, table, match, trip, and nearest queries.

What OSRM Does

  • Computes point-to-point routes with turn-by-turn instructions
  • Generates distance and duration matrices for many-to-many queries
  • Matches GPS traces to road segments via map matching
  • Solves traveling salesman approximations with the trip service
  • Finds nearest road segments for snapping coordinates to the network

Architecture Overview

OSRM uses a multi-level Dijkstra (MLD) or contraction hierarchies (CH) algorithm. During preprocessing, the road graph is extracted from OSM PBF files using Lua profiles that define vehicle-specific speeds and restrictions. The preprocessed data is loaded into memory by the HTTP server (osrm-routed), which handles concurrent requests via a thread pool and responds with JSON including geometry, duration, and step-by-step instructions.

Self-Hosting & Configuration

  • Run with Docker using the official ghcr.io/project-osrm/osrm-backend image
  • Download region-specific OSM extracts from Geofabrik or planet.openstreetmap.org
  • Customize routing behavior by editing Lua profiles for car, bicycle, or foot
  • Use MLD algorithm for faster preprocessing and comparable query speed to CH
  • Deploy behind a reverse proxy with caching for production workloads

Key Features

  • Sub-second response times even for cross-country routes on a single machine
  • HTTP API compatible with the OSRM API v1 specification used by many frontends
  • Lua-scripted profiles allow customizing speeds, turn penalties, and access restrictions
  • Supports alternative routes, waypoints, and route annotations (speed, duration per segment)
  • Compact preprocessed data fits continental datasets in moderate RAM

Comparison with Similar Tools

  • GraphHopper — Java-based, supports more profiles out of the box, easier customization
  • Valhalla — multi-modal routing with transit support, dynamic costing, tiled data
  • Google Directions API — cloud service, broader data coverage, usage-based pricing
  • pgRouting — SQL-based routing inside PostgreSQL, slower but tightly integrated with spatial queries

FAQ

Q: How much RAM does OSRM need? A: A planet-wide dataset requires roughly 64 GB RAM. Country-level extracts typically need 2-8 GB.

Q: Can OSRM handle real-time traffic? A: OSRM uses static edge weights. For live traffic, you need to reprocess data or use tools that support dynamic costing.

Q: Does it support public transit routing? A: No. OSRM focuses on road-network routing. For multi-modal transit, consider Valhalla or OpenTripPlanner.

Q: How often should I update the map data? A: Reprocess from a fresh OSM extract weekly or monthly depending on how current your routes need to be.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。