DuckDB extension for routing and travel time calculations using Valhalla routing engine
Maintainer(s):
onnimonni
Installing and Loading
INSTALL valhalla_routing FROM community;
LOAD valhalla_routing;
Example
-- Load extensions
INSTALL httpfs; LOAD httpfs;
INSTALL spatial; LOAD spatial;
LOAD valhalla_routing;
-- Download and build tiles (Pure SQL!)
SELECT valhalla_build_tiles(
'https://download.geofabrik.de/europe/monaco-latest.osm.pbf',
'./monaco_tiles'
);
-- Load tiles
SET valhalla_tiles = './monaco_tiles';
-- Calculate route
SELECT
round(r.distance_km, 1) as km,
round(r.duration_minutes, 1) as minutes,
ST_NPoints(r.geometry) as waypoints
FROM (
SELECT valhalla_route(
ST_Point(7.4275, 43.7397), -- Casino Monte-Carlo
ST_Point(7.4254, 43.7308), -- Oceanographic Museum
'auto'
) as r
);
About valhalla_routing
DuckDB Valhalla Routing Extension
Point-to-point routing with distance, duration, and geometry using the Valhalla routing engine.
Key Features (v0.2.0)
- Pure SQL Workflow: Download and build tiles entirely from SQL using
valhalla_build_tiles() - Smart Configuration: Use
SET valhalla_tiles = './path'to load routing data - Flexible Input: Accepts WKT strings, WKB blobs, or GEOMETRY types
- GEOMETRY Output: Returns proper GEOMETRY types (via macro) or WKB blobs
- Multi-Mode Routing: Supports auto, bicycle, pedestrian, truck, bus, taxi, motor_scooter
- Matrix Queries: Calculate N×M travel time matrices
- Spatial Integration: Works seamlessly with DuckDB spatial extension
Functions
Tile Management (NEW in v0.2.0):
valhalla_build_tiles(pbf_url, output_dir)- Download PBF and build routing tilesSET valhalla_tiles = 'path'- Load tiles (auto-detects valhalla.json)
Routing:
valhalla_route(from, to, costing)- Returns GEOMETRY type (recommended)valhalla_route_wkb(from, to, costing)- Returns WKB BLOBtravel_time_matrix(lats1, lons1, lats2, lons2, costing)- Distance/duration matrixtravel_time_locate(lat, lon, costing)- Snap coordinates to road networktravel_time_request(action, json)- Raw Valhalla JSON API
Quick Start (100% Pure SQL)
-- Build tiles from HTTP URL
SELECT valhalla_build_tiles(
'https://download.geofabrik.de/europe/monaco-latest.osm.pbf',
'./tiles'
);
-- Load and route
SET valhalla_tiles = './tiles';
SELECT valhalla_route(ST_Point(7.42, 43.73), ST_Point(7.43, 43.74), 'auto');
Documentation
- README.md - Quick start and API reference
- ITALY.md - Complete Italy dataset guide
- examples/ - Ready-to-use examples
Datasets
Tested with:
- Italy (2.4 GB tiles): Rome, Milan, Venice, Florence
- Estonia: Tallinn-Tartu examples
- Monaco: Test data
Download OSM extracts from Geofabrik
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| travel_time | scalar | NULL | NULL | |
| travel_time_is_loaded | scalar | NULL | NULL | |
| travel_time_load_config | scalar | NULL | NULL | |
| travel_time_locate | scalar | NULL | NULL | |
| travel_time_matrix | table | NULL | NULL | |
| travel_time_request | scalar | NULL | NULL | |
| valhalla_build_tiles | scalar | NULL | NULL | |
| valhalla_route_wkb | scalar | NULL | NULL |
Added Settings
| name | description | input_type | scope | aliases |
|---|---|---|---|---|
| valhalla_tiles | Path to Valhalla tiles directory or config file | VARCHAR | GLOBAL | [] |