# Zonal statistics basic output

I have been using the zonal statistics tool to quantify the variability of slopes around archaeological sites.

I have noticed in some experiments that there are differences between the mean and the median of the values within the polygons that I use. We want to use the mean slope to calculate biomechanical indices in burials of each of the polygons.

Since there is a difference between the mean and the median of each polygon, it can indicate that there is no normal distribution in the slope values sampled. In that sense, using the mean and the standard deviation would be somewhat misleading.

Is there any way to calculate the interquartile range of the values of the pixels inside a polygon? I am using QGIS 3.6 on Windows 10 with 32 GB of RAM.

• What GIS software are you using? – PolyGeo Jun 3 '19 at 18:54
• Version 3.6 of what? – PolyGeo Jun 4 '19 at 0:31
• There is an edit button beneath your question that you can use to revise it with any requested clarifications. – PolyGeo Jun 4 '19 at 2:19
• Hi @GerardoJimenez QGIS 3.6 :) -- (1) Generate points (pixel centroids) inside polygons tool, (2) Sample raster values tool, then open the attribute table of the point data, and (3) Field calculator expression `iqr("value", group_by:="polygon_id")` . – Kazuhito Jun 4 '19 at 12:51
• @ Kazuhito can you post your comment as an answer? – Gerardo Jimenez Jun 4 '19 at 14:44

## 1 Answer

Extracting cell values to vector points will allow us to further manipulate them through the Field Calculator.

(1) Generate points (pixel centroids) inside polygons tool

(`Processing Toolbox > Vector creation`)

This tool takes a raster and a vector polygon layer, to generate a point (vector layer) at the center of each pixel. However, this tool does not automatically read the cell value during the process.

(2) Sample raster values tool

(`Processing Toolbox > Raster analysis`)

This tool adds the raster cell value to corresponding vector point.

(3) Field calculator

Open the attribute table of the point layer (from step 2) and start the Field Calculator. Expression to calculate the IQR is something like:

``````iqr("value", group_by:="polygon_id")
``````

here "value" field is the raster cell value, while "polygon_id" is the unique id field taken from the polygon layer in the step (1) above.