# import raster image
data(normforest)
normforest <- terra::unwrap(normforest)
# crop raster to smaller area
x <- terra::crop(normforest, terra::ext(normforest[1:100, 1:100, drop = FALSE]))
# get a surface of root mean square roughness
sa_img <- focal_metrics(x = x, window = matrix(1, 5, 5),
metrics = list('sa'), progress = TRUE)
# plot the result
terra::plot(sa_img$sa)
Run the code above in your browser using DataLab