V2 API parameter for OSM restrictions?


#1

What is an API v2 parameter to force the service to take restrictions into account. I have tried optimized=false or preference=recommended, no result. E.g. right only restriction is ignored:
https://api.openrouteservice.org/v2/directions/driving-car?api_key=mykey&start=8.69276,49.415092&end=8.692138,49.414484&preference=recommended


#2

Yeah, there’s unfortunately only a hacky way to do this and not with GET. You’ll have to use POST for this:

Just specify some options and it’ll turn off speed-up, i.e. contraction hierarchies. Try {"options": {"avoid_countries": [1]}}, which would try to avoid Afghanistan. Or try another country you definitely don’t want to pass:


#3

@nils, thank you. preference=recommended worked with POST request. At least setting the option gives a different route .


#4

Think I misread. What kind of restrictions are you looking for? Turn restrictions?

recommended helps triggering turn restrictions I think, but could have some side effects I’m still not clear about. It might be fastest with turn restrictions. But probably more complicated than that. I think @HendrikLeuschner can help here.


#5

Yes, I want a route which respects https://wiki.openstreetmap.org/wiki/Relation:restriction#Road_signs.


#6

You currently should have the option to turn off contraction based speedups by using avoid countries as Nils said, or using e.g. avoid ferries. Contraction based speedups have no turn restrictions at the moment. It should trigger the use of ALT.
Does it produce the results youre looking for that way?


#7

@HendrikLeuschner, I managed to get a correct route complying with turn restriction using POST API :

import requests
api_key=“my key”

url = ‘https://api.openrouteservice.org/v2/directions/driving-car/geojson
payload = {
‘coordinates’: [[8.69276,49.415092],[8.692138,49.414484]]
, ‘preference’ : ‘recommended’
}

import json
r = requests.post(url, data=json.dumps(payload)
, headers = {
“Content-Type”: “application/json”
, “Authorization” : api_key
, “Accept” : “application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8”
}
)

This route at demo site