-
Notifications
You must be signed in to change notification settings - Fork 403
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 |
Hi @ddunlop, I've revisited your original example and noticed that the locations listed in the POST request body don't match the actual locations which have been used in the query that is reported in the response. I've rerun my script with the latter coordinates and noticed that these locations are scattered across several islands. The connections between the different islands seem not (yet) properly mapped in OSM. However, as I was still puzzled by the missing values in your response object for the locations within one and the same island, I've tested under ORS v8.0.1, i.e. against the version you have been running your queries on back then. And voilà: I've got the same response as you, meaning all values set to Only partially, because the problem still persists and can lead to some bizzare behavior as illustated by the following example. There, the connections between locations 1-4 are properly resolved while the rest is missing, even though connections between locations 7-8 can be resolved when queried separately. Most importantly, for locations 4-8 you get an empty matrix! library(openrouteservice)
library(leaflet)
locations <- list(
c(-157.8581401, 21.3098845),
c(-157.85031, 21.30382),
c(-157.833707, 21.299987),
c(-157.83342, 21.299776),
c(-156.46452, 20.88829),
c(-159.31975372883534, 22.071610308056204),
c(-155.66481, 20.02241),
c(-155.09788, 19.71695)
)
ors_matrix(locations)$durations
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 0.00 204.35 254.15 258.24 NA NA NA NA
#> [2,] 169.59 0.00 224.01 228.11 NA NA NA NA
#> [3,] 434.72 285.34 0.00 4.09 NA NA NA NA
#> [4,] 430.62 281.24 135.42 0.00 NA NA NA NA
#> [5,] NA NA NA NA 0 NA NA NA
#> [6,] NA NA NA NA NA 0 NA NA
#> [7,] NA NA NA NA NA NA 0 NA
#> [8,] NA NA NA NA NA NA NA 0
ors_matrix(locations[5:8])$durations
#> [,1] [,2] [,3] [,4]
#> [1,] 0 NA NA NA
#> [2,] NA 0 NA NA
#> [3,] NA NA 0.00 5324.36
#> [4,] NA NA 5307.96 0.00
ors_matrix(locations[4:8])$durations
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 NA NA NA NA
#> [2,] NA 0 NA NA NA
#> [3,] NA NA 0 NA NA
#> [4,] NA NA NA 0 NA
#> [5,] NA NA NA NA 0
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")) Created on 2024-11-19 with reprex v2.1.1 |
@aoles Thanks for looking at this again! I'm still very interested in getting this fixed so that we can reliably tell if two locations can be driven between. |
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: