Skip to contents

This function will calculate fetch values for 8 directions (horizontally, vertically, and diagonally). The function will create an 8 layer SpatRaster with a raster layer for north, south, east, west, northeast, southeast, southwest, and northwest fetch values. 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_directions(
  r = NULL,
  max_dist = 1e+05,
  res = 2000,
  water_value = NA,
  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.

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) {
# calculate 8 fetch directions using a binary raster RasterLayer as the input
fetch_dirs <- fetchr::get_fetch_directions(
r      = fetchr::landwater
)
# plot 8 fetch directions fetch
plot(fetch_dirs)
# calculate 8 fetch directions using a sf MULTIPOLYGON object as the input
fetch_poly <- fetchr::get_fetch_directions(
r = fetchr::land_vect
)
# plot mean fetch from a polygon object
plot(fetch_poly)
}