[Qgis-user] QgsZonalStatistics
Leo Kris Palao
lk.palao at gmail.com
Tue Jul 8 20:13:36 PDT 2014
Dear QGIS Users,
I am trying to run a script in python console to calculate zonal statistics
but it always throws an error. This is the script that I am running:
import qgis.analysis
vectorlayer=r'E:\filepath\vector.shp'
rasterfile = r'E:\filepath\raster.tif'
zonalstats =
qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile,str(1), 1)
zonalstats.calculateStatistics(None)
The error says:
TypeError: arguments dit not match any overloaded call:
QgsZonalStatistics(QgsVectorLayer, QString, QString attributePrefix="", int
rasterBand=1): argument 1 has unexpected type 'str'
QgsZonalStatistics(QgsZonalStatistics): argument 1 has unexpected type 'str'
However, if I load my raster and vector file in QGIS and run the script
below, it is working properly:
import qgis.analysis
vectorlayer=qgis.utils.iface.mapCanvas().layer(0)
rasterfile = qgis.utils.iface.mapCanvas().layer(1).source()
zonalstats =
qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile,str(1), 1)
zonalstats.calculateStatistics(None)
Thanks in advance for any help.
-Leo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140709/412b1d72/attachment.html>
More information about the Qgis-user
mailing list