How can I calculate the 3D surface area (including topography) for an elevation raster map in R, preferably with package terra
? Something like the r.surf.area
module of GRASS GIS, or the surfaceArea
function of the R sp
package, but (if possible) also accounting for latitude/longitude:
library(terra)
library(sp)
r <- terra::rast(system.file("ex/elev.tif", package="terra"))
terra::expanse(r) # computes 2D surface area, considering the relationship between longlat degrees and meters across the globe
m <- sp::SpatialPixelsDataFrame(points = crds(r), data = data.frame(r))
sp::surfaceArea(m) # computes 3D area, considering the sloping nature of the surface