I got this Python script from this previous post. I've edited it for my project but nothing happens when I execute it. I downloaded the zonal statistics plugin, and usually when I run it, it adds a new field to the shapefile with the statistics I need, for example minimum. Since I need to do it multiple times, I was hoping to use the script. I tried the batch execute, but for GDAL it doesn't allow you to select one statistic, and Saga always gives an error somewhere.
Here's the script I use:
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('D:/all_structures_tez.shp', 'zonepolygons', "ogr")
# specify raster filename
rasterFilePath = 'D:/slow.tif'
# usage - QgsZonalStatistics (QgsVectorLayer *polygonLayer, const QString &rasterFile, const QString &attributePrefix="", int rasterBand=1)
zoneStat = QgsZonalStatistics (polygonLayer, rasterFilePath, 'pre-', 1, QgsZonalStatistics.Min)
zoneStat.calculateStatistics(None)
QGIS ver 2.18.3
all_structures_tez
after running it, there are no added columns, right?