# This script computes the MEAN in zonal statistics for many rasters for polygon vector data. 

import glob, os, qgis.analysis
from qgis.analysis import QgsZonalStatistics

vectorlayer = QgsVectorLayer('path to vector file', 'zonepolygons', "ogr")  # Insert path to vector file here.
rasterfolder = 'Path to folder with raster data' # Insert path to folder with raster data here (all raster must be in *.tif format)
os.chdir(rasterfolder)
for lyr in glob.glob("*.tif"):
    band = 1
    zoneStat = QgsZonalStatistics (vectorlayer, lyr,lyr[:-3], band, QgsZonalStatistics.Mean)
    print(zoneStat)
    zoneStat.calculateStatistics(None)
print('done')

