0

How can I use a remote osrm server to calculate driving distances in the USA (or North America). If at all possible, I would really like to avoid having to set up my own local server.

I am basing my MWE off of the answer by SamR in this question (https://stackoverflow.com/questions/74997208/how-to-speed-up-code-that-finds-shortest-driving-time-between-two-sets-of-points). I am trying to find the shortest driving times between two sets of points. As a baseline:

library(osrm)

source <- data.frame(
    id = 1:3,
    latitude = c(45.37306, 45.37306, 45.37306),
    longitude = c(-108.41307, -108.11307, -107.81307)
)

dest <- data.frame(
    id = 4:5,
    latitude = c(44.3500, 38.6800), 
    longitude = c(-68.2100, -109.5700)
)

osrmTable(
    src = source[c("longitude", "latitude")],
    dst = dest[c("longitude", "latitude")],
    osrm.profile = "car", measure=c("duration", "distance"),
    osrm.server = "https://routing.openstreetmap.de/")

$durations
      1    2
1 154.1 2365
2 154.1 2365
3 154.1 2365

$distances
       1       2
1 132471 3014230
2 132471 3014230
3 132471 3014230

$sources
        lon      lat
1 -10.46702 52.10941
2 -10.46702 52.10941
3 -10.46702 52.10941

$destinations
         lon      lat
1 -10.424649 51.88574
2  -9.497727 38.78069

These results do not make much sense. I then try a different server (https://router.project-osrm.org/), but the results (not shown) are exactly the same as above.

osrmTable(
    src = source[c("longitude", "latitude")],
    dst = dest[c("longitude", "latitude")],
    osrm.profile = "car", measure=c("duration", "distance"),
    osrm.server = "https://router.project-osrm.org/")

options(osrm.server = "https://router.project-osrm.org/")
osrmTable(
    src = source[c("longitude", "latitude")],
    dst = dest[c("longitude", "latitude")],
    osrm.profile = "car", measure=c("duration", "distance"))

Am I doing something incorrectly? Is there a different osrm.server that I can use?

1
  • 1
    You're likely better off asking directly at the github repository. I personally think the package could do a better job helping users get set up with their own server github.com/riatelab/osrm/issues
    – thus__
    Jan 10, 2023 at 16:37

1 Answer 1

0

As far as I can tell, the problem comes when the latitudes (or longitudes) of at least two points are identical or nearly identical. If one changes them slightly so that they are a bit different, then it seems to work (in other words, it works for the USA). See https://stackoverflow.com/questions/75331431/osrmtable-give-incorrect-results-when-two-latitudes-or-longitudes-are-identical. With that said, I am not sure why this happens or if there is another solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.