This function calculates the total area of a SpatRaster object and the overlapping areas with up to two additional SpatRaster objects. The results can be saved to a CSV file if a filename is provided.
Arguments
- x
A SpatRaster object for which the area will be calculated.
- y
An optional SpatRaster object with a single layer to calculate the overlapping area with
x
.- z
An optional SpatRaster object with a single layer to calculate the overlapping area with
x
andy
.- filename
A character string specifying the name of the CSV file to save the results. If not provided, the results will not be saved to a file.
- unit
A character string specifying the unit of measurement for area calculations. Default is "km".
- cellsize
An optional numeric value specifying the cell size for area calculations. If not provided, the function will use the cell size of the raster.
- ...
Additional arguments to be passed to other methods.
Value
A data frame containing the area of each layer in the SpatRaster object,
along with the overlapping areas if y
or z
are provided.
Examples
# \donttest{
library(terra)
#> terra 1.8.29
bin1 <- terra::rast(system.file("extdata", "ref.tif", package = "divraster"))
area.calc(bin1, bin1[[1]], bin1[[2]])
#> Layer Area Overlap_Area_Y Overlap_Area_Z Overlap_Area_All
#> 1 A 6154.240 6154.240 3269.418 3269.418
#> 2 B 6346.524 3269.418 6346.524 3269.418
#> 3 C 4615.735 2307.850 2884.851 1730.886
#> 4 D 5961.930 2692.502 3461.731 1538.558
#> 5 E 6154.240 2307.824 3654.089 1346.246
#> 6 F 5384.971 2692.494 2692.504 1538.571
#> 7 G 5384.936 3077.118 3077.083 2307.819
#> 8 H 5192.708 2115.543 3269.470 1538.576
#> 9 I 6346.598 3461.793 2500.170 1153.932
#> 10 J 6154.223 2115.502 3269.431 1538.532
# }