-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Using location dependent data in profiles
Prepare location-dependent data in GeoJSON format, e.g. country names using query-overpass
:
echo '[out:json];rel["boundary"="administrative"]["admin_level"="2"]["ISO3166-1:alpha3"];out geom;' | \
query-overpass --flat-properties > countries.geojson
grep -oP '"ISO3166-1:alpha3":"[A-Z]{3}"' countries.geojson | sort > ISO3166-1:alpha3.txt
wc -l ISO3166-1:alpha3.txt
217 ISO3166-1:alpha3.txt
Add location-dependent handling in a profile, e.g. print way ids and country names in process_way
:
print ('Way ' .. way:id() .. ' in ' .. way:get_location_tag('name') ..
' [' .. way:get_location_tag('ISO3166-1:alpha3') .. ']')
Running OSRM with --location-dependent-data
command line argument will produce output:
wget http://download.geofabrik.de/europe/monaco-latest.osm.pbf
osrm-extract -p ../profiles/car.lua --location-dependent-data=countries.geojson monaco-latest.osm.pbf
...
Way 4097656 in Monaco [MCO]
Way 4098197 in Monaco [MCO]
Way 4212554 in France [FRA]
Way 4224972 in Monaco [MCO]
...
Way 4230116 in Monaco [MCO]
Way 4230117 in Monaco [MCO]
Way 4230118 in Monaco [MCO]
Way 4230119 in Monaco [MCO]
Way 4230122 in Monaco [MCO]
Way 4230126 in France [FRA]
Way 4230182 in France [FRA]
Way 4230185 in Monaco [MCO]
Way 4230186 in Monaco [MCO]
Way 4230187 in Monaco [MCO]
Way 4230891 in Monaco [MCO]
Way 4534918 in France [FRA]
Way 4978262 in France [FRA]
...
To speed up data extraction with location-dependent tags, one can pre-process OSM files by adding locations to ways with osmium
and avoid using the internal locations cache:
osmium add-locations-to-ways --keep-untagged-nodes monaco-latest.osm.pbf -o monaco-latest-loc.osm.pbf
osrm-extract -p ../profiles/car.lua --location-dependent-data=countries.geojson \
--use-locations-cache=no monaco-latest-loc.osm.pbf
The pre-processing step adds node locations directly into OSM ways, so the internal cache is not need. This reduces memory consumption by osrm-extract
, but increases OSM PBF file size.
--use-locations-cache=no
is used with an OSM file that was not pre-processed then an exception will be thrown
osrm-extract -p ../profiles/car.lua --location-dependent-data=countries.geojson \
--use-locations-cache=no monaco-latest.osm.pbf
...
terminate called after throwing an instance of 'sol::error'
what(): lua: error: invalid location