Skip to contents

This function will calculate the mean, maximum, minimum, or total fetch distance in 8 directions (horizontally, vertically, and diagonally). When provided raster data, the default behavior is to treat all NA cells as water cells and all non NA cells as land. If you want to specify a different value for water cells, use the water_value argument to specify the grid cells that represent water. When a sf/terra polygon is provided, a cell resolution must be provided to specify the desired resolution of the output raster. Returns a binary landwater SpatRaster with land values of 0 and water values of 1.Returns a raster of the same CRS, resolution, and extent as the input raster or vector.

Usage

get_fetch(
  r = NULL,
  max_dist = 1e+05,
  res = 2000,
  water_value = NA,
  func = "mean",
  in_parallel = TRUE,
  verbose = TRUE
)

Arguments

r

terra SpatRaster, raster RasterLayer, sf POLYGON/MULTIPOLYGON geometry, terra SpatVector POLYGON/MULTIPOLYGON geometry, or a character filepath pointing to a .shp, .gpkg, .geojson, or .tif file representing land and water. Provide a SpatRaster or RasterLayer should be a binary landwater raster with land values of 0 and water values of 1.

max_dist

numeric, maximum distance (meters) to calculate fetch values out to. Default is 100,000m (100km)

res

numeric, specifying the desired resolution of the output raster when providing a polygon. If a polygon is given, the polygon must be rasterized at a specific resolution. This argument is ignored if a raster/terra raster is given. Default is 2000, which will rasterize polygons onto a grid with a grid cell resolution of 2000 x 2000.

water_value

numeric, value indicating the value of the water cells within the input raster. If a sf/terra polygon is given, this argument is ignored. Default is NA, such that NA cells are treated as water cells and all other cells are land cells.

func

character R function to apply to distances from each cell. Either mean, min, max, or sum.

in_parallel

logical whether calculations should be done using parallel workers. If TRUE, (default), processes are run in parallel.

verbose

logical, whether messages should be printed. Default is FALSE, no messages print.

Value

SpatRaster of mean, max, min, or total wind fetch distances from land calculated for every water pixel.

Examples

if (FALSE) {
# mean fetch distance using a binary raster RasterLayer as the input
mean_fetch <- fetchr::get_fetch(
r      = fetchr::landwater
)
# plot mean fetch
plot(mean_fetch)

# maximum fetch distance using a binary raster RasterLayer as the input
max_fetch <- fetchr::get_fetch(
r      = fetchr::landwater,
func   = "max"
)

# plot max fetch
plot(max_fetch)

# minimum fetch distance using a binary raster RasterLayer as the input

min_fetch <- fetchr::get_fetch(
r      = fetchr::landwater,
func   = "min"
)

# plot min fetch

plot(min_fetch)

# mean fetch distance using a sf MULTIPOLYGON object as the input
fetch_poly <- fetchr::get_fetch(
r = fetchr::land_vect
)
# plot mean fetch from a polygon object
plot(fetch_poly)

# increase the maximum distance to calculate fetch lengths out to 200km
increase_max_dist <- fetchr::get_fetch(
r           = fetchr::landwater,
max_dist    = 200000,
in_parallel = TRUE                 # Run in parallel
)

# plot mean fetch going out 200km
plot(increase_max_dist)
}