I need to calculate some zonal statistics from raster files for some polygons in a shapefile. I am using the following code which works:
eligibleLayer = QgsVectorLayer("/home/usr/Desktop/polygons.shp", "polygons", "ogr") for raster in findRasters(windMapsDirectory, '*.tif'): (infilepath, infilename) = os.path.split(raster) windMapName = infilename list1 = re.split('\W+',windMapName) list2 = re.split("_", list1) list3 = list2 string1 = ''.join(list3) if string1 == 'K': zoneStat = QgsZonalStatistics(eligibleLayer, windMapName, 'K_', 1) zoneStat.calculateStatistics(None)
The problem is that I only need the mean from the zonal statistics (no count and sum). I tried using:
if string1 == 'K': zoneStat = QgsZonalStatistics(eligibleLayer, windMapName, 'K_', 1, QgsZonalStatistics.Mean)
However, I get the following error: type object 'QgsZonalStatistics' has no attribute 'Mean' . I am using QGIS 2.8.6.