Skip to main content
1 of 3
zonalstats = qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile)
zonalstats.calculateStatistics(None)

calculates by default just Count, Sum and Mean (as you can tell from Raster -> Zonal Statistics in QGIS Desktop, it can do a lot more).

If you, for instance, want to compute just the Mean you have to use:

zonalstats = qgis.analysis.QgsZonalStatistics(vectorlayer, rasterfile, QgsZonalStatistics.Mean)
zonalstats.calculateStatistics(None)

see API for all options.