Bug report #17159

Wrong results using tool "Zonal Statistics"

Added by Pieter Roggemans about 7 years ago. Updated over 6 years ago.

Status:Closed
Priority:High
Assignee:-
Category:C++ plugins/Zonal statistics
Affected QGIS version:2.18.12 Regression?:No
Operating System:Windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:Yes Copied to github as #:25058

Description

The tool "Zonal statistics" gives wrong results for polygons that are (mainly) smaller than the pixels size of the raster data. In this case, the "count" value is a decimal number instead of an integer, and I don't find a logic in what the number is based on: no obvious correlation with area,....

To reproduce:
  1. On this location (https://drive.google.com/open?id=0B-lmgiUm-f0HQXFRYlBoUE9QM2s), you'll find 3 files:
  • L2A_T31UES_20170506T105031_TCI_10m_nomixels.tif: a sentinel2 TCI image where the mixels were set to 0 by using the "Rasterize" function to evade having mixels influence the results in "Zonal statistics". The Nodata value of the file is set to 0.
  • Polygons_error_zonalStatistics.zip: a shape file containing polygons that will produce count values that are not natural numbers. In most of the cases the number of pixels should have been 0, in some cases it should have been 1. The columns are already a calculation using "Zonal Statistics" on the tif file also provided.
  • Polygons_OK_zonalStatistics.zip: a shape file containing polygons that will produce count values that are correct. The "nodata" pixels are ignored, as is to be expected. The columns are already a calculation using "Zonal Statistics" on the tif file also provided.
  1. Unzip the zip files
  2. Add the above files to a project
  3. Do "Raster"/"Zonal statistics"/"Zonal statistics".
  4. Choose the tif file above, and either the "Error" shape file or the "OK" shape file + make sure you check the 'count' field.
  5. All 'count' values of the count column will be a decimal number for the 'Error' shapefile, for the 'OK' shapefile they will be integers.

Any questions are ofcourse very welcome.

Associated revisions

Revision 83d44b9f
Added by Nyall Dawson over 6 years ago

Fix zonal statistics calculations when pixel size is greater than
polygon size

Fixes #17159

History

#1 Updated by Giovanni Manghi about 7 years ago

  • Category changed from Rasters to C++ plugins/Zonal statistics

The same has been seen on master, where the tool is only available as part of the Processing toolbox.

#2 Updated by Giovanni Manghi over 6 years ago

  • Priority changed from Normal to High

#3 Updated by Nyall Dawson over 6 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

Also available in: Atom PDF