Smallest polygon possible to avoid road

Hey,

what would be the smallest polygon possible to avoid (and/or at least reduce speed of) a certain road but potentially still allow (i,e) crossing to the other sidewalk by foot?

A single point doesn’t seem to do the job…

M.

1 Like

@kochen,

Just found a thread that confirms this behavior pretty clearly:

As Peter mentioned there, GraphHopper doesn’t support using a single Point geometry inside the areas section of a custom model.

You need to create a small Polygon (or MultiPolygon) around the location you want to affect deally large enough to intersect the road segment you’re trying to penalize or avoid.

That lines up with my tests too tiny polygons work fine as long as they touch the target edge.

Thanks!
Since I’m looking for foot routing, this sounds like a challenge to be able to block one side of the road, but not the other - specially with more narrow streets.

By the way, is there “sidewalk” information, i,e 2 edges from A to B or do we have a way to differentiate between A-to-B (one side of the street) and A’-to-B’ (the other)?

So basically, I’d have to create a small enough polygon to block one side and hope it’s not too big to block the other side.

M.

1 Like

@kochen

Yeah, that’s the tricky part in OSM, a way is basically just a centerline defined by ordered nodes, not separate left/right sides of a street.
Docs: Way - OpenStreetMap Wiki

So when GraphHopper imports the data, it builds edges along that same centerline. Unless the sidewalks are mapped as independent ways (like highway=footway), the router can’t really tell which side you mean.

If you only want to discourage routing through that area instead of fully blocking it you can use something like:

“priority”: [
{ “if”: “in_area.restricted_zone”, “multiply_by”: “0.7” }
]

That will still allow crossing if needed but make it less likely to choose that segment.

But maybe I’m missing some detail i’m a relatively new GraphHopper user.

That totally makes sense - thanks!

Is there a way to know the width of ways (edges), so I can carefully calculate a “fitting” polygon?

Also, what is this annotation: in_area.restricted_zone?
I know in_areaX can be used, but I didn’t see this before…

By definition, GraphHopper doesn’t calculate the physical width of a road during routing**.**
What you can use instead are the OSM attributes such as max_width or road categorization fields like road_class and road_environment.

The max_width tag represents legal or physical width restrictions, and there’s an example of its usage in the official config-example.yml file within the GraphHopper repository.

For example, road_class distinguishes highways, primary, secondary, and residential roads — which can help you approximate or prioritize wider vs. narrower routes even without exact width data.

Regarding in_area.restricted_zone, it’s a condition from the Custom Model that lets you apply routing rules inside specific polygons, such as reducing priority or penalizing certain areas.

Please avoid using LLMs without confirming that it works properly. The notation you suggested does not work, due to the dot and the format is just in_areaX as @kochen mentioned and then the id of the area has to be area1. (or more precisely it is in_<the_area_id>)

2 Likes

Thanks @Dev-Pablo

1 Like

Thanks for confirming this @karussell.