A Python-based solution for integrating historical traffic data with Valhalla's routing engine to improve ETA accuracy for Careem's ride-hailing platform in Amman, Jordan. This implementation enhances Valhalla's routing capabilities without modifying its core C++ codebase.
- Python 3.x
- Osmium Tool
- Valhalla routing engine
- OSRM (for validation)
Follow the gis-ops guide for installing Valhalla on Ubuntu.
For basic Valhalla configuration and running instructions, see the gis-ops guide for running Valhalla.
After installing and configuring Valhalla:
- Clone the repository:
git clone https://github.com/muhammadazzazy/osm-valhalla-traffic-mapper.git cd osm-valhalla-traffic-mapper
- Download Jordan OSM data:
./scripts/download_jordan_osm.sh
- Extract Amman region:
./scripts/extract_amman_data.sh
osm-valhalla-traffic-mapper/
├── src/
│ ├── routes.py # OSRM vs Valhalla distance comparison logic
│ ├── graph_id.py # Python implementation of the to_string functionality provided by Valhalla
│ ├── predicted_speeds.py # Historical speeds conversion to DCT-II functionality
│ ├── main.py # Traffic CSV file preparation and writing utilities
│ ├── get_etas.py # Valhalla ETA extraction functionality
│ ├── speeds_checker.py # Speed-limit violation validator
│ ├── speeds_extractor.py # Speed data extraction from JSON
│ └── valhalla_way_id_mapper.py # OSM way ID mapping tools
│ └── valhalla_monitor.py # Traffic CSV monitoring for automating updates to routing graph
├── scripts/
│ ├── download_jordan_osm.sh # Script to download Jordan OSM data
│ └── extract_amman_data.sh # Script to extract Amman region data using Osmium
routes.py
: Validates routing accuracy by comparing Valhalla and OSRM distance calculationsget_etas.py
: Extracts and processes ETAs from Valhallagraph_id.py
: Handles Valhalla graph ID conversion and processing
predicted_speeds.py
: Converts historical speed data using DCT-II functionalityspeeds_checker.py
: Validates speed data against Jordan's traffic regulationsspeeds_extractor.py
: Extracts speed data from JSON format
main.py
: Prepares and writes traffic CSV filesvalhalla_way_id_mapper.py
: Maps OSM way IDs to coordinates
download_jordan_osm.sh
: Downloads latest Jordan OSM dataextract_amman_data.sh
: Extracts Amman-specific region using Osmium
The system integrates with Valhalla through:
- Graph ID conversion matching Valhalla's internal format
- OSM way ID mapping for coordinate pairs
- Batch processing support for routing requests
Processes historical traffic data to enhance ETA accuracy:
- Processes 2016 weekly speed patterns (5-minute intervals)
- Extracts day/night speed variations
- Validates against local speed limits
- Prepares data in Valhalla-compatible format
Contributions welcome via pull requests.
- OpenStreetMap contributors
- Valhalla and OSRM teams