Skip to content

Calculate traveling times from many to one #67

@ccamara

Description

@ccamara

Provided the following dataframe in which I have several source locations and destination (same destination for all, in this case):

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 <- rep(-2.885882, 5),
lat_to <- rep(43.297457, 5)

df2 <- data.frame(lon_from, lat_from, lon_to, lat_to) 

> df2
   lon_from lat_from    lon_to   lat_to
1  2.885882 43.29169 -2.885882 43.29746
2 -2.885882 43.29169 -2.885882 43.29746
3 -2.885521 43.29661 -2.885882 43.29746
4 -2.887446 43.29855 -2.885882 43.29746
5 -2.885882 43.29169 -2.885882 43.29746
> 

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:

  1. I need to feed it with a list, not a dataframe (although documentation specifies that I could use a dataframe, I haven't been able to do it).
  2. Distances are calculated from every observation to every other one. I haven't found the way to calculate the many to one option stated in the description.

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.

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions