redist: Get distances between data and regions.

View source: R/redist.R

redistR Documentation

Get distances between data and regions.

Description

Finds distances in km between data provided as sf dataframe with point geometry and regions provided as sf dataframe with polygon or multipolygon geometry.

Usage

redist(data, regions, region_id, max_dist, cores = 1, progress = FALSE)

Arguments

data

An sf data frame with point geometry.

regions

An sf dataframe with polygon or multipolygon geometry.

region_id

Optional name of column in 'regions' that contains the id that each region belongs to (no quotes). If null, it will be assumed that each row is its own region.

max_dist

a maximum distance that is needed for future calculations. (Set equal to maximum 'smooth' when predicting on new observations.)

cores

Number of cores for parallel computing. 'cores' above default of 1 will require more memory. (Progress bar only appears if ' cores' = 1.)

progress

If true, a text progress bar is printed to the console. Progress set to FALSE will find distances quicker if max_dist is not specified.

Value

A matrix where each row corresponds one-to-one with each row in provided 'data'. Matrix columns are either named with regions from 'region_id' column of 'regions' or the row numbers of 'regions' if 'region_id' is missing. Values are in kilometers.

See Also

remap - uses redist for regional models.

Examples

library(remap)
data(utsnow)
data(utws)

# Build a matrix of distances between objects of utsnow and utws
# We will not set max_dist, so all distances will be found
dists <- redist(data = utsnow,
                regions = utws,
                region_id = HUC2)

head(dists)


remap documentation built on July 9, 2023, 6:44 p.m.