0

I have one polygon shapefile and one raster file (both EPSG: 4326) and I am calculating the minimum, maximum and average raster value in all polygons using two methods:

  1. QGIS 3.16.10, Zonal statistics tool
  2. Python 3.9.7, Rasterstats 0.15.00, stats = rs.zonal_stats(gdf, file, stats = ['mean', 'min', 'max'], nodata = -999, all_touched=True)

When I compare the result, most numbers are different (and not just rounding errors). Sometimes, the mean, minumum and maximum ist the same. Sometimes, either of the minimum or maximum (and hence the mean) is different, sometimes all three are different.

What could be the reason behind that?

eigenvector
  • 397
  • 5
  • 22
  • 1
    Have you tried without all_touched=True – BERA Sep 10 '21 at 11:49
  • Yes: without all_touched=True many numbers are missing (probably those polygons that do not fully encompass a raster pixel?) and the numbers that are not missing are the same as in QGIS Zonal statistics. Does that suggest that QGIS Zonal statistics uses "all_touched" true whenever the polygon is smaller that the raster pixel and leaves the option away when it is bigger? – eigenvector Sep 10 '21 at 11:56
  • I'm now having exactly the same problem. I'm also using Python(rasterstats) and QGIS together. I think it depends on how it handles pixels that are on the border of the polygons. This link might be helpful for understanding how QGIS zonal statistics works. https://gis.stackexchange.com/questions/276794/how-does-qgis-zonal-statistics-handle-partially-overlapping-pixels – ShyGiantRat Feb 27 '22 at 04:39

0 Answers0