How do I use zonal statistics in the python console to get CSV/dbf output?
I have used the code like this:
# Python code for Zonal statistics
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import iface
from qgis.analysis import QgsZonalStatistics
#specify polygon shapefile vector
polygonLayer = QgsVectorLayer(' E:/Trash/BhagaP.shp', 'zonepolygons', "ogr")
# specify raster filename
rasterFilePath = 'E:/Trash/Test48P.img'
# usage - QgsZonalStatistics (QgsVectorLayer *polygonLayer, const QString &rasterFile, const QString &attributePrefix="", int rasterBand=1)
zoneStat = QgsZonalStatistics (polygonLayer, rasterFilePath, 'pre-', 1, QgsZonalStatistics.Mean)
zoneStat.calculateStatistics(None)