We’re building support for external raster data sources in OSRM. This will unlock countless possibilities in OSRM — most immediately for us it means the ability to run elevation-aware routing profiles, letting us better optimize for the way humans really bike or walk.
The OSRM raster source feature is data-agnostic, meaning it’s BYOData — it can consume just about any geo-referenced raster dataset. The elevation case is obvious, where queried values are numeric, but you could also write a routing profile to optimize for any kind of data you have — air quality, crime rates, you name it. Since it’s written natively in C++, it doesn’t introduce the magnitude of slowdown inherent to database queries.
Using an external data source in a routing profile is easy — just as OSRM Lua profiles require a node_function and a way_function, they’ll optionally call a source_function to load a source into memory and a segment_function to query that source per graph segment. So your profile would now have two additional functions that look like this:
<div class="highlight">---------------------------------------------------- Called once to load raster sources into memory.--------------------------------------------------function source_function () -- Define lat/lon min/max and data dimensions from environment variable reads raster_source = load_raster_data( "./srtm_bayarea.asc", LON_MIN, LAT_MIN, LON_MAX, LAT_MAX, NROWS, NCOLS)end---------------------------------------------------- Called per segment to update edge weights.--------------------------------------------------function segment_function (source, target, distance, weight) local sourceData = get_raster_interpolate(raster_source, source.lon, source.lat) local targetData = get_raster_interpolate(raster_source, target.lon, target.lat) local elev_delta = targetData.datum - sourceData.datum local penalize = 0 slope = math.abs(elev_delta / distance) if elev_delta <span class="o">
The OSRM raster source feature is data-agnostic, meaning it’s BYOData — it can consume just about any geo-referenced raster dataset. The elevation case is obvious, where queried values are numeric, but you could also write a routing profile to optimize for any kind of data you have — air quality, crime rates, you name it. Since it’s written natively in C++, it doesn’t introduce the magnitude of slowdown inherent to database queries.
Using an external data source in a routing profile is easy — just as OSRM Lua profiles require a node_function and a way_function, they’ll optionally call a source_function to load a source into memory and a segment_function to query that source per graph segment. So your profile would now have two additional functions that look like this:
<div class="highlight">---------------------------------------------------- Called once to load raster sources into memory.--------------------------------------------------function source_function () -- Define lat/lon min/max and data dimensions from environment variable reads raster_source = load_raster_data( "./srtm_bayarea.asc", LON_MIN, LAT_MIN, LON_MAX, LAT_MAX, NROWS, NCOLS)end---------------------------------------------------- Called per segment to update edge weights.--------------------------------------------------function segment_function (source, target, distance, weight) local sourceData = get_raster_interpolate(raster_source, source.lon, source.lat) local targetData = get_raster_interpolate(raster_source, target.lon, target.lat) local elev_delta = targetData.datum - sourceData.datum local penalize = 0 slope = math.abs(elev_delta / distance) if elev_delta <span class="o">