Search Shortcut cmd + k | ctrl + k
valhalla_routing

DuckDB extension for routing and travel time calculations using Valhalla routing engine

Maintainer(s): onnimonni

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.4.4 1.4.5 1.5.5 1.5.6 2.0.0
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

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 tiles
  • SET 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 BLOB
  • travel_time_matrix(lats1, lons1, lats2, lons2, costing) - Distance/duration matrix
  • travel_time_locate(lat, lon, costing) - Snap coordinates to road network
  • travel_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

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  

Overloaded Functions

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

name description input_type scope aliases typed_value
temp_directory Set the directory to which temporary files are written. VARCHAR GLOBAL [] post.db.tmp
valhalla_tiles Path to Valhalla tiles directory or config file VARCHAR GLOBAL []