slope: Slope of grid cells in a DEM

Description Usage Arguments Value See Also Examples

View source: R/slope.R

Description

Calculates the slope of every grid cell in a digital elevation model (DEM) from the output of cgrad, which is a set of unit vectors normal to every grid cell.

Usage

1

Arguments

cgrad

A 3D array of dimensions nrow(dem), ncol(dem),3, where the third dimensions are the x, y z component of the unit vectors normal to the surface of the DEM grid cells.

degrees

Logical. If FALSE, returns radians, if TRUE, returns degreees.

Value

A matrix of slope values for all grid cells.

See Also

aspect, cgrad

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Calculate the slope of a rough mountain area in the pyrinees
zipfile = tempfile()
download.file("https://meteoexploration.com/R/insol/data/dempyrenees.asc.zip",zipfile)
header = read.table(unz(zipfile,'dempyrenees.asc'),nrows=6)
dem = read.table(unz(zipfile,'dempyrenees.asc'),skip=6)
dem = as.matrix(dem)
unlink(zipfile)
cellsize = header[5,2]
slopedem = slope(cgrad(dem,cellsize),degrees=TRUE)
image(t(slopedem[nrow(slopedem):1,]),col=grey(100:1/100))


## similar but using raster
## Not run: 
require(raster)
demfile = tempfile()
download.file("https://meteoexploration.com/R/insol/data/dempyrenees.tif",demfile)
dem = raster(demfile)
slopedem = slope(cgrad(dem),degrees=TRUE)
slopedem = raster(slopedem,crs=projection(dem))
extent(slopedem) = extent(dem)
plot(slopedem,col = grey(100:1/100))
unlink(demfile)

## End(Not run)

insol documentation built on Feb. 10, 2021, 5:08 p.m.