8.2 Zonal toolset

8.2.1 Zonal Statistics

Zonal Statistics tool in ArcGIS pro is used for calculating the statistics on values of a raster within the zones of another dataset. In R we are able to produce similar results with the use of zonal function of the raster package.

r <- raster(ncols = 10, nrows = 10)
# generating random numbers that will used as values in our raster layer (r) -
# input values raster
values(r) <- runif(ncell(r)) * 1:ncell(r)

z <- r
# generating integer values for the raster layer z, which will be used as the
# zone raster
values(z) <- rep(1:5, each = 20)

# Zonal statistics - Summarize
zonal(r, z, "sum")
##      zone       sum
## [1,]    1  91.45046
## [2,]    2 273.45239
## [3,]    3 493.49186
## [4,]    4 607.91764
## [5,]    5 983.46942
# Zonal statistics - Mean
zonal(r, z, "mean")
##      zone      mean
## [1,]    1  4.572523
## [2,]    2 13.672619
## [3,]    3 24.674593
## [4,]    4 30.395882
## [5,]    5 49.173471
# Zonal statistics - Minimum
zonal(r, z, "min")
##      zone        min
## [1,]    1  0.1732373
## [2,]    2  1.7665573
## [3,]    3  5.0742877
## [4,]    4 10.0742510
## [5,]    5 18.6159826