1

I have used zonal statistics from processing to calculate the raster statastics with polygon layer.

processing.runalg('qgis:zonalstatistics', rlayersource, 1, vlayer, None, True, Path)

But this is taking more time if the no of polygon blocks are more. So i found that we can use numpy and scipy to calculate the statistics of the raster.

How can i do that?

1
  • 1
    I found the rasterstats package to be quite a bit faster than QGIS' implementation of raster statistics.Maybe take a look at that before you try to reinvent the wheel in Python.
    – Kersten
    Sep 3, 2015 at 11:39

1 Answer 1

1

If you have numpy and scipy properly configured you could try out the LecoS plugin. Depending on your system you might also have to install the python imaging library (however it is often co-installed).

Ether run it in directly in the processing toolbox enter image description here

or via the console (should be sth. like this for the mean. Not tested!)

processing.runalg('lecos:overlayrastermetricspolygons', 'raster', 'polygons', False,0,0,False, '~/out.csv')

Alternatively you could look into LecoS source how to use numpy and scipy for extracting data from raster layers. Uploaded it on github.

Your Answer

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

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