points_to_od: Convert a series of points into a dataframe of origins and...

View source: R/points_to_od.R

points_to_odR Documentation

Convert a series of points into a dataframe of origins and destinations

Description

Takes a series of geographical points and converts them into a data.frame representing the potential flows, or 'spatial interaction', between every combination of points.

Usage

points_to_od(
  p,
  pd = NULL,
  interzone_only = FALSE,
  ids_only = FALSE,
  max_dist = Inf,
  max_dest = Inf
)

points_to_odl(p, pd = NULL, crs = 4326, ...)

Arguments

p

A spatial points object or a matrix of coordinates representing points

pd

Optional spatial points object objects representing destinations. pd is ignored if p is a matrix. If pd is not provided, p is used as the destination points.

interzone_only

Should the result only include interzonal OD pairs, in which the ID of the origin is different from the ID of the destination zone? FALSE by default

ids_only

Should a data frame with only 2 columns (origin and destination IDs) be returned? The default is FALSE, meaning the result should also contain the coordinates of the start and end points of each OD pair.

max_dist

Numeric, maximum distance to consider. Default Inf. Not applicable when p is a matrix.

max_dest

The maximum number of destinations for each origin (numeric) sorted from closest to furthest. Default is Inf. Alternative to max_dist for limiting the number of ODs. Not applicable when p is a matrix.

crs

The coordinate reference system of the output, if not known in z. 4326 by default.

...

Additional arguments passed to ⁠points_to_od)⁠

Details

points_to_odl() generates the same output but returns a geographic object representing desire lines in the class sf.

Examples

library(sf)
p = od_data_centroids[1:2, ]
points_to_od(p)
points_to_od(p, ids_only = TRUE)
(l = points_to_odl(p, interzone_only = TRUE))
plot(l)
points_to_od(od_data_centroids[1:2, ], od_data_centroids[3, ])
l = points_to_odl(od_data_centroids[1:2, ], od_data_centroids[3, ])
plot(l)
(od = points_to_od(p, interzone_only = TRUE))
l2 = od_to_sf(od, od_data_centroids)
l2$v = 1
(l2_oneway = od_oneway(l2))
sf::st_length(l2)
# With max_dist:
if (require(nngeo)) {
  (l3 = points_to_odl(p, max_dist = 10000))
  sf::st_length(l3)
}

od documentation built on Sept. 11, 2024, 9:04 p.m.