catchment_connections.Rd
Extract connected consumer (from
) and provider (to
) locations within a catchment area,
as defined by cost and weights.
Consumer locations; a matrix-like object with columns containing latitudes and longitudes
(identified by from_coords
), and a column of IDs corresponding to rows in cost
(identified by
from_id
). Each identifying column can alternatively contain the associated matrix or vector, and
IDs can be in row names.
Provider locations;a matrix-like object with columns containing latitudes and longitudes
(identified by to_coords
), and a column of IDs corresponding to columns in cost
(identified by
to_id
). Each identifying column can alternatively contain the associated matrix or vector, and
IDs can be in row names.
A cost matrix, with row names corresponding to IDs of from
, and column names corresponding to
IDs of to
.
A weight matrix with the same dimensions as cost
, such as returned from
catchment_weight
.
Passes arguments to catchment_weight
if weight
is not a weight matrix.
Specify whether to return a data.frame
(default) with connection ids, weights, and costs,
an sf
data.frame
("sf"
) with linestring geometries added for each connection,
or a GeoJSON-formatted list ("list"
).
Names of ID and coordinate columns in from
and to
,
or vectors of IDs and matrices of coordinates.
An object with connection, weight, and cost information, with a format depending on return_type
.
pop <- simulate_catchments()
connections <- catchment_connections(
pop$consumers, pop$providers,
weight = "gaussian", max_cost = 1,
return_type = "sf"
)
if (require("leaflet", quiet = TRUE)) {
leaflet() |>
addPolylines(
data = connections, weight = 3, color = "#777",
highlightOptions = highlightOptions(color = "#fff", weight = 4),
label = ~ paste0("From: ", from, ", To: ", to, ", Weight: ", weight, ", Cost: ", cost)
) |>
addCircles(
data = pop$consumers, label = ~ paste0("Consumers: ", count, ", Access: ", access)
) |>
addCircles(
data = pop$providers, color = "#000", label = ~ paste("Provider", id)
)
}