I am using QGIS 1.8.0 on a Windows Home Premium 7 machine. I have a single band TIFF that is 187 MB in size. My vector polygon shapefile represents a regular grid of a 147x112 36kmx36km grid cells. Both files have the same map projection parameters. I installed the NextGIS ZonalStats plugin, and tried running it. I have also tried the embedded zonal stats plugin. Finally, I have tried the following commands in the Python command window:

rasterfile = qgis.utils.iface.mapCanvas().currentLayer().source()
vectorlayer = qgis.utils.iface.mapCanvas().currentLayer()
zonalstats = qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile)

In each case, the system fails to run to completion. Instead, I get the "Not Responding" error.

Sometimes Windows will ask me to kill the program. Other times, I have to kill it in the Task Manager.

Any help with this will be greatly appreciated as I am trying to move away from ArcGIS.

  • What is the CRS set to?
    – Willy
    Jan 14, 2013 at 0:11
  • In response to Willy, the two files have the following projection parameters: +proj=longlat +datum=WGS84 +no_defs The project projection parameters that I am using for display purposes are as follows: +proj=lcc +lat_1=33 +lat_2=45 +lat_0=40 +lon_0=-97 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs
    – James
    Jan 14, 2013 at 15:43
  • What would be the EPSG codes of those projections? Can you check your vector for errors? And if you could put examples of the files on the web that might be a chance to troubleshoot.
    – Willy
    Jan 16, 2013 at 1:40
  • The EPSG is 4326. If you send me an email at terrak[email protected], I will post details on how to retrieve the data.
    – James
    Jan 17, 2013 at 1:27

3 Answers 3


This could be happening because the analysis tools first need to be imported with the following command before it can access the zonal stats tools (you can put it before any of the other commands):

import qgis.analysis

That said, I would expect it to show an error rather than not responding. Also, there is a sequence to the commands. You need to first select the TIFF layer in the table of contents on the left, then execute the rasterfile = ... command. Then you select the vector layer and execute the vectorlayer = ... command. Then you can execute the other two commands to generate the statistics.


Most likely the vector file is topologically broken. Try and repair it first, and then retry.

The link provides a short guide on how to accomplish it with grass toolbox.

How to check Topology in QGIS?


Make sure that the two layers are in the same CRS and ensure that the topology is valid then try this:

from qgis.analysis import QgsZonalStatistics

shape_to_load = "C:\\path\\to\\shape.shp"
layerName= "Anything"
vectorlayer = QgsVectorLayer(shape_to_load, layerName, "ogr")
prefix ="Stats"

zoneStat = QgsZonalStatistics(vectorlayer, rasterlayer,prefix)

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.