foss4g how-to foss4g-how-to qgis 2.18.10 grass 7.2.1
In the previous entry, we learned how to sample raster and vector values at points. In this post, we’ll take a look at how we can compute for zonal statistics using a polygon layer in QGIS and GRASS.
Zonal statistics work by computing for statistics of a raster dataset (i.e. minimum, maximum, mean, etc.) within certain zones provided by another dataset (either another raster or a vector layer). Here, we’ll use a polygon vector layer to define our zones.
The tools we’ll be using are the Zonal statistics plugin in QGIS and the v.rast.stats or Update area attributes from raster module in GRASS.
The data layers for this how-to are:
We’ll try to get the minimum, maximum, and average solar radiation values for each zone provided in our sample-polygons layer.
The Zonal statistics plugin is a Core plugin in QGIS 2.18.XX that allows the user to calculate statistics on pixels of a raster band that are within polygons/zones in a vector layer. It creates additional fields in the vector layer using a user-defined prefix to hold the calculated statistics which include the minimum value, maximum value, mean value, count, and sum. You can read more about it here.
Check this post if you need help with installing/activating plugins.
Once activated, the plugin can be accessed via Raster -> Zonal statistics -> Zonal statistics.
DIRECTIONS:
Make sure that the layers you want to use are active (checked).
Open the Zonal statistics plugin.
- Select the Raster layer containing the band you want to compute statistics from (solar-radiation).
- Select the Band you want to compute statistics from (Band 1).
- Select the Polygon layer containing the zones (sample-polygons).
- Set the Output column prefix (GHI_).
- Check the Statistics to calculate.
Click OK.
If you open the attribute table of the sample-polygons layer, it should contain three additional fields named GHI_mean, GHI_min, and GHI_max.
The v.rast.stats module calculates univariate statistics from a raster map based on a vector map and uploads statistics to new attribute columns. You can read more about it here. It can be accessed by typing v.rast.stats in the Command console or via Vector -> Update attributes -> Update area attributes from raster [v.rast.stats].
DIRECTIONS:
On the Required tab:
- Select the Name of the vector map containing the zones (sample-polygons).
- Select the Name of the input raster to calculate statistics from (solar-radiation).
- Set the Column prefix for new attribute columns (GHI).
On the Optional tab:
- Select the Layer number or name to compute statistics from (1).
- Select the methods to use (or statistics to compute).
Click Run
If you open the attribute table of the sample-polygons layer, it should contain three additional fields named GHI_minimum, GHI_maximum, and GHI_average.
If you check their values, the results obtained using Zonal statistics in QGIS and v.rast.stats in GRASS are the same. Only the names of the additional attribute columns/fields created are different.
With that, you should now be able to compute zonal statistics using a polygon vector in QGIS and GRASS.
Tune in for the next installment of FOSS4G How-to and if you have any queries or requests, you can contact me or leave a comment below.
Cheers!
foss4g foss4gph qgis gis presentation
foss foss4g opensource freeasinfreedom freesoftware
foss4g foss4gph thesis uaap mapping the geography of the uaap spatial analytics basketball basketball analytics
foss4g foss4gph qgis gis presentation
If you find my website or any of the materials I share useful, you can consider donating to the cause below.
Except when explicitly stated otherwise, this work and its contents by Ben Hur S. Pintor is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Other works (software, source code, etc.) referenced in this website are under their own respective licenses.
This site is powered by Jekyll and hosted on Github (view source)