
This function calculates geographic statistics for each set of cells in an integer
or factor
GRaster
. Statistics include:
Area
Perimeter length
"Compact square" statistic:
"Compact circle" statistic:
fractal dimension:
The average x- and y-coordinates of each zone.
# S4 method for GRaster
zonalGeog(x, unit = "meters")
A list of data.frame
s or a data.table
s, one per layer in x
. Only layers that are integers or factors have their geographies calculated. Other layers have NULL
tables returned.
A GRaster
.
Character: Units of the output. Any of:
"meters"
(default)
"kilometers"
or "km"
"miles"
or "mi"
"yards"
or "yd"
"feet"
or "ft"
: International foot; 1 foot exactly equal to 0.3048 meters
"cells"
: Number or cells
Partial matching is used and case is ignored.
if (grassStarted()) {
# Setup
library(terra)
# Example data: Elevation and land cover
madElev <- fastData("madElev")
madForest2000 <- fastData("madForest2000")
madCover <- fastData("madCover")
# Convert to GRasters:
elev <- fast(madElev)
forest2000 <- fast(madForest2000)
cover <- fast(madCover)
# Rename
names(elev) <- "elev"
names(forest2000) <- "forest"
# Geometric statistics for an integer raster zoned by elevation:
fun <-
"= if (elev <400 & forest == 1, 0, if (elev >=400 & forest == 1, 1, null()))"
forestByElev <- app(c(elev, forest2000), fun = fun)
plot(forestByElev, main = "forest < 400 m & >= 400 m")
zonalGeog(forestByElev)
# Geometric statistics for a categorical raster:
zonalGeog(cover)
}
Run the code above in your browser using DataLab