I want to calculate the zonal statastics from multi band raster for a polygon layer. When I am using this snippet of code:
vectorlayer=qgis.utils.iface.mapCanvas().layer(0)
rasterfile = qgis.utils.iface.mapCanvas().layer(1).source()
zonalstats = qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile,"Zonal_")
zonalstats.calculateStatistics(None)
it is updating the field names but the values are NULL in the attribute table. So if I want to get the values to be updated, how can I do that?
Best Answer
Not sure why you're getting NULL values but the following code worked for me (note that I call the QGIS Zonal Statistics tool from the Processing plugin and I want to load the result):
The following is the help description for the parameters required which you can edit in your code:
Hope this helps!