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.
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:
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.