-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate traveling times from many to one #67
Comments
Thanks for reaching out! Both the source and the destination coordinates need to be provided in one data frame through the library(openrouteservice)
lon_from <- c(2.885882, -2.885882, -2.885521, -2.887446, -2.885882)
lat_from <- c(43.291695, 43.291695, 43.296608, 43.298549, 43.291695)
lon_to <- -2.885882
lat_to <- 43.297457
coordinates <- data.frame(lon = c(lon_from, lon_to), lat = c(lat_from, lat_to))
profiles <- c("car", "walking")
res <- sapply(profiles, function(profile) {
ors_matrix(coordinates, sources = 0:4, destinations = 5, profile = ors_profile(profile))$durations
})
res
#> car walking
#> [1,] 21038.67 455247.06
#> [2,] 209.23 630.95
#> [3,] 111.75 78.87
#> [4,] 139.00 295.19
#> [5,] 209.23 630.95 Created on 2020-11-21 by the reprex package (v0.3.0) |
Thank you for the explanation, @aoles ! It obviously works great. |
Thanks for your feedback! You are right that currently column names do not influence the coordinate order which is fixed as longitude, latitude. I thought this was clear from Re the |
Oh, I didn't see your answer! thank you very much, @aoles ! |
Provided the following dataframe in which I have several source locations and destination (same destination for all, in this case):
I would like to calculate how long does it take from each source (
c(df$lon, df$lat)
) to their target destination (c(df$lon_to, df$lat_to)
), according to different means of transport (let's say: car and walking).Apparently,
ors_matrix()
is what I am looking for!Unfortunately, I haven't been able to tame it for my case scenario. Currently, I am facing two problems:
So, here I am:close to what I am looking for, but stucked. Do you happen to know how to overcome these two problems? I have read the package's documentation, as well as the API documentation (https://openrouteservice.org/dev/#/api-docs/v2/matrix/{profile}/post) (which provides an extra argument called destination, which does not appear in the function's documentation), but haven't been able to figure it out.
The text was updated successfully, but these errors were encountered: