Bug report #17159
Wrong results using tool "Zonal Statistics"
|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|
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:
- 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.
- Unzip the zip files
- Add the above files to a project
- Do "Raster"/"Zonal statistics"/"Zonal statistics".
- Choose the tif file above, and either the "Error" shape file or the "OK" shape file + make sure you check the 'count' field.
- 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.