Learn R Programming

rdwplus (version 0.1.0)

fill_sinks: Fill sinks in a digital elevation model (DEM)

Description

A sink is a depression in a DEM. Water flows into these depressions but not out of them. These depressions, although often real features of landscapes, are problematic for flow direction and accumulation algorithms. Therefore, it is common practice to remove these depressions. This function removes depressions (sinks) in a DEM. Note that this function calls r.hydrodem, which is a GRASS GIS add-on. It can be installed through the GRASS GUI.

Usage

fill_sinks(dem, out, flags, overwrite = FALSE, max_memory = 300, ...)

Value

Nothing. A file with the name out will be created in the current GRASS mapset.

Arguments

dem

The name of a DEM in the current GRASS mapset.

out

Name of the output, which is a hydrologically corrected (sink-filled) DEM.

flags

Optional. A vector of flags that should be passed to r.hydrodem. See details for more on the possible flags.

overwrite

A logical indicating whether the output should be allowed to overwrite existing files. Defaults to FALSE.

max_memory

Max memory used in memory swap mode (MB). Defaults to 300.

...

Optional additional parameters to r.hydrodem.

Details

The following flags may be supplied (as strings):

  • "a": The nuclear option. Vigorously remove all sinks.

  • "verbose": Lots of module output.

  • "quiet": Barely any module output.

Examples

Run this code
# Will only run if GRASS is running
if(check_running()){
# Load data set
dem <- system.file("extdata", "dem.tif", package = "rdwplus")
landuse <- system.file("extdata", "landuse.tif", package = "rdwplus")
sites <- system.file("extdata", "site.shp", package = "rdwplus")
stream_shp <- system.file("extdata", "streams.shp", package = "rdwplus")

# Set environment parameters and import data to GRASS
set_envir(dem)
raster_to_mapset(rasters = c(dem, landuse), as_integer = c(FALSE, TRUE))
vector_to_mapset(vectors = c(sites, stream_shp))

# Create binary stream
rasterise_stream("streams", "streams_rast.tif", overwrite = TRUE)
reclassify_streams("streams_rast.tif", "streams_binary.tif",
 out_type = "binary", overwrite = TRUE)

# Burn dem 
burn_in(dem = "dem.tif", stream = "streams_binary.tif", 
out = "dem_burn.tif", burn = 10, overwrite = TRUE)

# Fill sinks
fill_sinks(dem = "dem_burn.tif", out = "dem_fill.tif", size = 1, overwrite = TRUE)

# Plot
plot_GRASS("dem_fill.tif", col = topo.colors(15))
}

Run the code above in your browser using DataLab