I have soil map with 3 RGB bands and I need a zonal histogram for polygons from this raster (how many pixels of each soil the polygon contains).

First I tried to sieve the raster and then get zonal histogram, but I found that sieve tool by default uses first band (red in my case). So different colors with the same value in the red band get the same value after the sieve. I tried this with another band but result was the same. Also I tried to create raster layer with raster calculator (just sum over values from all 3 bands).

Can anybody recommend any solution using QGIS?

enter image description here

  • If you wish to also ask about doing this using ArcGIS Desktop then please do that in a separate question.
    – PolyGeo
    Commented Mar 28, 2020 at 13:16
  • Do you want to individualize bands for calculating zonal histogram in each one?
    – xunilk
    Commented Mar 28, 2020 at 14:54
  • In ArcGIS, use the Combine tool to a unique value for each unique combination of band values. You'll need to each band to the tool separately, don't add the 3 band raster itself.
    – user2856
    Commented Mar 28, 2020 at 21:22

1 Answer 1


You could use RGB to PCT tool to convert the 3-bands raster to a single band raster (with an associated color palette).

This tool can be found in the Processing Toolbox | GDAL | Raster conversion.

enter image description here

Set the number of your soil categories (e.g. 12 colors in the above example) and run the tool.

Then the tool will return RGB to PCT layer which mimics the input raster as much as possible.

enter image description here

Now run Zonal histogram tool on this layer to obtain the soil pixels per each designated polygon.

Output zones attribute table:

enter image description here

  • Hi, Kazuhito! Thank you for you answer.
    – belinarch
    Commented Mar 28, 2020 at 18:17
  • Hi, Kazuhito! Thank you for your answer. I've tried this method as well, but 1) I don't know the exact number of soils and the whole area I need to analyze is more than 100000 km2 and count them is not an option 2) Even if I try sample areas with few soil type this method gives back layers with mixed pixels and the final result contains much more types than it should. For example in your solution two first polygons should have 4 types of soils but not 9.
    – belinarch
    Commented Mar 28, 2020 at 18:27
  • @belinarch You would better go back to the data provider and find the numbers. If it is not possible, you will need to find it yourself by some trials. (1) Run RGB to PCT tool then (2) Run PCT to RGB tool to see if it reproduce the original colors. (3) Repeat the process as necessary.
    – Kazuhito
    Commented Mar 28, 2020 at 22:50

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.