Avoid or include a large amount of POIs in route-planning

Hello there!

I am new to Graphhopper and wanted to ask how I should best tackle two specific use-cases:

I want to create a small app that allows users to plan routes from point A to B, just within one city (Vienna, Austria). Within this city, I have a large amount of points with lat/long, around 228.000, of different categories.

The route planning should either:

  • Avoid the vicinity of certain categories of points along the route, if possible.
  • Visit certain categories of points along the route, if it is not a big detour.

One route planning would only target a few categories, e.g. avoid points of categories A, B, C, D (11.153 points), or visit points of category F (9.400 points), along a route from A to B.

I thought I would start with avoiding certain points. I have looked at the blog post Examples for customizing routes, where it shows how a single polygon can be avoided.

Just to get a Proof-of-Concept going, I have tried to create a custom model to avoid multiple polygons. More specifically, I have drawn a 10m square around all points from one category and included some of them in the custom model. It looks like this:

{
    "priority": [
      {
        "if": "in_avoid",
        "multiply_by": "0"
      }
    ],
    "areas": {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "id": "avoid",
          "geometry": {
            "type": "Polygon",
            "coordinates": [
              [
                [
                  16.302208745133793,
                  48.223221470959245
                ],
                [
                  16.302478416713324,
                  48.223221470959245
                ],
                [
                  16.302478416713324,
                  48.22340113401607
                ],
                [
                  16.302208745133793,
                  48.22340113401607
                ],
                [
                  16.302208745133793,
                  48.223221470959245
                ]
              ],
              [
                [
                  16.302200703283482,
                  48.223171196872364
                ],
                [
                  16.30247037459815,
                  48.223171196872364
                ],
                [
                  16.30247037459815,
                  48.22335085992919
                ],
                [
                  16.302200703283482,
                  48.22335085992919
                ],
                [
                  16.302200703283482,
                  48.223171196872364
                ]
              ],
              ....
            ]
          }
        }
      ]
    }
  }

But while the squares denoting the points are shown successfully on the map, it doesn’t seem to work. See this demo.

Additionally, I was only able to include a small number of points in the request, as it results in a status 400 error: “Custom model cannot use more than 100 000 characters.” or 414: “Request-URI Too Large” very quickly. Of course, it doesn’t make sense to submit ten-thousands of polygons with each request. It was just meant as a POC, to see if I could avoid multiple points with Graphhopper. Could someone point out what I am doing wrong? How do I successfully avoid multiple squares? Is there a different, more suitable approach?

For any further development, I would need to setup my own Graphhopper instance, where the points with categories are already saved on the server and the request only submits “avoid category A,B,C” or “include category F”. Is something like this possible? Can you add a dataset of polygons, each with a category property to the Graphhopper instance, and then configure a request to include or avoid those polygons based on their property?

I am thankful for any pointers in the right direction :+1:

But while the squares denoting the points are shown successfully on the map

As stated in the documentation: for an “area” at the moment currently only a single Polygon is supported. However you could create multiple areas and use them in the custom model for exclusion/avoidance.

Additionally, I was only able to include a small number of points in the request, as it results in a status 400 error: “Custom model cannot use more than 100 000 characters.”

We placed a limit for the custom model at some point to avoid certain types of attacks for public facing GraphHopper services. You can reduce the precision of the coordinates or reduce the number of points per polygon to avoid this.

The “Request-URI Too Large” error should not happen as the /route endpoint with custom_model is only POST request. (probably you tried GH Maps? Then this error won’t occur in production)