Open Street Map Info and tools
Tools
Visual tool to create polygon (geoJSON): geojson
Explore maps with specific OSM tools: overpass
How to avoid certain roads/streets in OSM?
1. Leverage OSM Tags
OSM has a rich tagging system. You can use these tags to identify and avoid roads unsuitable for your vehicle:
maxheight: Specifies the maximum allowed height for vehicles.
maxweight: Specifies the maximum allowed weight for vehicles.
maxlength: Specifies the maximum allowed length for vehicles.
access: Controls general access restrictions (e.g., "no" for private roads, "delivery" for delivery vehicles only).
vehicle: Provides more specific restrictions on vehicle types (e.g., "no" for all vehicles, "car" for cars only).
2. Modify the OSRM Profile
OSRM uses profiles to determine routing preferences. You can customize a profile to incorporate vehicle restrictions:
-
Lua scripting: OSRM profiles are defined using Lua scripts. You can modify these scripts to check relevant OSM tags and assign high penalties (or make roads completely impassable) based on your vehicle's dimensions.
-
Example: Lua
function way_function (way, result)
-- Get the maxheight tag from OSM data
local maxheight = tonumber(way:get_value_by_key("maxheight"))
-- If maxheight is less than your vehicle's height (e.g., 3 meters), penalize the road
if maxheight and maxheight < 3 then
result.duration = result.duration * 1000 -- Increase travel time significantly
end
end
3. Pre-process OSM Data
For more complex scenarios, you might need to pre-process the OSM data:
Filter roads: Use tools like osmosis or osmfilter to remove roads that don't meet your vehicle's requirements before feeding the data to OSRM. Create custom tags: If the existing OSM tags don't fully capture your needs, you can add custom tags to the OSM data using tools like JOSM.
- External Routing Services
Consider using routing services that offer more advanced vehicle restriction options:
GraphHopper: Provides a flexible routing engine with support for various vehicle profiles and restrictions.
HERE Maps: Offers a Routing API with truck routing capabilities that consider vehicle dimensions and road restrictions. Important Notes
Using OSM filtering options
osmfilter
osmfilter is a command-line tool that allows you to filter OSM data based on tag values. Here's how you can use it to exclude roads with a maxheight less than your vehicle's height (e.g., 3 meters):
This command does the following:
osmfilter portugal.osm: Specifies the input OSM file (portugal.osm).--keep="highway=* and maxheight >= 3": Keeps only ways (roads) that have a highway tag (meaning they are roads) and a maxheight tag with a value greater than or equal to 3.-o=filtered_portugal.osm: Writes the filtered data to a new OSM file (filtered_portugal.osm).
osmosis
osmosis is another command-line tool that provides more advanced filtering and data manipulation options. You can use it to create more complex filters, such as combining multiple tag conditions or filtering based on relations:
osmosis \
--read-xml portugal.osm \
--tf accept-ways highway=* \
--tf reject-ways maxheight<3 or maxweight<10000 \
--used-node \
--write-xml filtered_portugal.osm
This command:
- Reads the
portugal.osmfile. - Accepts all ways with a
highwaytag. - Rejects ways with a
maxheight less than 3 meters or a maxweight less than 10,000 kg. - Includes the nodes used by the remaining ways.
- Writes the filtered data to
filtered_portugal.osm.
Advance filtering with osmosis
Create a tag filter file: Create a text file (e.g., tag_filter.txt) with lines like this:
- create atag filter file:
- use --tf option:
`bash
osmosis \
--read-xml portugal.osm \
--tf reject-ways file=tag_filter.txt \
--used-node \
--write-xml filtered_portugal.osm