Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'd like to calculate zonal statistics for a raster where the zones are defined by polygons in a vector layer within QGIS. Specifically I'm interested in calculating the median and mode raster values for each feature. QGIS includes a 'zonal statistics' plugin, but it only seems to calculate mean and sum statistics.

Is there another plugin that could do this task for me? I've looked at the source code for the existing statistics plugin and it looks like it would be fairly easy to modify, although my skills in C++ are fairly lacking.

QgsZonalStatistics source: http://www.qgis.org/api/qgszonalstatistics_8cpp_source.html

How to use QGIS Zonal Stats Plugin from Python Console?

Raster statistics available in ArcGIS: http://resources.arcgis.com/en/help/main/10.1/index.html#//009z000000w7000000

share|improve this question
    
I'm using the The v.rast.stats module in GRASS GIS. working on a huge data set (all europe at 100 m resolution). I have 32GB of installed memory (RAM). I have this error: Raster MASK found, temporarily disabled ERROR: G_calloc: unable to allocate 236326912 * 1 bytes of memory at raster.c:83 ERROR: An error occurred while converting vector to raster any suggestion? thanks –  Gra Aug 22 at 14:33
    
This doesn't actually answer the question. Instead of posting an answer, please create a new question, with a link to this question if it is relevant. –  Evil Genius Aug 22 at 14:52
    
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. –  Aaron Aug 22 at 14:53
    
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. –  vinayan Aug 22 at 15:18

2 Answers 2

up vote 3 down vote accepted

I haven't calculated mode values before (most frequently occurring value), but at least for quantile values you could try to use the plugin I coded (LecoS). Although not primarily intended for this use it is able to calculate some "zonal statistics" for polygon overlays.
How to:

  • Install numpy and scipy for your System and QGIS. On Windows choose the OSGEO4W advanced Install and select python-numpy and python-scipy. On Linux consult your linux package manager/compiler.
  • Download the experimental(!) LecoS plugin via the plugin downloader. The rest should be pretty self-explaining. enter image description here

Please pay attention that the plugin is still experimental and calculation might fail sometimes! If you want a clear procedure suited for your needs than i would advise you to look into numpy and also R with the raster and sp packages. I am also happy to see detailed bug reports and i will do the best i can to fix them. However if the calculation fails for you, you better lookout for other tools as well.

share|improve this answer
1  
raster, numpy, and R while indeed can do those operations are limited on the amount of ram your machine has.(meaning if your raster is more than you memory can handle, you program will crush). If your data are problematic in that kind of aspect, I recommend importing and using specialized GIS software, like grass –  nickves Apr 27 '13 at 17:57
1  
I've managed to adapt the code from LecoS to do exactly what I need to do. I never would have though to use PIL to rasterize the features - very clever. The polygons I'm using are individual buildings and thus aren't very large, so I don't expect to hit any memory allocation issues. –  Snorfalorpagus Apr 28 '13 at 12:13

The v.rast.stats module in GRASS GIS is very powerful and will allow you to calculate univariate statistics (n, min, max, range, mean, stddev, variance, coeff_var, sum) from a raster map based on polygon boundaries.

share|improve this answer
    
See this Wiki page how to use GRASS GIS in QGIS: grasswiki.osgeo.org/wiki/GRASS_and_Sextante –  markusN Apr 27 '13 at 9:24
1  
I think the OP wants to calculate the median and mode values, which is not possible with the v.rast.stats tool (you listed the available stats yourself) –  Curlew Apr 27 '13 at 10:15
1  
the documentation page provided above states that the -e flag can be used to calculate the median value (as well as the percentiles). the mode shouldn't be too hard to calculate with some scripting. –  dmci Apr 27 '13 at 12:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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