GRASS logo


r.slope.direction - Calculates slope following a direction raster.


raster, slope, direction, neighborhood, stream, trail, trac, path, road, street


r.slope.direction --help
r.slope.direction [-a] elevation=name direction=name dir_type=string steps=string slope_measure=string output=name[,name,...] [--overwrite] [--help] [--verbose] [--quiet] [--ui]


Compute slope as absolute values
Compute slope as absolute values (default allows negative slopes)
Allow output files to overwrite existing files
Print usage summary
Verbose module output
Quiet module output
Force launching GUI dialog


elevation=name [required]
Name of input elevation raster map
direction=name [required]
Input Direction raster map
Name of input raster map
dir_type=string [required]
Direction type
Type of diretion encoding in diections input raster map (default: auto)
Options: 45degree, degree, bitmask, bitmask_k, auto
Default: auto
steps=string [required]
Number of steps
Comma separated list of steps in direction for which slope is computed
Default: 1
slope_measure=string [required]
Slope measure
Format for reporting the slope (default: degree)
Options: difference, percent, percent_int, degree, degree_int
Default: degree
output=name[,name,...] [required]
Name for output raster map(s)

Table of contents


r.slope.direction computes slope as elevation difference divided by distance along a user given number of steps following a direction map.

Difference in altitude to the neighboring cell in the given direction is measured and divided by the distance (determined by north south and east west resolution of the computational region). With the steps paramter the user can define how many steps along the direction map the algorithm should perform. For each step a temporary raster map is created. Thus, processing time is - in addition to the computational region - mainly determined by the maximum steps value. Multiple neighboorhoods can be given in order to produce slope measures at different spatial scales.

The slope_measure option defines the format in which slope is reported. Possible values are

The a-flag allows to compute slope as absolute elevation differences.


The following examples are based on the North Carolina dataset!

Slope following a flow direction raster at different scales

# Set the computational region
g.region -p raster=elevation

# Convert street network to raster and assign pixels direction value
r.watershed elevation=elevation accumulation=faccum drainage=fdir

r.slope.direction --o --v elevation=elevation direction=fdir \
steps=1,5,13 output=fdir_slope_1,fdir_slope_5,fdir_slope_13 \
method=total_gradient format=percent scale=3 type=CELL
Slope following flow direction for 1 pixel Slope following flow direction for 5 pixels Slope following flow direction for 13 pixels
Slope following flow direction for 1 pixel. Slope following flow direction for 5 pixels. Slope following flow direction for 13 pixels.

Slope along a street network at different scales

# Set the computational region
g.region -p raster=elevation

# Convert street network to raster and assign pixels direction value input=streets_wake type=line output=streets_wake use=dir

# Directions output from needs to be adjusted so that:
# - direction information is coded a steps to neighboring cells
# - direction information always points to next pixel on the line
#   (only end pixels of a line should point to NULL cells)

# Deinfe variables

# Recode direction information
r.mapcalc --o expression="${tmp_dir}=if(int(round(${in_dir}/45.0))==0,8, \

# Make sure that direction points to next non-NULL cell in network
r.mapcalc --o expression="
${out_dir}=if(${in_dir}==8,if(isnull(${in_dir}[0,1]), \
if(isnull(${in_dir}[-1,1]), \
if(isnull(${in_dir}[1,1]), \
if(isnull(${in_dir}[-1,0]), \
if(isnull(${in_dir}[1,0]),8,6),2),7),1),8) \
,if(${in_dir}==7,if(isnull(${in_dir}[1,1]), \
if(isnull(${in_dir}[0,1]), \
if(isnull(${in_dir}[1,0]), \
if(isnull(${in_dir}[-1,1]), \
if(isnull(${in_dir}[1,-1]),7,5),1),6),8),7) \
,if(${in_dir}==6,if(isnull(${in_dir}[1,0]), \
if(isnull(${in_dir}[1,1]), \
if(isnull(${in_dir}[1,-1]), \
if(isnull(${in_dir}[0,1]), \
if(isnull(${in_dir}[0,-1]),6,4),8),5),7),6) \
,if(${in_dir}==5,if(isnull(${in_dir}[1,-1]), \
if(isnull(${in_dir}[1,0]), \
if(isnull(${in_dir}[0,-1]), \
if(isnull(${in_dir}[1,1]), \
if(isnull(${in_dir}[-1,-1]),5,4),7),4),6),5) \
,if(${in_dir}==4,if(isnull(${in_dir}[0,-1]), \
if(isnull(${in_dir}[1,-1]), \
if(isnull(${in_dir}[-1,-1]), \
if(isnull(${in_dir}[1,0]), \
if(isnull(${in_dir}[-1,0]),4,3),6),3),5),4) \
,if(${in_dir}==3,if(isnull(${in_dir}[-1,-1]), \
if(isnull(${in_dir}[0,-1]), \
if(isnull(${in_dir}[-1,0]), \
if(isnull(${in_dir}[1,-1]), \
if(isnull(${in_dir}[-1,-1]),1,3),5),2),4),3) \
,if(${in_dir}==2,if(isnull(${in_dir}[-1,0]), \
if(isnull(${in_dir}[-1,-1]), \
if(isnull(${in_dir}[-1,1]), \
if(isnull(${in_dir}[0,-1]), \
if(isnull(${in_dir}[0,1]),2,8),4),1),3),2) \
,if(${in_dir}==1,if(isnull(${in_dir}[-1,1]), \
if(isnull(${in_dir}[-1,0]), \
if(isnull(${in_dir}[0,1]), \
if(isnull(${in_dir}[-1,-1]), \
if(isnull(${in_dir}[1,1]),1,7),3),8),2),1) \

# Compute slope of the streets for three
# different step-sizes (step)
r.slope.direction -a elevation=elevation \
direction=streets_wake_dir45 steps=1,5,13 \

Slope following street direction for 1 pixel Slope following street direction for 5 pixels Slope following street direction for 13 pixels
Slope following street direction for 1 pixel. Slope following street direction for 5 pixels. Slope following street direction for 13 pixels.


r.mapcalc, r.path, r.slope.aspect,


Stefan Blumentrath, Norwegian Institute for Nature Research, Oslo, Norway
Written for the INVAFISH project (RCN MILJØFORSK grant 243910)


Available at: r.slope.direction source code (history)

Latest change: Thursday Feb 03 09:32:35 2022 in commit: f17c792f5de56c64ecfbe63ec315307872cf9d5c

Main index | Raster index | Topics index | Keywords index | Graphical index | Full index

© 2003-2022 GRASS Development Team, GRASS GIS 8.2.0 Reference Manual