Getting error when requesting asymetric distance matrix


#1

Hi there,

I’ve been having a similar problem to the one posted here.

Whenever I have an asymmetric distance matrix request, the response is either a matrix of ‘null’ values (in the case where the number of sources is less than the number of destinations) or an HTTP 500 (when the number of sources is greater than the number of destinations), with the message:

Could not write JSON: (was java.lang.ArrayIndexOutOfBoundsException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.ArrayIndexOutOfBoundsException) (through reference chain: heigit.ors.api.responses.matrix.JSONMatrixResponseObjects.JSONMatrixResponse[“matrix”])

Below is a JSON with 1 source and 50 destinations, using either the profile driving-hgv or driving-car:

{“locations”:[[-9.22364,38.7245],[38.699964,-9.228724],[38.72511,-9.226697999999999],[38.724542,-9.229082],[38.724668,-9.227764],[38.717421,-9.231227],[38.721934999999995,-9.227033],[38.724823,-9.226500999999999],[38.717937,-9.230781],[38.724956,-9.227272],[38.702624,-9.233547],[38.724105,-9.22414],[38.723977000000005,-9.227385],[38.711736,-9.245047],[38.722625,-9.228284],[38.719384999999996,-9.264483],[38.723024,-9.221397],[38.713305,-9.238038000000001],[38.710316999999996,-9.243889],[38.719181,-9.231102],[38.719071,-9.230567],[38.725343,-9.226583999999999],[38.725469,-9.228047],[38.725469,-9.228047],[38.728054,-9.241292999999999],[38.723684999999996,-9.227046000000001],[38.724908,-9.227260000000001],[38.705535,-9.232178999999999],[38.708619,-9.227438000000001],[38.706813000000004,-9.23971],[38.715246,-9.2438],[38.706462,-9.225954],[38.724489,-9.22251],[38.723556,-9.227911],[38.723556,-9.227911],[38.729875,-9.246381],[38.720075,-9.230806],[38.725503,-9.228325],[38.725359999999995,-9.227427],[38.717426,-9.230801],[38.707158,-9.229979],[38.725342,-9.226623],[38.724562,-9.228139],[38.724563,-9.228138000000001],[38.708312,-9.242773],[38.725402,-9.222009],[38.713621,-9.23672],[38.704075,-9.227255],[38.720284,-9.219457],[38.711535,-9.248978],[38.7244,-9.22363]],“sources”:[0],“destinations”:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50],“metrics”:[“distance”],“units”:“m”}

which returns:

{“distances”:[[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]],“destinations”:[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],“sources”:[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],“metadata”:{“attribution”:“openrouteservice.org | OpenStreetMap contributors”,“service”:“matrix”,“timestamp”:1554647956613,“query”:{“locations”:[[-9.22364,38.7245],[38.699964,-9.228724],[38.72511,-9.226697999999999],[38.724542,-9.229082],[38.724668,-9.227764],[38.717421,-9.231227],[38.721934999999995,-9.227033],[38.724823,-9.226500999999999],[38.717937,-9.230781],[38.724956,-9.227272],[38.702624,-9.233547],[38.724105,-9.22414],[38.723977000000005,-9.227385],[38.711736,-9.245047],[38.722625,-9.228284],[38.719384999999996,-9.264483],[38.723024,-9.221397],[38.713305,-9.238038000000001],[38.710316999999996,-9.243889],[38.719181,-9.231102],[38.719071,-9.230567],[38.725343,-9.226583999999999],[38.725469,-9.228047],[38.725469,-9.228047],[38.728054,-9.241292999999999],[38.723684999999996,-9.227046000000001],[38.724908,-9.227260000000001],[38.705535,-9.232178999999999],[38.708619,-9.227438000000001],[38.706813000000004,-9.23971],[38.715246,-9.2438],[38.706462,-9.225954],[38.724489,-9.22251],[38.723556,-9.227911],[38.723556,-9.227911],[38.729875,-9.246381],[38.720075,-9.230806],[38.725503,-9.228325],[38.725359999999995,-9.227427],[38.717426,-9.230801],[38.707158,-9.229979],[38.725342,-9.226623],[38.724562,-9.228139],[38.724563,-9.228138000000001],[38.708312,-9.242773],[38.725402,-9.222009],[38.713621,-9.23672],[38.704075,-9.227255],[38.720284,-9.219457],[38.711535,-9.248978],[38.7244,-9.22363]],“profile”:“driving-hgv”,“responseType”:“json”,“sources”:[“0”],“destinations”:[“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“11”,“12”,“13”,“14”,“15”,“16”,“17”,“18”,“19”,“20”,“21”,“22”,“23”,“24”,“25”,“26”,“27”,“28”,“29”,“30”,“31”,“32”,“33”,“34”,“35”,“36”,“37”,“38”,“39”,“40”,“41”,“42”,“43”,“44”,“45”,“46”,“47”,“48”,“49”,“50”],“metrics”:[“distance”],“units”:“m”},“engine”:{“version”:“5.0”,“build_date”:“2019-03-21T12:24:30Z”}}}

