Tutorial: Zonal statistics and area computation

4. Calculate zonal statistics

In this section we'll use a tool from the Processing Toolbox to calculate the zonal statics from the NDVI layer using the parcel polygons. The Processing Toolbox in QGIS provides a lot of tools for processing GIS data. Besides QGIS tools, it also has tools from GDAL, GRASS, and SAGA that are very useful.


1. You can activate the Processing Toolbox by choosing Processing | Toolbox from the main menu.

Now the Processing Toolbox panel shows up.

2. In the Processing Toolbox click on Raster analysis | Zonal statistics (you can use the search box to search for it):


3. In the dialogue choose parcels as Input layer and NDVI_11022023 as Raster layer. We leave the Output column prefix as default.

You can use the Output column prefix if you want to add the zonal statistics of other raster layers later. Then you want use here NDVI_ and if you do it for the DEM, you'll use DEM_. In this way you can distinguish the results in the attribute table.

4. Click on  to choose the statistics that you want to calculate. Here choose Mean, St dev, Minimum and Maximum and click OK to return.


5. At the Zonal Statistics field use the dropdown menu to choose Save to GeoPackage. There browse to the GeoPackage of this project and indicate in the popup that you want to use ndvistats as the layer name.


Note that in our case the parcel layer and the NDVI layer have different projections. You can see their EPSG codes in the square brackets. In this case, QGIS will take care of the reprojection in the background. It is however good practice to reproject the layers to the same projection. So here, it would have been better to reproject the NDVI layer to EPSG: 28992 and then perform the zonal statistics calculation.

6. Click Run. Click Close after calculation to close the dialog.

7. Check the calculated statistics per parcel in the attribute table.


8. Style the ndvistats layer using the Graduated renderer and use a green ramp to visualise the mean ndvi in the parcels.



9. Duplicate the ndvistats layer and visualise the other statistics too. You can rename the duplicates to avoid confusion.

In the next section we'll add the surface area and perimeter of the parcels to the attribute table.