knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(TerrainWorksUtils)
This package includes some methods from the DEM utilities toolbox. You can calculate slope metrics which can be used as model inputs. These methods are currently only supported on Windows.
Available metrics include:
"grad"
: Surface gradient. "plan"
: Plan curvature. Curvature along contour line (negative indicates convergent topography, positive indicates divergent topography)"prof"
: Profile curvature. A measure of changes in slope along the fall line (direction of maximum slope). Negative values indicate decreasing slope; positive values indicate increasing slope. Saturated return flow, where shallow groundwater tends to exfiltrate onto the surface, tends to occur in areas of negative profile curvature."bcon"
"dev"
: Elevation deviation: Local deviation from mean elevation, an indicator of locally high or low topography. Defined as (z-zmean)/sd, where z is elevation at a point (DEM cell), zmean is mean elevation over a circle with diameter equal to the specified length scale, and sd is standard deviation of elevation within that circle."twi"
: Topographic Wetness Index. "pca"
: Partial contributing area. Not currently supported. Surface metrics can be calculated over a scale which is greater than the resolution of the DEM, which can add some smoothing to the output. The default is a 15-meter scale.
Let's say you want to calculate gradient, plan curvature, and profile curvature to use as inputs for a landslide susceptibility model. The example DEM which comes with this package is at a 20-meter scale, so we will calculate the metrics over a 40-meter scale.
Let's create a temporary output directory to put the files. In your workflow, you should save them somewhere that makes sense, like the same directory as the DEM.
DEM_path <- system.file("elev_scottsburg/elev_scottsburg.flt", package = "TerrainWorksUtils") output_dir <- "\\\\Mac/Home/Documents/terrainworks/code/TerrainWorksUtils/inst/elev_scottsburg" metrics <- c("plan", "grad", "prof", "dev") calculate_surface_metrics(metrics = metrics, DEM_path = DEM_path, output_dir = output_dir, length_scale = 15)
This will have written rasters to the output directory for plan curvature,
gradient, and profile curvature based on the DEM. They are written both as
.flt
files and as .tif
files.
list.files(output_dir)
The input file used to run the executable is also saved to the output directory:
input_makeGrids.txt
. You can examine this file to help with debugging.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.