[Qgis-user] zonal statistics with multiple bands raster
Etienne Tourigny
etourigny.dev at gmail.com
Fri Aug 9 07:31:03 PDT 2013
On Fri, Aug 9, 2013 at 10:06 AM, Xavier Vollenweider
<Xavier.Vollenweider at unige.ch> wrote:
> Dear all,
>
>
>
> Some progresses, the following little code does what I need for the first
> band (i.e. day) I think:
>
>
>
> 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))
>
> zonalstats.calculateStatistics(None)
>
>
>
> I would like know to loop over the 11117 days with something like:
>
> Day=range(1,11117,1)
>
> for i in Day:
>
>
>
> My question is hence: how do I access the other bands?
from the api [1] you should pass the band number as argument to
QgsZonalStatistics()
[1] http://www.qgis.org/api/classQgsZonalStatistics.html
>
> This doesn’t work for instance: rasterfile =
> qgis.utils.iface.mapCanvas().layer(data at 1).source()
>
>
>
> All the best,
>
>
>
> Xav
>
>
>
>
>
> From: qgis-user-bounces at lists.osgeo.org
> [mailto:qgis-user-bounces at lists.osgeo.org] On Behalf Of Xavier Vollenweider
> Sent: vendredi 9 août 2013 14:18
> To: qgis-user at lists.osgeo.org
> Subject: [Qgis-user] zonal statistics with multiple bands raster
>
>
>
> Dear all,
>
>
>
> I would like to compute zonal statistics from a raster file with multiple
> bands (11’117 actually). The raster file (.cdf) contains daily rainfall for
> Kenya from 1983 to present. I need to get the average rainfall for each
> county.
>
>
>
> I know how to do it manually for each band, but doing it on the 11’117
> bands is clearly not option...
>
>
>
> Could you provide me with a way to automatize it via the python console?
>
>
>
> Ideally, I would like the end result should be a shape file with the 11’117
> attributes that I will eventually save as a .csv. The goal is to build a
> panel dataset that I will use in R or Stata.
>
>
>
> All the best,
>
>
>
> Xav
>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
More information about the Qgis-user
mailing list