Question

The openrouteservice R package provides for the plotting of a route between two points and the calculation of the distance between them: https://openrouteservice.org/openrouteservice-r-package/

In all the documentation and the vignette, data is only ever entered in list format - for instance in this example of the ors_matrix function:

https://giscience.github.io/openrouteservice-r/articles/openrouteservice.html#matrix-1

However, I have a large dataset with multiple pairs of points (i.e. an origin and destination column, each filled with multiple destination postcodes) for which I would like to calculate the distance of the route, and it is not clear to me how I can amend the code to accommodate this format.

I have got as far as using the ors_geocode function to create variables with the coordinates of origin and destination but it isn't clear to me how to do the next step as all examples provided seem to either only use a single pair of points or to have multiple points in list rather than data frame format.

I'm sure the answer is pretty straightforward but I am new to working with spatial data so would appreciate any suggestions. Thanks.

Example of my dataset (with dummy postcodes...):

origin destination mode
SW1A 0AA CF99 1SN driving-car
SW1A 1AA EH99 1SP driving-car

Example of desired output

origin destination mode distance
SW1A 0AA CF99 1SN driving-car n1
SW1A 1AA EH99 1SP driving-car n2

df1<-data.frame(data)

df1$orig_coord<-lapply(df$origin, ors_geocode)
df1$dest_coord<-lapply(df$destination, ors_geocode)

[edited to add example dataset and desired output]

0

There are 0 best solutions below