2

I am trying to calculate more distances In R using the package "osrm". I don't know what I am doing wrong because I followed all the steps of the package. When I try to use the argument max-table-size, it returns an error.

I already tried to put the argument max-table-size into the code, but that doesn't work.

I tried to do this:

distancias <- osrmTable(loc = dist[1:100, c("id","lon","lat")]"max-table-size")

when I try this, I have this error:

The OSRM server returned an error: Error in names(src) <- c("id", "lon", "lat"): 'names' attribute [3] must be the same length as the vector [1]

library(osrm)

dist <- read.table ("C:\\Users\\hammer\\Documents\\Erick\\22-05-19\\Distancias\\mg.txt", header=TRUE, sep="\t")


distancias <- osrmTable(loc = dist[1:100, c("id","lon","lat")])


write.table(distancias, file = "dist.txt", sep="\t")

I hope get one distance matrix of 3.600 x 3.600

Swifty
  • 839
  • 2
  • 15
  • 40
Heavy Hammer
  • 291
  • 3
  • 11
  • 1
    Since we don’t know what your data look like, it’s hard to say exactly what is causing the error. I think though that “loc” doesn’t have same number of rows as “lat”, “long”, and “id”. All of those should have same number of rows. Next time add `dput( head( yourdata))` to your question so we know what the data look like. – shea May 23 '19 at 14:01
  • Thank you a lot to answer. My data has 3 rows, one with the id (city code) et two other rows with the coordinates. When I try with less then 100 cases, work very well, the problem it's when I try to get more than that. – Heavy Hammer May 23 '19 at 14:12

2 Answers2

5

The osrm statement on the maximum number of locations supported is:

If you want to get a large number of distances make sure to set the "max-table-size" argument (Max. locations supported in table) of the OSRM server accordingly.

This statement concerns the OSRM server, not the R package osrm. If you use your own server you can change the number of locations supported in an osrmTable() call.

This example using the docker image provided by OSRM will allow the use of 10000 locations:

docker run -t -i -p 5000:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld --max-table-size 10000 /data/berlin-latest.osrm

rcarto
  • 71
  • 2
0
dfm = osrmTable(src = df, dst = df)
Jan
  • 4,974
  • 3
  • 26
  • 43
  • 3
    Welcome to Stack Overflow! While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Jul 27 '22 at 16:10
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 30 '22 at 13:08