Skip to content
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

Open
1 task done
ddunlop opened this issue Apr 29, 2024 · 1 comment
Open
1 task done

Comments

@ddunlop
Copy link

ddunlop commented Apr 29, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Where did you encounter this issue?

live API, self-hosted instance

Request URL

https://api.openrouteservice.org/v2/matrix/driving-car

POST Request Body

{
  "locations": [
    [-157.8814736, 21.3280137],
    [-157.8667852, 21.3138143],
    [-158.0245043, 21.4545909],
    [-157.9076614, 21.6066256],
    [-157.9186302, 21.6240531],
    [-157.9813495, 21.6950804],
    [-156.2243193, 20.6204251]
  ],
  "destinations": [0],
  "metrics": ["distance", "duration"],
  "units": "mi"
}

Response

Response
{
    "durations": [
        [
            0.0
        ],
        [
            null
        ],
        [
            null
        ],
        [
            null
        ],
        [
            null
        ],
        [
            null
        ],
        [
            null
        ],
        [
            null
        ]
    ],
    "distances": [
        [
            0.0
        ],
        [
            null
        ],
        [
            null
        ],
        [
            null
        ],
        [
            null
        ],
        [
            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.83337,
                21.300157
            ],
            "snapped_distance": 39.68
        },
        {
            "location": [
                -157.833248,
                21.300057
            ],
            "snapped_distance": 35.92
        },
        {
            "location": [
                -156.464698,
                20.88822
            ],
            "snapped_distance": 20.03
        },
        {
            "location": [
                -159.319676,
                22.071742
            ],
            "snapped_distance": 16.72
        },
        {
            "location": [
                -155.6649,
                20.022491
            ],
            "snapped_distance": 13.04
        },
        {
            "location": [
                -155.097922,
                19.717017
            ],
            "snapped_distance": 8.69
        }
    ],
    "metadata": {
        "attribution": "openrouteservice.org | OpenStreetMap contributors",
        "service": "matrix",
        "timestamp": 1714395744688,
        "query": {
            "locations": [
                [
                    -157.8581401,
                    21.3098845
                ],
                [
                    -157.85031,
                    21.30382
                ],
                [
                    -157.833707,
                    21.299987
                ],
                [
                    -157.83342,
                    21.299776
                ],
                [
                    -156.46452,
                    20.88829
                ],
                [
                    -159.31975372883534,
                    22.071610308056204
                ],
                [
                    -155.66481,
                    20.02241
                ],
                [
                    -155.09788,
                    19.71695
                ]
            ],
            "profile": "driving-car",
            "responseType": "json",
            "destinations": [
                "0"
            ],
            "metrics": [
                "distance",
                "duration"
            ],
            "units": "mi"
        },
        "engine": {
            "version": "8.0.0",
            "build_date": "2024-03-21T13:55:54Z",
            "graph_date": "2024-04-28T13:28:40Z"
        }
    }
}

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

@aoles
Copy link
Member

aoles commented Jun 5, 2024

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,
Andrzej

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"))

Rplot04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
ors general
  
To do
Development

No branches or pull requests

2 participants