Restricted routing zones specified by a polygon

How can I find a route that considers certain restricted areas (such as private territories or environmental no-drive zones) that is specified by a polygon? I want to be able to enable/disable the restriction at query time. I found “spatial rules” in the config file, but I am not sure if it’s the right solution.

Yes, that might be the right solution if you know how to customize the Java code. Currently only the opposite via block_area is possible out of the box.

Is there any documentation or code example how to start?

See the web API docs

There is not much about spatial rules in the docs, but I think I got a good understanding about them by reading the source code. Is there any way to enable/disable them at query time? The docs say that you need to re-import your graph after enabling spatial rules. Does it mean that it cannot be selectively switched on at query time?

Spatial rules is pretty new and currently only really useful or customizable if you code in Java. E.g. have a look into the DataFlagEncoder that stores an ID per country. The same could be done for your restricted areas. Then in a custom Weighting you can easily enable or disable or change costs for an edge with such an information attached, i.e. you should be able to change this per request (if you disable CH).

How about block_area? What do you think about implementing a polygon Shape and allowing parseBlockArea to parse polygons? parseBlockArea could also accept the id of the polygon only since the boundaries are already encoded in OSM files.

Yes, sure, this is also possible and any contribution is welcome :slight_smile: !

Do you have any idea the boundaries inside the OSM file are kept in storage or not? I want to be able to find the boundary by its id. I don’t think passing the whole polygon with any query is a good idea.
I seems to me that they are not kept. If that’s right, what is a good way to store the boundaries?

Probably via relations but I have on idea how they are tagged. You can search the OSM wiki or use

See the PR #1306

1 Like