[Qgis-user] QgsZonalStatistics

Marcel Radischat m.radischat at gin-n.de
Thu Jul 10 02:21:11 PDT 2014


Hi!

The error says, that your first argument is a String, and it is actually.
Yet the call of QgsZonalStatistics(QgsVectorLayer, QString, QString attributePrefix="", int rasterBand=1) would need an object of type QgsVectorLayer

You can read about the api for QgsVectorLayer at http://qgis.org/api/2.4/classQgsVectorLayer.html#aadd199d200b5a58a7743532063e26811

HTH

Marcel

On 09 Jul 2014, at 05:13, Leo Kris Palao <lk.palao at gmail.com> wrote:

> 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
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140710/20c47c38/attachment.html>


More information about the Qgis-user mailing list