Python and openrouteservice - Driving distance between 2 geolocations (not all exactly are reachable driving)

631 views Asked by At

My goal is to get the driving distance/time between 2 geolocations (latitude and longitude), doing this for a file of around 2k pairs of geolocations. I must be use free APIs or whatever free resources, reason why I'm usin openrouteservice with this simple code inside a function to get driving distance/time:

import numpy as np
import pandas as pd
import openrouteservice
from openrouteservice import convert

api_key = 'api_key'
client = openrouteservice.Client(key=api_key)

coords = ((lon_orig, lat_orig),(lon_dest, lat_dest))
res = client.directions(coords, radiuses =1000)
res['routes'][0]['summary']

My problems comes due to this API gives error of type: '404 ({'error': {'code': 2009, 'message': 'Route could not be found - Unable to find a route between points...' because not all pairs of destination geolocations appears to be reachable driving or walking.

To give an example, I get an error when I tried coords = ((-69.20438,-12.58308),(-70.43474,-13.03910)), because there's like a river so cars can't reach to that exactly point.

So I wonder if there's some way of approximate the destination geolocations to some new reachable (I read the openrouteservice documentation but didn't find something like that and also tried to increases 'radiuses' parameter, but I got error anyway), or maybe using another API to help openrouteservice to improve that, or finally recommend another way of doing this efficiently.

0

There are 0 answers