I have a big shapefile ( more than 500.000 polygons) and a raster file. I want to calculate the majority pixel per polygon, which I can do with zonal statistics. However, I also need the percentage of this majority value per polygon. There is a post that suggests using the zonal histogram in batch mode, which I do not how to do use. Could somebody explain in more detail this solution or a different one?

This is the link for the post: Counting percentage of raster cell inside polygon using QGIS

  • You need batch mode only if you have more than one vector layer. As I understood, you have 500.000 polygons on one layer, so no need for batch mode.
    – Babel
    May 22, 2023 at 12:02
  • Depending on how large your polygons are/how many cells each polygon contains, you might hit performance limitation. So it very much depends on the data you have what would be the most performant way to do so. But in principle, I don't see why the linked solution should not work in your case.
    – Babel
    May 22, 2023 at 12:40

1 Answer 1


You dont need batch:

1 Zonal statistics to find the majority value for each polygon: enter image description here

2 Zonal histogram with the zonal statistics as input to count the number of pixels of each raster class, for each polygon. Each class is added as a column: enter image description here 3 Field calculator to calculate the percentages. Modify the expression to include all raster classes that exists as columns in zonal histogram output.

"HISTO_2" , "HISTO_41" , "HISTO_42" , "HISTO_51" , "HISTO_52" , "HISTO_53" , "HISTO_61" , "HISTO_111",  "HISTO_112" , "HISTO_113" , "HISTO_114" , "HISTO_115" , "HISTO_118" , "HISTO_121" , "HISTO_122" , "HISTO_123" , "HISTO_124" , "HISTO_125" ))/
 array_sum( array(
"HISTO_2" , "HISTO_41" , "HISTO_42" , "HISTO_51" , "HISTO_52" , "HISTO_53" , "HISTO_61" , "HISTO_111",  "HISTO_112" , "HISTO_113" , "HISTO_114" , "HISTO_115" , "HISTO_118" , "HISTO_121" , "HISTO_122" , "HISTO_123" , "HISTO_124" , "HISTO_125" ))

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.