Extract connected consumer (from) and provider (to) locations within a catchment area, as defined by cost and weights.

catchment_connections(from, to, cost = NULL, weight = 1, ...,
  return_type = "data.frame", from_id = "GEOID", from_coords = c("X",
  "Y"), to_id = "GEOID", to_coords = c("X", "Y"))

Arguments

from

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.

to

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.

cost

A cost matrix, with row names corresponding to IDs of from, and column names corresponding to IDs of to.

weight

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.

return_type

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").

from_id, from_coords, to_id, to_coords

Names of ID and coordinate columns in from and to, or vectors of IDs and matrices of coordinates.

Value

An object with connection, weight, and cost information, with a format depending on return_type.

Examples

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)
    )
}