Custom routing with areas to block road

Hello,

I’m using V2.3 of the API on local server and test it with postman.
I can block a road area with customizable routing and it works fine with Polygon type but i don’t know if it’s possible to define a block area only with one Point ? (or a LineString)

Areas with polygon : works

    "areas": {
    "my_area": {
        "type": "Feature",
        "properties": {},
        "geometry": {
            "type": "Polygon", 
            "coordinates": [[
                [ -0.7127972099767277, 44.739707842549166 ],
                [ -0.7123227673290969, 44.739995613498024 ],
                [ -0.7123675389242864, 44.74001452855458 ],
                [ -0.7128260195249365, 44.73973072600916 ],
                [ -0.7127972099767277, 44.739707842549166 ]
            ]]
        }
    }
}

Areas with point : no error but doesn’t work

"areas": {
    "my_area": {
        "type": "Feature",
        "properties": {},
        "geometry": {
            "type": "Point", 
            "coordinates": 
                [ -0.7487185935645827, 44.71070580340984 ]
        }
    }
}

I’ve tested also block_area parameter and it works with only one point.

Thanks for your answer

The geometry is casted in a Polygon, then it tests whether the edge of the graph is in the polygon or not.
There is no check to avoid to load point instead of polygon.

Ok, thanks, i don’t know if i can find a workaround to fix that, maybe find a way to construct à little polygon with only one source point

Why do you want to ‘block a single point’? What kind of result do you expect?

I mean if you want to avoid an event on the road, so you want to avoid a certain point on the road localized with lat/long.

When i use the endpoint /route with this json, an alternative route is calculated to avoid this point and it works fine.

{
"block_area": "44.694596625778644,-0.7666432735494823",
"ch.disable": true,
"points": [
	[
		-0.6005437,
		44.859633
	],
	[
		-1.1827195,
		44.6489763
	]
],
"points_encoded": false,
"vehicle": "car"

}

But if i use the custom endpoint /custom-route (my example in my first post), i lost this possibility to define an area to avoid a part of a road with only one point define on it, that’s why i ask if this possibility can be done with custom-route (it seems to be not possible, only Polygon is available, not Point, in Geojson area)

Ah I see. I don’t know why custom-route is not working with a single point. But honestly I don’t know why block_area does work with a single point either. The idea is to create an ‘area’ and avoid edges that are within this area. Why do you not use a circle with a small radius?

But I certainly agree this should be consistent. If its working for block_area it should also work for custom-route. The ‘area’ feature of custom-route should replace block_area entirely at some point.

I see block_area as a legacy feature and only because we (incorrectly) supported blocking points (IMO a point is not an area), I do not see a reason to support it now for custom routing especially as instead of a single point a small bounding box or triangle could be used (a circle+radius won’t work as a Polygon is required, I think)

btw @MichelD did you get an understandable error message when using a Point?

Ok, I thought there might be some reason block_area supports single points that I was not aware of. Otherwise I agree a point is not an area so it should not be supported. But supporting circles for custom-route would be nice?

Circle support would be really nice, yes.

The problem with circles is that GeoJSON and the Polygon class from JTS do not support it (for Polygon this even makes sense :wink: ). But surely there is a way to do it but I see it as a new feature.

Thanks for all this details.

I don’t have error when i’m using Point instead of Polygon in the Geojon Post body for custom-route endpoint (in postman), just the Point is not use in the path calculation result.

Unfortunate that Point is not supported with new Areas definition, i find this feature very useful with block_area in case i have only one point localized information and not an area, so, i have to find a workaround with that.

A simple workaround would be using a small rectangle for example?

Yes, it’s a possibility, not so easy as it seems i think

Why is this not easy? Maybe I still did not understand why you are trying to block single points?

Imagine you travel on a road and there is an accident in front of you and you want to notify it with your phone, the only coordinates you can send comes from the localization of your phone, one point with latitude/longitude, and with this localized information an application wants to block this part of road.
You need to be precise enough to not block the other side of the road for example.

Ok blocking a road in only one direction is an interesting use-case indeed. But this does not work with block_area either, does it? Most roads in GraphHopper are represented by a single edge representing both directions and thus they can only be blocked or not blocked, but not blocked in a single direction. Also block_area with a single point does not really block a single point (what would this mean anyway?), but uses a circle with a default 5m radius. So if you want to achieve the same effect as block_area with a single point using route-custom maybe the best you can do is drawing a 5m square around your point.

I made some tests using block_area with one point and it seems to work, i mean only one side of the road is affect (one side of a motorway is blocked for example), i was really surprised, but, maybe i haven’t tested enough :laughing:

Which point/road was it?

After additional tests, i think it works when road is clearly divide in two sides : see my pics below, a block_area (marker) with one point on the bad side of the road doesn’t affect the path result (green path), if i place it in the other side (on the green path), then the result path is changed to avoid this point (the block point works)

Yes for these kind of roads graphhopper uses two one way edges (one for each direction) and blocking them in isolation is possible. But using block_area with a single point should be almost the same as using route-custom with a 10m square. The only difference is that block_area uses a circle with a 5m radius.