0

I am currently trying to use OSRM's Table service to get the durations of the fastest routes between two points, to be able to build a time matrix using Python and later use it as a parameter in an optimization problem.

My problem is that whenever I run my own server through my jupyter notebook (using five different locations) the 'durations' array returns empty, like in the following example:

str_locations = '-30.59464,-71.19366;-30.60386,-71.21342;-30.58654,-71.18429;-30.60298,-71.20075;-30.58603,-71.19196'
r=requests.get('http://localhost:5000/table/v1/driving/'+str_locations+'?sources=0')
r.json()['durations'][0]

returns:

[0, 0, 0, 0, 0]

I've already checked that those points exist and are connected using the two first points in map.project-osrm.org (here's the link). Plus, whenever I replace the local server with the online demo (http://router.project-osrm.org/) the array is not empty, but that doesn't work with more than 100 coordinates and I need at least 250.

I think it could have something to do with the algorithm that I am using, MLD rather than CH?

2
  • Can you share the exact query to the live server that works? Commented Nov 25, 2018 at 8:31
  • This is the query that works but returns an empty array 'http://localhost:5000/table/v1/driving/-30.59464,-71.19366;-30.60386,-71.21342;-30.58654,-71.18429;-30.60298,-71.20075;-30.58603,-71.19196?sources=0'. And when I put it on the demo server like this: link It says that there is no route between them. Those points all are situated in the same town and when I use the example query the same thing happens. Commented Nov 25, 2018 at 14:43

1 Answer 1

3

Your latitude and longitude are in the incorrect order.

For example, this query works:

http://router.project-osrm.org/table/v1/driving/-71.1936,-30.59464;-71.21342,-30.60386;-71.18429,-30.58654;-71.20075,-30.60298;-71.19196,-30.58603?sources=0

But it returns a bad response when the coordinate order is swapped.

Additionally, here's a different way to declare and use your lat/lon tuples in your code. Doing it with an array of a lat/long tuples makes it so that these kinds of errors are easier to fix, and your code is more generic.

host = 'http://localhost:5000/'
path = 'table/v1/driving/'
waypoints = [(-30.59464,-71.19366),(-30.60386,-71.21342),(-30.58654,-71.18429),(-30.60298,-71.20075),(-30.58603,-71.19196)]
waypoints = ';'.join(map(lambda pt: '{},{}'.format(*reversed(pt)), waypoints))
r = requests.get('{}{}{}?sources=0'.format(host, path, waypoints))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.