| Title: | Catchment and Subcatchment Delineation |
|---|---|
| Description: | Use `terra` SpatRaster and SpatVector objects directly with WhiteBox Tools' stream and hydrology functions. |
| Authors: | Michael Schramm [aut, cre] (ORCID: <https://orcid.org/0000-0003-1876-6592>) |
| Maintainer: | Michael Schramm <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-28 08:17:40 UTC |
| Source: | https://github.com/TxWRI/SELECTRshed |
Breaches all of the depressions in a DEM using Lindsay's (2016) algorithm. This should be preferred over depression filling in most cases.
create_breach_depression( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, max_depth = Inf, max_length = Inf, flat_increment = NULL, fill_pits = FALSE, ... )create_breach_depression( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, max_depth = Inf, max_length = Inf, flat_increment = NULL, fill_pits = FALSE, ... )
dem |
A character file path to a raster or a SpatRaster object. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
max_depth |
numeric, Optional maximum breach depth (default is |
max_length |
numeric, Optional maximum breach channel length (in grid cells; default is |
flat_increment |
numeric, Optional elevation increment applied to flat areas. Default is |
fill_pits |
logical, Optional flag indicating whether to fill single-cell pits. Default is |
... |
optional arguments passed to |
A SpatRaster object.
dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_breach_depression(dem)dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_breach_depression(dem)
Creates a DEM with breached depressions using the least cost pathway. This is a
wrapper for whitebox::wbt_breach_depressions_least_cost() that accepts terra SpatRaster
objects or a file path to common raster files.
create_breach_depression_lc( dem, output = tempfile(fileext = ".tif"), dist = 100, whitebox_wd = NULL, max_cost = Inf, min_dist = FALSE, flat_increment = NULL, fill = FALSE, ... )create_breach_depression_lc( dem, output = tempfile(fileext = ".tif"), dist = 100, whitebox_wd = NULL, max_cost = Inf, min_dist = FALSE, flat_increment = NULL, fill = FALSE, ... )
dem |
A character file path to a raster or a SpatRaster object. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
dist |
Maximum search distance for breach paths in cells. Defaults to 100. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
max_cost |
numeric, Optional maximum breach cost (default is |
min_dist |
logical, Optional flag indicating whether to minimize breach distances. Default is |
flat_increment |
Optional elevation increment applied to flat areas. Default is |
fill |
logical, Optional flag indicating whether to fill any remaining unbreached depressions. Default is |
... |
optional arguments passed to |
A SpatRaster object.
dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_breach_depression_lc(dem, dist = 10)dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_breach_depression_lc(dem, dist = 10)
Creates a flow accumulation grid from a D8 flow direction raster or imput DEM.
This is a wrapper for whitebox::wbt_d8_flow_accumulation() that accepts
terra SpatRaster objects or a file path to common raster files.
create_d8_fa( D8pointer, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, out_type = "cells", log = FALSE, clip = FALSE, pntr = TRUE, esri_pntr = FALSE, ... )create_d8_fa( D8pointer, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, out_type = "cells", log = FALSE, clip = FALSE, pntr = TRUE, esri_pntr = FALSE, ... )
D8pointer |
A character file path to a raster or a SpatRaster object. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
out_type |
A character value indicating the values calculated for each cell. One of |
log |
Optional flag to request the output be log-transformed. |
clip |
Optional flag to request clipping the display max by 1%. |
pntr |
Is the input raster a D8 flow pointer rather than a DEM? |
esri_pntr |
Input D8 pointer uses the ESRI style scheme. |
... |
optional arguments passed to |
A SpatRaster object.
# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) create_d8_fa(D8pointer)# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) create_d8_fa(D8pointer)
Creates a flow direction or pointer grid using the d8 algorithm. This is a
wrapper for the whitebox tools d8_pointer that accepts terra SpatRaster
objects or a file path to common raster files.
create_d8_pointer( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, esri_pntr = FALSE, ... )create_d8_pointer( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, esri_pntr = FALSE, ... )
dem |
A character file path to a raster or a SpatRaster object. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
esri_pntr |
logical, D8 pointer uses the ESRI style scheme. |
... |
optional arguments passed to |
a SpatRaster object.
# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_d8_pointer(dem)# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_d8_pointer(dem)
Creates a DEM with all of the depressions filled and flat areas removed. This is a
wrapper for whitebox::wbt_fill_depressions() that accepts terra SpatRaster
objects or a file path to common raster files.
create_fill_depressions( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, fix_flats = TRUE, flat_increment = NULL, max_depth = NULL, ... )create_fill_depressions( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, fix_flats = TRUE, flat_increment = NULL, max_depth = NULL, ... )
dem |
A character file path to a raster or a SpatRaster object. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
fix_flats |
logical, indicating whether flat areas should have a small gradient applied. Defaults to |
flat_increment |
Optional elevation increment applied to flat areas. Defaults to |
max_depth |
Optional maximum depression depth to fill. Defaults to |
... |
optional arguments passed to |
A SpatRaster object.
# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_fill_depressions(dem)# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_fill_depressions(dem)
Wrapper for whitebox FillSingleCellPits. Raises pit cells to the elevation of their lowest neighbor.
create_single_pit_fill( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, ... )create_single_pit_fill( dem, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, ... )
dem |
A character file path to a raster or a SpatRaster object. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
whitebox_wd |
A valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
... |
optional arguments passed to |
A SpatRaster object
dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_single_pit_fill(dem)dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) create_single_pit_fill(dem)
Creates a raster of likely stream cells from a flow-accumulation raster using
the Whitebox Tools algorithm. This is a
wrapper for whitebox::wbt_extract_streams() that accepts terra SpatRaster
objects or a file path to common raster files.
create_streams( flow_accumulation, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, threshold = 1000, zero_background = FALSE, ... )create_streams( flow_accumulation, output = tempfile(fileext = ".tif"), whitebox_wd = NULL, threshold = 1000, zero_background = FALSE, ... )
flow_accumulation |
SpatRaster object, Input raster D8 flow accumulation file. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
threshold |
Numeric value indicating the threshold in flow accumulation values (number of cells) for channelization. |
zero_background |
logical, Flag indicating whether a background value of zero should be used. |
... |
optional arguments passed to |
A SpatRaster object.
# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) create_streams(D8fa)# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) create_streams(D8fa)
Creates a stream vector (terra SpatVector object) from a D8 flow direction
raster and stream network raster.
This is a wrapper for whitebox::wbt_raster_streams_to_vector() that accepts
terra SpatRaster objects or a file path to common raster files.
create_streams_vector( streams, d8_pointer, output = tempfile(fileext = ".shp"), whitebox_wd = NULL, esri_pntr = FALSE, all_vertices = FALSE, ... )create_streams_vector( streams, d8_pointer, output = tempfile(fileext = ".shp"), whitebox_wd = NULL, esri_pntr = FALSE, all_vertices = FALSE, ... )
streams |
SpatRaster object, input raster streams. |
d8_pointer |
SpatRaster object, input raster D8 pointer. |
output |
A character file path specifying where the raster file should be stored. Defaults to a temporary file. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
esri_pntr |
logical, D8 pointer uses the ESRI style scheme. |
all_vertices |
logical, Do you want to preserve all vertices in output (i.e. no straight-line generalization). |
... |
optional arguments passed to |
A terra SpatVector object
# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) streams <- create_streams(D8fa) create_streams_vector(streams, D8pointer)# example code dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) streams <- create_streams(D8fa) create_streams_vector(streams, D8pointer)
Identifies the catchments, or sub-basin, draining to each link in a stream network.
create_subbasins( d8_pntr, streams, output = tempfile(fileext = ".tif"), esri_pntr = FALSE, whitebox_wd = NULL, type = "terra", ... )create_subbasins( d8_pntr, streams, output = tempfile(fileext = ".tif"), esri_pntr = FALSE, whitebox_wd = NULL, type = "terra", ... )
d8_pntr |
Input D8 pointer raster file. |
streams |
Input raster streams file. |
output |
A character file path specifying where the shapefile file should be stored. Defaults to a temporary file. |
esri_pntr |
D8 pointer uses the ESRI style scheme. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
type |
character, one of |
... |
optional arguments passed to |
SpatRaster
dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) streams <- create_streams(D8fa) create_subbasins(D8pointer, streams)dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) streams <- create_streams(D8fa) create_subbasins(D8pointer, streams)
Identifies the watershed, or drainage basin, draining to a set of target cells.
create_watershed( d8_pntr, pour_pts, output = tempfile(fileext = ".tif"), esri_pntr = FALSE, whitebox_wd = NULL, type = "terra", ... )create_watershed( d8_pntr, pour_pts, output = tempfile(fileext = ".tif"), esri_pntr = FALSE, whitebox_wd = NULL, type = "terra", ... )
d8_pntr |
Input D8 pointer. |
pour_pts |
Input pour points (outlet). |
output |
A character file path specifying where the shapefile file should be stored. Defaults to a temporary file. |
esri_pntr |
D8 pointer uses the ESRI style scheme. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
type |
character, one of |
... |
optional arguments passed to |
A SpatRaster or wbt_result object.
dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) gpkg <- system.file("extdata", "thompsoncreek.gpkg", package = "SELECTRdata") pourpoint <- terra::vect(gpkg, layer = "pourpoint", crs = terra::crs(dem)) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) streams_ras <- create_streams(D8fa) ## write pourpoints to temp folder temp_pour_point_file <- tempfile("snapped", fileext = ".shp") snapped_pour_point <- snap_pour_point(pour_pts = pourpoint, streams = streams_ras, output = temp_pour_point_file) snapped_pour_point <- terra::vect(temp_pour_point_file) pour_point_rast <- terra::rasterize(snapped_pour_point, streams_ras) create_watershed(d8_pntr = D8pointer, pour_pts = pour_point_rast) ## cleanup temp files unlink(tempdir(), recursive = FALSE)dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) gpkg <- system.file("extdata", "thompsoncreek.gpkg", package = "SELECTRdata") pourpoint <- terra::vect(gpkg, layer = "pourpoint", crs = terra::crs(dem)) D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) streams_ras <- create_streams(D8fa) ## write pourpoints to temp folder temp_pour_point_file <- tempfile("snapped", fileext = ".shp") snapped_pour_point <- snap_pour_point(pour_pts = pourpoint, streams = streams_ras, output = temp_pour_point_file) snapped_pour_point <- terra::vect(temp_pour_point_file) pour_point_rast <- terra::rasterize(snapped_pour_point, streams_ras) create_watershed(d8_pntr = D8pointer, pour_pts = pour_point_rast) ## cleanup temp files unlink(tempdir(), recursive = FALSE)
Moves outlet points used to specify points of interest in a watershedding operation to the nearest stream cell.
snap_pour_point( pour_pts, streams, output = tempfile(fileext = ".shp"), whitebox_wd = NULL, snap_dist = 90, type = "terra", ... )snap_pour_point( pour_pts, streams, output = tempfile(fileext = ".shp"), whitebox_wd = NULL, snap_dist = 90, type = "terra", ... )
pour_pts |
Input vector pour points (outlet) file. |
streams |
Input raster streams file. |
output |
A character file path specifying where the shapefile file should be stored. Defaults to a temporary file. |
whitebox_wd |
valid working directory for whitebox to store temporary rasters. Defaults to NULL which stores in a temporary space that is deleted when the user session is over. You can use this to store rasters before they are processed into terra::rast objects. Otherwise it is suggested to leave this NULL and store the rasters using the output argument. |
snap_dist |
Maximum snap distance in map units. |
type |
character, one of |
... |
optional arguments passed to |
terra SpatVector object.
## example data dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) gpkg <- system.file("extdata", "thompsoncreek.gpkg", package = "SELECTRdata") pourpoint <- terra::vect(gpkg, layer = "pourpoint", crs = terra::crs(dem)) ## create flow direction and flow accumulation rasters D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) ## create streams network raster streams_ras <- create_streams(D8fa) ## write pourpoints to temp folder temp_pour_point_file <- tempfile("snapped", fileext = ".shp") ## snap pour points to stream raster network snapped_pour_point <- snap_pour_point(pour_pts = pourpoint, streams = streams_ras, output = temp_pour_point_file) ## you probably need a raster of the pour point, you need to call ## terra::vect since it is a SpatVectorProxy pour_point_rast <- terra::rasterize(terra::vect(temp_pour_point_file), streams_ras) ## cleanup temp files unlink(tempdir(), recursive = FALSE)## example data dem <- system.file("extdata", "thompsoncreek.tif", package = "SELECTRdata") dem <- terra::rast(dem) gpkg <- system.file("extdata", "thompsoncreek.gpkg", package = "SELECTRdata") pourpoint <- terra::vect(gpkg, layer = "pourpoint", crs = terra::crs(dem)) ## create flow direction and flow accumulation rasters D8pointer <- create_d8_pointer(dem) D8fa <- create_d8_fa(D8pointer) ## create streams network raster streams_ras <- create_streams(D8fa) ## write pourpoints to temp folder temp_pour_point_file <- tempfile("snapped", fileext = ".shp") ## snap pour points to stream raster network snapped_pour_point <- snap_pour_point(pour_pts = pourpoint, streams = streams_ras, output = temp_pour_point_file) ## you probably need a raster of the pour point, you need to call ## terra::vect since it is a SpatVectorProxy pour_point_rast <- terra::rasterize(terra::vect(temp_pour_point_file), streams_ras) ## cleanup temp files unlink(tempdir(), recursive = FALSE)