This function takes an 'od data frame' with the first two columns matching IDs of spatial objects, and matches them with objects representing origins and destinations in wide range of input data types (spatial lines, points or text strings). It returns a data frame of coordinates representing movement between all origin (ox, oy) and destination (dx, dy) points.
od_coordinates(x, p = NULL, pd = NULL, silent = TRUE, sfnames = FALSE)
A data frame in which the first two columns are codes representing points/zones of origin and destination
Points representing origins and destinations
Points representing destinations, if different from origin points
Hide messages? FALSE
by default.
Should output column names be compatible with the sf package?
A data frame with origin and destination coordinates
See points_to_od()
for a function that creates
an 'od data frame' from a set (or two sets) of points.
x = od_data_df
p = od_data_centroids
res = od_coordinates(x, p)[1:2, ]
class(res)
#> [1] "data.frame"
res
#> ox oy dx dy
#> 6 -1.545094 53.80925 -1.545708 53.79593
#> 4 -1.518911 53.79230 -1.545708 53.79593
od_coordinates(x, p, sfnames = TRUE)[1:2, ]
#> x y x y
#> 6 -1.545094 53.80925 -1.545708 53.79593
#> 4 -1.518911 53.79230 -1.545708 53.79593
od_coordinates(x, p, silent = FALSE)[1:2, ]
#> points not in od data removed.
#> ox oy dx dy
#> 6 -1.545094 53.80925 -1.545708 53.79593
#> 4 -1.518911 53.79230 -1.545708 53.79593
od_coordinates(x, p)
#> ox oy dx dy
#> 6 -1.545094 53.80925 -1.545708 53.79593
#> 4 -1.518911 53.79230 -1.545708 53.79593
#> 3 -1.545708 53.79593 -1.545708 53.79593
#> 2 -1.517420 53.77493 -1.545708 53.79593
#> 5 -1.564659 53.81767 -1.561249 53.80470
#> 3.1 -1.545708 53.79593 -1.561249 53.80470
#> 1 -1.561249 53.80470 -1.545708 53.79593
x = od_data_df2[1:3, ]
p = od_data_centroids2
pd = od_data_destinations
od_coordinates(x, p, pd)
#> ox oy dx dy
#> 3 -1.679672 53.86497 -1.664912 53.87430
#> 1 -1.376812 53.76545 -1.508841 53.80662
#> 2 -1.331076 53.79493 -1.342522 53.83669