And here is a JSON with 50 sources and 1 destination, using the profile driving-car:

{“locations”:[[-9.228724,38.699964],[-9.226697999999999,38.72511],[-9.229082,38.724542],[-9.227764,38.724668],[-9.231227,38.717421],[-9.227033,38.721934999999995],[-9.226500999999999,38.724823],[-9.230781,38.717937],[-9.227272,38.724956],[-9.233547,38.702624],[-9.22414,38.724105],[-9.227385,38.723977000000005],[-9.245047,38.711736],[-9.228284,38.722625],[-9.264483,38.719384999999996],[-9.221397,38.723024],[-9.238038000000001,38.713305],[-9.243889,38.710316999999996],[-9.231102,38.719181],[-9.230567,38.719071],[-9.226583999999999,38.725343],[-9.228047,38.725469],[-9.228047,38.725469],[-9.241292999999999,38.728054],[-9.227046000000001,38.723684999999996],[-9.227260000000001,38.724908],[-9.232178999999999,38.705535],[-9.227438000000001,38.708619],[-9.23971,38.706813000000004],[-9.2438,38.715246],[-9.225954,38.706462],[-9.22251,38.724489],[-9.227911,38.723556],[-9.227911,38.723556],[-9.246381,38.729875],[-9.230806,38.720075],[-9.228325,38.725503],[-9.227427,38.725359999999995],[-9.230801,38.717426],[-9.229979,38.707158],[-9.226623,38.725342],[-9.228139,38.724562],[-9.228138000000001,38.724563],[-9.242773,38.708312],[-9.222009,38.725402],[-9.23672,38.713621],[-9.227255,38.704075],[-9.219457,38.720284],[-9.248978,38.711535],[-9.22363,38.7244],[-9.22364,38.7245]],“sources”:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49],“destinations”:[50],“metrics”:[“distance”],“units”:“m”}

which returns an HTTP 500 error with the message:

Could not write JSON: (was java.lang.ArrayIndexOutOfBoundsException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.ArrayIndexOutOfBoundsException) (through reference chain: heigit.ors.api.responses.matrix.JSONMatrixResponseObjects.JSONMatrixResponse[“matrix”])

I have also tested this by reducing the total number of locations and maintaining an asymetric request (always specifying the sources and the destinations), and I obtained the same results.

I recognize that the issue is very similar to the one I linked above, I just wanted to give extra information and inform you that the driving-hgv only fixed half the problem for me (when there are more sources than destinations this works, but not when there are more destinations than sources).

Thank you for your time!


#2

Hello there,

Here I seem to have the same problem with R. When I run an asymmetric matrix request with a one to many I get back an error:

Error: openrouteservice API request failed
[6002] Parameter ‘sources’ has incorrect value or format.

I’ve tried all the combinations of profiles and which side is 1. None seem to work. Two sources does seem to work.

This is the call:

res <-
ors_matrix(
coordinates,
sources = c(0),
destinations = c(1:10),
profile = “driving-hgv”
)

The site seems to say that one to many should work. I might be doing something wrong.

Any ideas?

Thanks!

Nick


#3

Hi Nick,
thank you for your inquiry! The problem is that both sources and destinations are expected to be formatted as arrays. However, single-element vectors happen to be internally simplified to atomic values resulting in an invalid request. In order to prevent the conversion you need to wrap them in I(), such as:

res <-
ors_matrix(
  coordinates,
  sources = I(c(0)),
  destinations = c(1:10),
  profile = “driving-hgv”
)

Cheers,
Andrzej

UPDATE
As of package version 0.3.1 there is no need of providing single-element arguments as atomic vectors of length 1 or wrapping them in I(). The following should work just fine:

res <-
ors_matrix(
  coordinates,
  sources = 0,
  destinations = c(1:10),
  profile = “driving-hgv”
)

#4

Hi Andrzej,

Works like a charm! Thank you for the speedy and helpfull reply.

Best,
Nick


#5

@ElliotShame

Regarding your first request the response of a null matrix occurs, because your longitude, latitude coordinates are flipped (except the first coordinate pair).
Furthermore, if your request has in total 50 coordinate pairs, then the array consists of 0-49 indexes. The correct destinations array in your first request then would be: [1,2,3,4,5,6,…,49] . The same applies to your second example. The correct sources array would be: [0,1,2,3,4,...,48] and the destinations array would be [49].