This assumes an id column in input and output shapes and

getContainedIn(
  inputShape,
  outputShape,
  inputVars = inputShape %>% dplyr::groups(),
  outputVars = outputShape %>% dplyr::groups(),
  suffix = c(".x", ".y")
)

Arguments

inputShape

- a sf containing points of interest (or shapes)

outputShape

- a sf containing polygons to locate the input in

inputVars

- defines the columns of the input that you want to retain (as a dplyr::vars(...) list). This grouping should uniquely identify the row. If not present will use the current grouping of inputShape.

outputVars

- defines the columns of the output that you want to retain (as a dplyr::vars(...) list). This grouping should uniquely identify the row. If not present will use the current grouping of outputShape.

suffix

- the suffix of any duplicated columns as per dplyr::inner_join()

Value

- a mapping as a dataframe relating the input id column and output id columns

Examples

# find the hospitals in a given area.
mapping = getContainedIn(
inputShape = arear::surgecapacity,
outputShape = arear::ukcovidmap(),
inputVars = dplyr::vars(hospitalId),
outputVars = dplyr::vars(code)
)
#> Spherical geometry (s2) switched off
#> caching item: ~/.cache/arear/reporting-map-87104ae5fea70bf68227e23cc93f9b65-72f531d1a36ddd6b5cbc433c29147817.rda
#> although coordinates are longitude/latitude, st_contains assumes that they are
#> planar