Distance matrix returning 'None' values

Hi, I’m trying to calculate the distance matrix between 9 cities.
I’ve implemented the distance matrix exactly the same way as the example on the ORS GitHub python repository (https://github.com/GIScience/openrouteservice-py/blob/9fc22f378db8f9ef98a1675031055b1ae2bec97b/examples/basic_example.ipynb). I get the correct distance and times for 7 out of the 9 cities, while the remaining 2 cities return distances and times of ‘None’.

My code is as follows:

import openrouteservice as ors
import folium

client = ors.Client(key=‘ORSKey’)

m = folium.Map(location=[22.937506, -30.559482], tiles=‘cartodbpositron’, zoom_start=13) #folium — Folium 0.14.0 documentation

coordinates = [[26.4463605889411, -32.1540273871439],
[26.8672642069916, -28.6144032334478],
[28.1257789858759, -26.1061469151442],
[30.7485588070194, -28.7165849266373],
[29.2897631723233, -23.7853352498787],
[30.2989842255136, -25.8736514600477],
[25.5196480753104, -26.2681354867569],
[21.4028091591807, -29.4534052770319],
[20.6160379293236, -33.01454785206833]
]

matrix = client.distance_matrix(
locations=coordinates,
profile=‘driving-hgv’,
metrics=[‘distance’, ‘duration’],
units = ‘km’,
validate=True,
)

for marker in coordinates:
folium.Marker(location=list(reversed(marker))).add_to(m)

print(“Durations in secs: {}\n”.format(matrix[‘durations’]))
print(“Distances in km: {}”.format(matrix[‘distances’]))

m

My output matrix is as follows:

Distances in km: [[0.0, 522.94, 849.5, 1029.21, 1167.97, 1119.38, 942.81, None, None], [522.88, 0.0, 334.47, 487.94, 652.93, 604.34, 608.76, None, None], [853.31, 338.51, 0.0, 515.41, 329.41, 290.57, 343.5, None, None], [1030.06, 487.63, 509.17, 0.0, 731.45, 511.97, 808.66, None, None], [1168.74, 653.94, 334.57, 738.21, 0.0, 437.33, 617.92, None, None], [1118.64, 603.84, 284.44, 511.92, 430.45, 0.0, 592.27, None, None], [943.0, 608.6, 326.25, 808.97, 616.67, 593.15, 0.0, None, None], [None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None]]

I’d really appreciate any assistance, thanks in advance!

Hi @fuzaild23,

that is the case if a route there could not be found.
This is normally due to the location being too far away from the road network.
The default snapping radius for points is 350 meters.
Your last 2 points can’t be found due to this.

Yes the error response could be a lot better :sweat:
If you want you can add an issue for it in our backend repo.

Best regards

1 Like