I would like to know how the zonal_stats() function from the library rasterstats works, as I am calculating the mean values of a raster within a polygon. If a raster cell touches partially the polygon boundaries, is the whole cell included in the statistics? or is it "clipped" and then calculated? I cannot see a reference in rasterstats documentation.


1 Answer 1


It's explained in the docs that @Spacedman linked, via the all_touched parameter:

all_touched: bool, optional

Whether to include every raster cell touched by a geometry, or only those having a center point within the polygon. defaults to False
  • Thank you mikewatt, I haven't seen this parameter. Sep 17, 2021 at 7:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.