No-Go Zone with Custom Model may find a way in sometimes

Hi there,
Custom model was a great feature to control the route. I am currently using it as a No-Go zone, so my model is something like:

"speed": [
    {
      "if": "in_custom1",
      "multiply_by": "0.0"
    },
    {
      "if": "in_custom1",
      "limit_to": "0.0"
    }
  ],
  "priority": [
    {
      "if": "in_custom1",
      "multiply_by": "0.0"
    }
  ],
  areas...

In a example where we want a route from origin to a destination, in which one of them is inside a No-Go area and the other not, we would expect to get a NO connection between them. And indeed sometimes I get a response: “Connection between locations not found”, but sometimes a connection is found, just like the example below. It depends only in the origin and destination locations, changing just a bit it’s lat or long may change from existing or not a connection/route.

Of course, there is a dashed segment which is not accounted for in the metrics (distance and time).

example 1, connected

example not connected:
example not connected

Could not post it… but play around with points and you may build other weird examples, like one with both points near enough each other, both inside the No-Go region, and near the border, they will be connect somehow.

What makes it GH decides when to connect them or not? What are the limits for this dashed segment? How can I be sure, looking in the response body, what is happening (assuming I don’t know a priori that one of the points are inside the No-Go area)

Thank you very much!

You can check if the point is in the polygon before you send the request.

The point snaps to other locations outside the area until a distance of approx 1km.

Or you can check if the distance of the point to its corresponding “snapped point” in the snapped_waypoints array of the JSON is too large, then you could e.g. reject the route result.

Thank you.
I’ve got this encoded “snapped_waypoints”: “`er{k@rzbcxAgfmC_sD|fDt^” from the example above and I am not being able to convert it back to lat long valid values (from -180 to +180)…problably doing something wrong. But is it possble to get it in the request answer in the lat long format?

Also, snappoint should be for on both points/endings, origin and destin, like in this example 2 points to snap
but the is only one output: “snapped_waypoints”: “`er{k@rzbcxAgfmC_sD|fDt^” (which I could no convert as well, problably doing something wrong)

If this is not possible I will try the look ahead point inside the custom area.

If the snapped_waypoints array is encoded the points array is encoded too and can be decoded with the same polyline decoding algorithm: graphhopper/web-api/src/main/java/com/graphhopper/jackson/ResponsePathDeserializerHelper.java at master · graphhopper/graphhopper · GitHub

Or disable encoding via "points_encoded": false.

1 Like