1

I'm trying to calculate the time on foot by two coordinates with OpenStreetMap.

I'm using this dataset: https://github.com/JayScribes/Geocode-Distance/blob/main/NYC%20Bike%20Share%20Data.csv

And this is my code:

library(readr)
NYC_Bike_Share_Data <- read_csv("NYC Bike Share Data.csv")
View(NYC_Bike_Share_Data)

library(osrm)
osrm_conn <- osrm::osrmTable(profile = "foot-walking")
 
origen<-c(NYC_Bike_Share_Data$ss_lat,NYC_Bike_Share_Data$sslong)
destino<-c(NYC_Bike_Share_Data$es_lat,NYC_Bike_Share_Data$es_long)


duracion <- osrmTable(osrm_conn, loc = c(origen, destino))$durations[1]

Output:

Error: "loc" should be a data.frame or a matrix of coordinates, an sfc POINT object or an sf POINT object.
0

1 Answer 1

0

Your definitions are incorrect, you are making vectors and not data frames/matrixes using the c() function.
Also, it is convention to list longitude as the first column followed by latitude.

Note: orsm limits calls to less than 1000 points, so you will need to subdivide your dataset.

The following should work for you:

NYC_Bike_Share_Data <- read.csv("NYC Bike Share Data.csv")

library(osrm)

origen<-NYC_Bike_Share_Data[ ,c("ss_long", "ss_lat")]
destino<-NYC_Bike_Share_Data[ ,c("es_long", "es_lat")]

duracion <- osrmTable(src = origen, dst =destino,  osrm_profile = "foot", measure = "duration")

This is resulting is a matrix instead of a single output value for each row. Also the matrix is asymmetric thus going from A to B is different than going from B to A. I am not sure if this is expected. You will need to extract the diagonal from this matrix for your final answer.

diag(duracion$durations)
Sign up to request clarification or add additional context in comments.

2 Comments

I have a problem with this line "osrm_conn <- osrm::osrmTable(profile = "foot-walking")".Specifically: "Error in osrm::osrmTable(profile = "foot-walking") : unused argument (profile = "foot-walking")"
@Amc, I am not sure where this came from but it was in your code osrm::osrmTable(profile = "foot-walking"). I deleted it now and fixed a typo in the last line. orsmTable() is not behaving as expected.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.