Shanghai OSRM Travel Time Visualization
This project generates a high-resolution travel time heatmap from a given origin point in Shanghai using a locally deployed OSRM (Open Source Routing Machine) backend.
It builds a uniform grid of latitude-longitude coordinates, queries OSRM for estimated driving times, filters out water regions, and visualizes the results on an OpenStreetMap base map.
Click HERE to go to the project.
⚙️ Parameters
At the top of runpic.py, you can adjust the following parameters to control the experiment:
| Parameter | Description | Default |
|---|---|---|
OSRM_URL |
URL of the local OSRM server | "http://localhost:5000" |
PROFILE |
OSRM routing profile (driving, walking, cycling) |
"driving" |
ORIGIN_LAT |
Latitude of the origin point (e.g., SJTU dormitory) | 31.198606 |
ORIGIN_LON |
Longitude of the origin point | 121.432725 |
LAT_MIN, LAT_MAX |
Latitude bounds for the analysis region | 30.7, 31.35 |
LON_MIN, LON_MAX |
Longitude bounds for the analysis region | 121.18, 121.86 |
STEP |
Grid step in degrees (smaller = denser grid, slower runtime) | 0.001 |
output_csv |
Path to save raw travel-time data | "osrm_times.csv" |
output_png |
Path to save the final visualization | "osrm_times_map_shanghai.png" |
🧭 How to Use
1. Prepare Environment
Install required dependencies (Python ≥3.10):
1 | |
2. Start Local OSRM Server
Download Shanghai OSM data and build the routing graph:
1 | |
Leave the OSRM server running on port 5000.
3. Run the Script
In another terminal:
1 | |
The script will:
- Generate a uniform geographic grid across Shanghai.
- Query OSRM in batches for travel times from the origin point.
- Remove grid points falling inside Shanghai’s rivers and coastal waters.
- Render and save a colored travel-time map.
4. Outputs
- Map image:
osrm_times_map_shanghai.png— A heatmap of travel times:- Blue → fast / close
- Yellow → medium
- Red → slow / distant
(Capped at 3600 s; all values above appear as red)
5. Notes
- The base map tiles are fetched from OpenStreetMap Mapnik.
- OSMnx is used to retrieve Shanghai’s administrative boundary and water polygons.
- You can adjust
cmap,vmin,vmax, andalphato tune visualization style. - Increasing grid resolution (
STEP) will produce finer results but may increase runtime.
Shanghai OSRM Travel Time Visualization
https://cloudflipper.github.io/2025/11/09/Shanghai-OSRM-Travel-Time-Visualization/