How many regions does the custom model supports?

How many regions does the custom model supports? I am using it to avoid some areas, and I have tried to use more than one region/polygon inside the 3D coordinates array in the FeatureCollection! It seems to work initially…

I was expecting to avoid all regions in the featureCollection, is not that right?

But for some reason, sometimes it avoids only the first region and completly ignores the others?
Example:

{
    "speed": [
      {
        "if": "in_custom1",
        "multiply_by": "0.5"
      },
      {
        "if": "in_custom1",
        "limit_to": "1"
      }
    ],
    "priority": [
      {
        "if": "in_custom1",
        "multiply_by": "0"
      }
    ],
    "areas": {
      "type": "FeatureCollection",
      "features": [
        {
          "type": "Feature",
          "id": "custom1",
          "properties": {},
          "geometry": {
            "type": "Polygon",
            "coordinates": [
              [
                [-46.670824,-23.510283],
                [-46.647865,-23.529092],
                [-46.679021,-23.518625],
                [-46.670824,-23.510283]
              ], 

              [
 		[-46.771592,-23.566614],
                [-46.769361,-23.553087],
                [-46.714601,-23.515015],
                [-46.696576,-23.521466],
                [-46.771592,-23.566614]
              ],
               
              [
                [-46.714857,-23.587119],
                [-46.73992,-23.592466],
                [-46.760669,-23.569354],
                [-46.728247,-23.56982],              
                [-46.714857,-23.587119]
              ],        
   
              [
                [-46.66428,-23.57661],
                [-46.66971,-23.58173],
                [-46.67624,-23.57347],
                [-46.67248,-23.56969],
                [-46.66428,-23.57661]
              ]
            ]
          }
        }
      ]
    }
  }

The problem is likely that you mixed the order of latitude and longitude. Note, that the POST request requires all coordinate arrays in the order of [longitude,latitude]. (only the GET request uses point=lat,lon but it does not support custom_model)

Not really.! The lat,long are in the correct order inside the geoJson, as well in the query. All the regions appears in the GraphHopper Maps | Route Planner as a polygon (picture below):


In the picture, just he triangle is avoided, and not the others.
If we swap the first polygon (the triangle) by any other polygon it will avoid just that first one and not the others.
Note that also the alternatives routes deviates from first polygon only as well.
I also tried in the https://explorer.graphhopper.com/ tool and postman, all of them gives the same result.
I also noted in some other tests with more polygons, that all polygons were avoided (not by accident or mistake, it was a maze to force deviations). So I could not understand the reason or when GH uses one or more polygons inside the FeatureCollection. It is clear that GH will need to check “point inside the polygon” many times, making an extra effort.

Sorry, I looked only half. The problem is that you did not specify a Polygon but a MultiPolygon and did not say so and we also do not yet support MultiPolygon. Instead you can list multiple Polygons, like you get when you use the “edit” polygon button in GH Maps. E.g. this.

{
  "priority": [
    {
      "if": "in_area1",
      "multiply_by": "0"
    },
    {
      "if": "in_area2",
      "multiply_by": "0"
    },
    {
      "if": "in_area3",
      "multiply_by": "0"
    }
  ],
  "areas": {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                12.906897,
                50.846475
              ],
              [
                12.91445,
                50.848642
              ],
              [
                12.919428,
                50.845716
              ],
              [
                12.911704,
                50.842464
              ],
              [
                12.906897,
                50.846475
              ]
            ]
          ]
        },
        "properties": {},
        "id": "area1"
      },
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                12.910357,
                50.832003
              ],
              [
                12.915507,
                50.828533
              ],
              [
                12.927008,
                50.834388
              ],
              [
                12.919112,
                50.840242
              ],
              [
                12.910357,
                50.832003
              ]
            ]
          ]
        },
        "properties": {},
        "id": "area2"
      },
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                12.897464,
                50.845158
              ],
              [
                12.905876,
                50.845267
              ],
              [
                12.907764,
                50.840172
              ],
              [
                12.901069,
                50.838763
              ],
              [
                12.897464,
                50.845158
              ]
            ]
          ]
        },
        "id": "area3"
      }
    ]
  }
}

And instead of multiple conditions you can use a single one:

{
   "if": "in_area1 || in_area2 || ...",
   "multiply_by": "0"
}
1 Like

That’s absolutely right! I was using MultiPolygon of GeoJson instead of listing them separately!

It worked nicely now!

Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.