ORS Directions shortest path through green

I am trying to use the directions service of ORS and I want to know if what I am trying to achieve is possible and to know how to set the parameters correctly to get the desired output.

I want to get the shortest path from point A to B and I don’t want to take into account any traffic rules. Take for
instance the following example:

I have two questions that I would like to ask (corresponding to the numbers in the image):

  1. Sometimes the coordinates that are used are located in the middle of a field. Is it possible to also visualise the line between the point on the map and the shortest way to the road and to also take this into account in the calculated distance?
  2. Is it possible, that if the route that follows the road is way longer than a route through the green, to make the route go through the green? I have tried to use {“profile_params”:{“weightings”:{“green”:{“factor”:1}}}}, but that didn’t do it.

I am eager to hear from you! Thanks in advance.

Younes

Javascript code:

var request = new XMLHttpRequest();

request.open('GET', 'https://api.openrouteservice.org/directions?api_key=5b3ce3597851110001cf6248c057ebe63f0a4775b34a2ce3885d5221&coordinates=5.603635,53.10476%7C5.616580,53.10950&profile=foot-walking&preference=shortest&options=%7B%22profile_params%22:%7B%22weightings%22:%7B%22green%22:%7B%22factor%22:1%7D%7D%7D%7D');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

request.send();

I fear you’ll have to use client-side post-processing checks to do what you want.

  1. Easy: get the straight line between your input point and the route start and mulitply the distance of that line with a predefined speed (depending on profile…) and add it to route distance & duration

  2. Trickier. Here you’d find the distances between all waypoints of the routing output and your final point. Then if the shortest distance is smaller than the remaining routing output distance, you take the shortcut from that waypoint.

Both approaches are VERY vulnerable (it’s not always traversable fields…). On the backend it’s not possible as of now. The solution would be open-space routing. But even there we’d have to define OSM tags of multipolygons which are routable and I doubt that open agricultural fields would be one of them. Rather like city squares and the like. Could be interesting though.

Hi Nils,

Thanks for your quick response. I will try to make it work client-side!

Kind regards,

Younes