-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matrix endpoint returning null for all locations when one route does not exist #1785
Comments
Thanks @ddunlop for your patience! Unfortunately, I was unable to reproduce the described behavior when querying the ORS public API, see the following R script. Apparently the last location from the provided list of locations lies on a different island than the rest. There doesn't seem to be a connection mapped in OSM between these two islands, so no route can be found from/to the last and the other locations, as evident from the map below. Could you maybe provide some details on the configuration of your ORS instance? Cheers, library(openrouteservice)
library(leaflet)
locations = list(
c(-157.8814736, 21.3280137),
c(-157.8667852, 21.3138143),
c(-158.0245043, 21.4545909),
c(-157.9076614, 21.6066256),
c(-157.9186302, 21.6240531),
c(-157.9813495, 21.6950804),
c(-156.2243193, 20.6204251)
)
ors_matrix(locations)$durations
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.00 246.19 1704.80 3366.19 3503.91 4221.34 NA
#> [2,] 362.33 0.00 1991.80 3574.82 3712.54 4508.34 NA
#> [3,] 1736.16 1942.24 0.00 4102.02 3921.32 3028.61 NA
#> [4,] 3349.09 3538.51 4069.81 0.00 209.71 1049.52 NA
#> [5,] 3510.71 3700.13 3913.01 233.61 0.00 892.72 NA
#> [6,] 4301.90 4507.98 3020.29 1073.42 892.72 0.00 NA
#> [7,] NA NA NA NA NA NA 0
res <- ors_matrix(locations, destinations=0, metrics=c("distance", "duration"), units = "mi")
res$durations
#> [,1]
#> [1,] 0.00
#> [2,] 362.33
#> [3,] 1736.16
#> [4,] 3349.09
#> [5,] 3510.71
#> [6,] 4301.90
#> [7,] NA
res$distances
#> [,1]
#> [1,] 0.00
#> [2,] 2.26
#> [3,] 15.11
#> [4,] 27.89
#> [5,] 29.18
#> [6,] 39.87
#> [7,] NA
df <- do.call(rbind, locations) %>% data.frame()
colnames(df) <- c("lon", "lat")
leaflet() %>%
addTiles() %>%
addAwesomeMarkers(data = df, icon = awesomeIcons(text = 1:nrow(df), fontFamily = "arial")) |
@aoles Thanks for looking into this. While I can't reproduce it on api.openrouteservice.org with the original example, I can see it happening with other data. I do think that you are correct that the cause has something to do with the route not having a connection between the two islands. But I would expect distance & duration from the routeable locations and then {
"locations": [
[-157.8581401, 21.3098845],
[-157.85031, 21.30382],
[-157.83342, 21.299776],
[-124.13527, 40.77891]
],
"destinations": [0],
"metrics": ["distance", "duration"],
"units": "mi"
} Response{
"durations": [
[
0.0
],
[
null
],
[
null
],
[
null
]
],
"distances": [
[
0.0
],
[
null
],
[
null
],
[
null
]
],
"destinations": [
{
"location": [
-157.858147,
21.309892
],
"snapped_distance": 1.08
}
],
"sources": [
{
"location": [
-157.858147,
21.309892
],
"snapped_distance": 1.08
},
{
"location": [
-157.850419,
21.303858
],
"snapped_distance": 12.08
},
{
"location": [
-157.833248,
21.300057
],
"snapped_distance": 35.92
},
{
"location": [
-124.1355,
40.77891
],
"snapped_distance": 19.36
}
],
"metadata": {
"attribution": "openrouteservice.org | OpenStreetMap contributors",
"service": "matrix",
"timestamp": 1717984752030,
"query": {
"locations": [
[
-157.8581401,
21.3098845
],
[
-157.85031,
21.30382
],
[
-157.83342,
21.299776
],
[
-124.13527,
40.77891
]
],
"profile": "driving-car",
"responseType": "json",
"destinations": [
"0"
],
"metrics": [
"distance",
"duration"
],
"units": "mi"
},
"engine": {
"version": "8.0.1",
"build_date": "2024-05-14T10:47:52Z",
"graph_date": "2024-06-03T14:51:26Z"
}
}
} Response without the last location{
"durations": [
[
0.0
],
[
169.59
],
[
430.62
]
],
"distances": [
[
0.0
],
[
0.89
],
[
2.39
]
],
"destinations": [
{
"location": [
-157.858147,
21.309892
],
"snapped_distance": 1.08
}
],
"sources": [
{
"location": [
-157.858147,
21.309892
],
"snapped_distance": 1.08
},
{
"location": [
-157.850419,
21.303858
],
"snapped_distance": 12.08
},
{
"location": [
-157.833248,
21.300057
],
"snapped_distance": 35.92
}
],
"metadata": {
"attribution": "openrouteservice.org | OpenStreetMap contributors",
"service": "matrix",
"timestamp": 1717985112816,
"query": {
"locations": [
[
-157.8581401,
21.3098845
],
[
-157.85031,
21.30382
],
[
-157.83342,
21.299776
]
],
"profile": "driving-car",
"responseType": "json",
"destinations": [
"0"
],
"metrics": [
"distance",
"duration"
],
"units": "mi"
},
"engine": {
"version": "8.0.1",
"build_date": "2024-05-14T10:47:52Z",
"graph_date": "2024-06-03T14:51:26Z"
}
}
} |
I wonder if some of my initial requests caused this issue. I've been coming up with examples of this failure by taking our entire body and posting it—this has 100 locations. Then, I try to shrink the request down to a few to make a good example. But is the full post with 100 locations somehow causing future requests to return nulls? |
Thanks @ddunlop for your feedback! I was eventually able to reproduce the described behavior, see the script below. There is no request/response caching performed in openrouteservice, so the history of your requests doesn't matter. library(openrouteservice)
library(leaflet)
locations = list(
c(-157.8581401, 21.3098845),
c(-157.85031, 21.30382),
c(-157.83342, 21.299776),
c(-124.13527, 40.77891)
)
ors_matrix(locations[1:3])$durations
#> [,1] [,2] [,3]
#> [1,] 0.00 197.43 264.42
#> [2,] 169.59 0.00 234.28
#> [3,] 430.62 281.24 0.00 ors_matrix(locations[1:4])$durations
#> [,1] [,2] [,3] [,4]
#> [1,] 0 NA NA NA
#> [2,] NA 0 NA NA
#> [3,] NA NA 0 NA
#> [4,] NA NA NA 0 Created on 2024-06-12 with reprex v2.1.0 |
Is there an existing issue for this?
Where did you encounter this issue?
live API, self-hosted instance
Request URL
https://api.openrouteservice.org/v2/matrix/driving-car
POST Request Body
Response
Response
Current behavior
The last location is causing all of the distance & duration results to become null. If you remove the last location from the request then the distance & duration arrays start to return numerical values.
Expected behavior
All of the locations except for the last one should return numbers. The distance & duration for the last one should be null.
Openrouteservice Version
8.0.0
Build date
2024-03-21T13:55:54Z
Graph date
2024-04-28T13:28:40Z
Forum Topic Link
https://ask.openrouteservice.org/t/matrix-endpoint-returning-null-for-all-locations-when-some-routes-exist/6046
The text was updated successfully, but these errors were encountered: