5

I have been trying to use the QGIS zonal statistics plugin. My raster has a nodata value of -99999 and all other values are positive. After computing the mean zonal statistics there are a number of features that have a negative mean indicating that the Zonal Stats plugin must be included nodata values in the calculations. Is there a workaround for this or am I doing something wrong:

from qgis.analysis import QgsZonalStatistics
vectorLayer = qgis.utils.iface.activeLayer()
rasterLayer = "path/to/my/raster/et_30.tif"
prefix = 'Test'
zoneStat = QgsZonalStatistics(vectorLayer, rasterLayer,prefix)
zoneStat.calculateStatistics(None)
  • I'm hoping a simple change in what you're doing will solve the problem, but there are workarounds. One idea is to use zonal stats to count the number of NoData cells within each zone and use that information to adjust the statistics. It will work with additive stats like means and variances, but not with rank-based stats like medians. Some stats will need no adjustment at all, such as the max (assuming it exceeds the NoData value). Other stats can be recovered by doing the calculation twice, using different NoData codes. (E.g., you can find the min by using a very large NoData value.) – whuber Jul 19 '13 at 17:38
  • Has anyone found a solution to this problem? – user25843 Jan 15 '14 at 19:43
1

It's not your fault. Here's the ticket for this issue: http://hub.qgis.org/issues/9349

  • According to the ticket, the issue should be solved now. – AndreJ Dec 19 '14 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.