Skip to contents

Provides a method for preprocessing sf/terra polygons or raster/terra rasters for calculating fetch using get_fetch(). 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. Returns a binary landwater SpatRaster with land values of 0 and water values of 1. A water value should be specified to indicate which pixel value should represent water in the final raster. The rest of the pixels will indicate land cells.

Usage

get_landwater(r, water_value = NA, res = 2000, verbose = TRUE)

Arguments

r

sf POLYGON/MULTIPOLYGON, terra SpatVect POLYGON, SpatRaster, RasterLayer, or a file path (character) to a vector/raster data file. Data must be on a projected CRS.

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.

res

numeric resolution for template raster. 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.

verbose

logical, whether messages should be printed. Default is TRUE, so messages will print.

Value

SpatRaster, binary landwater raster with land values of 0 and water values of 1

Examples

if (FALSE) {
# Create a binary landwater SpatRaster from a sf polygon at a 2000m x 2000m resolution
lw <- fetchr::get_landwater(
                r   = fetchr::land_vect,
                res = 2000
                )
}