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?

3
  • 1
    Have you tried without all_touched=True
    – Bera
    Commented Sep 10, 2021 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? Commented Sep 10, 2021 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. gis.stackexchange.com/questions/276794/… Commented Feb 27, 2022 at 4:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.