<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi!<div><br></div><div>The error says, that your first argument is a String, and it is actually.</div><div>Yet the call of <i>QgsZonalStatistics(QgsVectorLayer, QString, QString attributePrefix="", int rasterBand=1) </i>would need an object of type <i>QgsVectorLayer</i></div><div><i><br></i></div><div>You can read about the api for QgsVectorLayer at <a href="http://qgis.org/api/2.4/classQgsVectorLayer.html#aadd199d200b5a58a7743532063e26811">http://qgis.org/api/2.4/classQgsVectorLayer.html#aadd199d200b5a58a7743532063e26811</a></div><div><br></div><div>HTH</div><div><br></div><div>Marcel</div><div><br><div><div>On 09 Jul 2014, at 05:13, Leo Kris Palao <<a href="mailto:lk.palao@gmail.com">lk.palao@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Dear QGIS Users,</div><div><br></div><div>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:</div><div><br></div>

<div><div>import qgis.analysis</div><div>vectorlayer=r'E:\filepath\vector.shp'</div><div>rasterfile = r'E:\filepath\raster.tif'</div><div>zonalstats = qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile,str(1), 1)</div>

<div>zonalstats.calculateStatistics(None)</div></div><div><br></div><div>The error says:</div><div><br></div><div>TypeError: arguments dit not match any overloaded call: QgsZonalStatistics(QgsVectorLayer, QString, QString attributePrefix="", int rasterBand=1): argument 1 has unexpected type 'str'</div>

<div>QgsZonalStatistics(QgsZonalStatistics): argument 1 has unexpected type 'str'</div><div><br></div><div>However, if I load my raster and vector file in QGIS and run the script below, it is working properly:</div>

<div><br></div><div><div>import qgis.analysis</div><div>vectorlayer=qgis.utils.iface.mapCanvas().layer(0)</div><div>rasterfile = qgis.utils.iface.mapCanvas().layer(1).source()</div><div>zonalstats = qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile,str(1), 1)</div>

<div>zonalstats.calculateStatistics(None)</div></div><div><br></div><div>Thanks in advance for any help.</div><div>-Leo</div></div>
_______________________________________________<br>Qgis-user mailing list<br><a href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a><br>http://lists.osgeo.org/mailman/listinfo/qgis-user</blockquote></div><br></div></body></html>