# Calculating proportion of polygon by value in QGIS?

Using QGIS, I have a single-band raster with with multiple counties. I have reclassified the pixels into 2 categories, using a singleband pseudocolor, based on their value ( > or < 3800), corresponding to non-forest or forest land.

How do I calculate the proportion of pixels that is in each of the 2 categories, in each county?

I have a lot of images over a lot of years so I would prefer to not take the route the I figured out - converting to shp, exporting as csv, sorting csv and calculating percentages in Excel.

• it's not entirely clear from your question if your "multiple counties" are available as a polygon layer, can you confirm this?
– dmci
Jan 14, 2016 at 12:47

Or just extract the rasters by the polygons Clip raster layer with *raster* mask layer in QGIS

It has been while since I used the zonal statistics but I remember it give a count value. • Yes. I had discovered the Zonal Statistics plugin and had it working nicely - giving me a summary of each county. The problem is that it doesn't give me values per category, ie forested vs non-forested (the ones shown in my TOC). Any way to get it to show me # of pixels/category? Jan 13, 2016 at 1:15
• Thanks makes sense for nominal data, I may be mixing the arc and qgis zonal functions. just make two rasters and give each pixel a value of 1 and then it is the sum in this table or the count. Forested= 1 in one and unforested = 1 in the other. right? Jan 13, 2016 at 2:04
• That doesn't quite make sense to me. How do I give each pixel a 1? Jan 13, 2016 at 2:27
• @user65148 gis.stackexchange.com/questions/27988/… Jan 13, 2016 at 2:31
• Im saying if all pixels are 1 or 0 then the sum of the pixels is the count. So <3800 to 1. Jan 13, 2016 at 2:33

I know this is an old question, but I wanted to give input as this is something I just had to do. I have a raster with a single band and unique values representing land cover usage and polygons representing historical wildfires. I used the Zonal Histogram tool in QGIS 3.8: to add columns with each value and the count of pixels that contain that value within the wildfire footprint (i.e. i want to get % land use within fire footprint): 