HES 505 Fall 2024: Session 8
R server fix: run install.packages('sf')
in the Console
Fall Graduate Proposal Showcase is tomorrow, 3-5pm, in the Student Union Building, Simplot AC Ballroom!
Any questions that came up during the homework?
By the end of today, you should be able to:
Access the elements that define a raster
Build rasters from scratch using matrix operations and terra
Evaluate logical conditions with raster data
Calculate different measures of raster data
Vector data describe the “exact” locations of features on a landscape (including a Cartesian landscape)
Raster data represent spatially continuous phenomena (NA
is possible)
Depict the alignment of data on a regular lattice (often a square)
matrix
objects in R
Geometry is implicit; the spatial extent and number of rows and columns define the cell size
terra
syntax is different for terra
compared to sf
Representation in Environment
is also different
Can break pipes, Be Explicit
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16
class : SpatRaster
dimensions : 4, 4, 1 (nrow, ncol, nlyr)
resolution : 1, 1 (x, y)
extent : 0, 4, 0, 4 (xmin, xmax, ymin, ymax)
coord. ref. :
source(s) : memory
name : lyr.1
min value : 1
max value : 16
Note: you must have terra
loaded for plot()
to work on Rast*
objects; otherwise you get Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'
res
) defines the length and width of an individual pixelterra
Predicates: evaluate a logical statement asserting that a property is TRUE
terra
does not follow the same hierarchy as sf
so a little trickier
terra
Can 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? |
terra
terra
Take exactly 2 inputs, return 1 matrix of cell locs where value is TRUE
adjacent
: identifies cells adajcent to a set of raster cells
terra
Slightly 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 |
terra
SpatRaster
describing the measuremeasure | returns |
---|---|
distance |
shortest distance to non-NA or vector object |
gridDistance |
shortest distance through adjacent grid cells |
costDist |
Shortest distance considering cell-varying friction |
direction |
azimuth to cells that are not NA |
rast
helpfile and check the argument descriptions.NA
and plot. Try different cases if time allows.NA
(from step 4), create and plot a raster showing the distance to the nearest non-NA
cell.costDist
and gridDistance
to see how those functions can be used.wildfire_hazard_agg.tif
data from the assignment03
folder. Use the data as the input for the distance
function and plot the result. How might this be useful in your research?By the end of today, you should be able to:
Access the elements that define a raster
Build rasters from scratch using matrix operations and terra
Evaluate logical conditions with raster data
Calculate different measures of raster data