HES 505 Fall 2022: Session 11
Matt Williamson
Image Source: USGS
By the end of today, you should be able to:
Evaluate logical conditions with raster data
Calculate different measures of raster data
Align rasters for spatial processing
Raster data represent spatially continuous phenomena (NA is possible)
Depict the alignment of data on a regular lattice (often a square)
matrix objects in RGeometry is implicit; the spatial extent and number of rows and columns define the cell size
terraPredicates: evaluate a logical statement asserting that a property is TRUE
terra does not follow the same hierarchy as sf so a little trickier
terraCan tell us qualities of a raster dataset
Many similar operations for SpatVector class (note use of .)
| predicate | asks… |
|---|---|
is.lonlat |
Does the object have a longitude/latitude CRS? |
inMemory |
is the object stored in memory? |
is.factor |
Are there categorical layers? |
hasValues |
Do the cells have values? |
terraterraTake exactly 2 inputs, return 1 matrix of cell locs where value is TRUE
adjacent: identifies cells adajcent to a set of raster cells
terraSlightly more flexible than sf
One result for each layer in a stack
| measure | returns |
|---|---|
cellSize |
area of individual cells |
expanse |
summed area of all cells |
values |
returns all cell values |
ncol |
number of columns |
nrow |
number of rows |
ncell |
number of cells |
res |
resolution |
ext |
minimum and maximum of x and y coords |
origin |
the orgin of a SpatRaster |
crs |
the coordinate reference system |
cats |
categories of a categorical raster |
terraSpatRaster describing the measure| measure | returns |
|---|---|
distance |
shortest distance to non-NA or vector object |
gridDistance |
shortest distance through adjacent grid cells |
costDistance |
Shortest distance considering cell-varying friction |
direction |
azimuth to cells that are not NA |
aggregate, disaggregate, resample allow changes in cell size
aggregate requires a function (e.g., mean() or min()) to determine what to do with the grouped values
resample allows changes in cell size and shifting of cell centers (slower)