Difference between snap_prevention and custom_model

Hi there,

Does someone knows the difference between snap_prevention and custom_model for preventing a certain road environment? I’ve trying to understand to difference between them reading the documentation, but I got no success on it.

E.g. To certain route I need to avoid FERRIES, using snap_prevention, this doesn’t work, but on custom_model does.

Can anyone tell me the difference between them?

Thanks you before hand!

Snapping is the process of finding the closest road for the query point and snap_prevention configured to which road classes or environment it is allowed to snap. E.g. copy&paste the following JSON into the API explorer:

{
  "points": [
    [
      13.668919,
      51.07263
    ],
    [
      13.520002,
      51.062436
    ]
  ],
  "snap_preventions": [
    "motorway"
  ],
  "profile": "car"
}

click send and compare with the response when you remove the snap_preventions array: the start segment is different, but note that the route itself still contains motorway with the snap prevention of motorway.

Now. A custom_model controls the routing process itself (and if you exclude certain roads completely also the snapping process is changed). So e.g. if you want to exclude motorways for your route you do:

{
  "points": [
    [
      13.668919,
      51.07263
    ],
    [
      13.520002,
      51.062436
    ]
  ],
  "profile": "car",
  "ch.disable": true,
  "custom_model": {
  "priority": [
    {
      "if": "road_class == MOTORWAY",
      "multiply_by": "0.0"
    } ]
  }
}

But as soon as you specify a (small) positive number for the multiplication the snapping to motorways will be allowed and still motorways will be avoided on the route. E.g. replace the number 0.0 with 0.1 and see that it snaps to the motorway but leaves the motorway as fast as possible.

Also note that the custom_model requires to use ch.disable=true which activates a different and slower algorithm. (You can avoid this via using the Profiles API which is currently in private beta.)

Hope this helps :slight_smile: