Kristian Evers asked on the fediverse:
I have a raster where each cell is categorized with a value of either 1, 2 or 3.
In #QGIS, how would I determine the percentage of cells in each category?
This piqued my curiosity so here you go!
The Raster layer unique values report tool provides both a table containing value
& count
columns and a number of outputs, among other things TOTAL_PIXEL_COUNT
and NODATA_PIXEL_COUNT
.


The Field calculator can be used to calculate an additional column for the table. Note that I decided for NODATA
pixels to not count towards the total number of pixels here!

Combine them in a model, add appropriate inputs and you have a fancy new QGIS tool to calculate the percentages of each value in a raster image:


Here is my model file: