I'm computing some zonal statistics, and was comparing the results obtained using the GDAL cookbook example code here with the rasterstats zonal_stats function.
I want to compute the mean value per polygon, as well as the number of raster pixels that contributed to that calculation. I think rasterstats gives you the number of contributing pixels with their 'count' statistic.
I'm not sure how to get that with the GDAL code, though. I first thought that's what their 'numpoints' variable was counting, but their numpoints corresponds to the number of points within a ring, and I think that means the number of vertices of the ring (please correct me if I'm wrong).
Can anyone explain how to compute the number of raster pixels contributing to the GDAL cookbook calculation? Counting the number of pixels of their 'zoneraster' array variable doesn't come close to agreeing with the rasterstats count, either.
true
to 1 andfalse
to 0. This is a good approach because it accounts correctly for any NoData cells in the original value grid.