How does one go about obtaining a summary of the counts of cell values within a raster in QGIS? I know QGIS is doing this, in order to provide the summary statistics and histogram in the properties of the layer. I do not need the summary statistics nor a histogram image, but rather counts of individual values.

It looks like there was at one point an attempt to add a special feature for this (Feature #4321, http://hub.qgis.org/issues/4321).

Am I missing something really obvious?

up vote 21 down vote accepted

r.report from GRASS in the Processing toolbox lets you get a count if you set the Units to c.

getting count of raster values with r.report in qgis processing with grass

Results in (this includes NoData represented as int 0):

+-----------------------------------------------------------------------------+ 
| Category Information | cell| 
| #|description | count| 
|-----------------------------------------------------------------------------| 
|  0| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |147600504| 
| 10| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 46945| 
| 20| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 34371070| 
| 30| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 38494918| 
| 34| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 3542216| 
| 50| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 37053253| 
| 80| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 24184039| 
|110| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 8622768| 
|120| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 4279049| 
|122| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 3126056| 
|131| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 786| 
|133| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 452832| 
|136| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 29765| 
|137| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 317| 
|140| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 1725632| 
|147| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 130470| 
|153| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 1153795| 
|162| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 125372| 
|167| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 176| 
|175| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 36144| 
|181| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 160465| 
|188| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 50| 
|194| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 4854| 
|210| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |257580769| 
|220| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 35232865| 
|230| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 6891335| 
|-----------------------------------------------------------------------------| 
|TOTAL |604846445| 
+-----------------------------------------------------------------------------+

Taken from: example raster with paletted band

  • @SaultDon, I tried to use r.report on my rasterdata to count individual values, like in your example. But, I only got a summary - number of pixels,min/max etc. The report only contains: <pre></pre> What can I be missing? I changed the units to 'c'. – SoS Feb 11 '16 at 11:07
  • @SoS It's difficult to guess without more info or a sample data set to test on. – SaultDon Feb 11 '16 at 15:35
  • This is great, but is there a solution that produces a plainer file- either a csv or a dbf, so that the user can Import it directly to Excel or use it as Input for another tool? – MonsterMushroom Sep 21 '17 at 9:59
  • 2
    @MonsterMushroom use r.stats - it can output in a computer friendly format ready for spreadsheets, in fact r.report uses r.stats in the background – SaultDon Sep 21 '17 at 17:36
  • @SaultDon Thanks! – MonsterMushroom Sep 22 '17 at 7:44

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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