The Visual Raster Cheat Sheet
Source:vignettes/visual_raster_cheetsheet.Rmd
visual_raster_cheetsheet.RmdEtienne B. Racine (etiennebr@gmail.com)
2023-08-20 (R version 4.2.2 and raster package version 3.6.23)
Source code and package available at https://github.com/etiennebr/visualraster. Suggestions, contributions, feature request, and bug report are appreciated and help to keep that project alive.
Local
Local analysis consider cells independently
Access

r[13]
#> [1] 8
r[2, 3]
#> [1] 8
r[2, ]
#> [1] 9 4 8 3 1 3 3 8 3 8
r[ , 3]
#> [1] 4 8 8 4 6 8 7 9 9 5
#r[2:3, , drop = FALSE] |> lh()Add vectors

Cell from point
cellFromXY(r, pt)
#> [1] 23
colFromX(r, pt$x)
#> [1] 3
rowFromY(r, pt$y)
#> [1] 3
fourCellsFromXY(r, as.matrix(pt))
#> [,1] [,2] [,3] [,4]
#> [1,] 23 33 32 22Focal
Focal analysis consider a cell plus its direct neighbours in a contiguous and symetrical manner
focal
r_focal = focal(r, fun = mean, w = matrix(1,nrow=3,ncol=3))
One can remove edge effect by ignoring NA values

Zonal
Zonal analysis consider group of cells in an irregular, but conitguous (in space or value) manner.
boundaries
“Detect boundaries (edges). boundaries are cells that have more than one class in the 4 or 8 cells surrounding it, or, if classes=FALSE, cells with values and cells with NA.”

Terrain

terrain
r_terrain = terrain(v, opt = c("slope", "aspect", "tpi", "tri", "roughness", "flowdir"))
Angular data can sometimes be better expressed using a circular palette. In the following figure, blue is North orientation, while South is red. Both colors reach black at West and white at East. The preceeding figure had some sharp edges on North faces, when angle slightly changed from 360 to 0.



























