Bug report #11135

Zonal Statistics is calculating wrong mean values

Added by Marcel Foelsch over 9 years ago. Updated about 7 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Analysis library
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:19463

Description

Hello,
the Zonal Statistics tool doesn't work correctly (wrong MEAN value). Here is a link to the Forum-question: [[http://gis.stackexchange.com/questions/112435/is-there-an-issue-with-zonal-statistics-calculating-wrong-mean-values]]

I'm using QGIS 2.2.

ZonalStat.zip (7.86 KB) Marcel Foelsch, 2014-09-04 12:01 AM

rast2.tif - Copy of the provided raster with no data pixels turned into zeroes (193 KB) Giovanni Manghi, 2014-10-05 08:18 AM

Associated revisions

Revision 213a22bc
Added by Nyall Dawson almost 9 years ago

Fix calculation of zonal stats when source contains nodata or nan
pixels (fix #11135)

Revision a0017f97
Added by Nyall Dawson almost 9 years ago

Fix calculation of zonal stats when source contains nodata or nan
pixels (fix #11135)

History

#1 Updated by Giovanni Manghi over 9 years ago

  • File rast2.tif added
  • Category set to 94
  • Affected QGIS version changed from 2.4.0 to master

I can confirm this on the latest master, where both the tool in the raster menu and in the processing toolbox (one C++ and the other python) make the same error and give the wrong result.

The provided test raster has no data areas and once transformed them into 0 then the zonal stats tool returns the same mean value, meaning that it seems no data is taken into account as 0.

Please notice also that:

with the processing tool and the provided sample raster the "min" and "max" values do not make any sense (and it seems to give the wrong values with any input raster)

other computed values too, both with the processing tool and the C++ plugin seems odd.

#2 Updated by Alexander Bruy over 9 years ago

  • Category changed from 94 to Processing/QGIS

#3 Updated by Paolo Cavallini almost 9 years ago

  • Category changed from Processing/QGIS to 115

I confirm; the problem seems to lay in the core C++ plugin rather than in Processing, and it is due to NULL values

#4 Updated by Nyall Dawson almost 9 years ago

  • Status changed from Open to Closed

#5 Updated by Paolo Cavallini almost 9 years ago

Thanks Nyall. Has this been backported?

#6 Updated by Giovanni Manghi about 7 years ago

  • Category changed from 115 to Analysis library

#7 Updated by Spencer Gardner about 7 years ago

  • Status changed from Closed to Reopened

I'm seeing a regression in this on 2.18.3 in Linux. There are no Zonal Statistics in the Raster menu, but the Processing routine seems to be having the same problem as described above. Is this a bad implementation in processing now? If so, I'll open a new bug.

#8 Updated by Nyall Dawson about 7 years ago

  • Status changed from Reopened to Closed

Sounds like a different issue - processing doesn't reuse this library (until 3.0, when it does). You'll need to open a new issue against processing.

Also available in: Atom PDF