0

I'm trying to calculate zonal statistics on some imagery that has a bunch of pixels that come out as 0s. This is affecting the mean value for the area, or at least seems to be.

I'm using the rasterstats library. Is there some flag to ignore a certain value?

  • You've provided very little information about what you've tried (i.e. post your code if you want specific answers). Can you not just use numpy indexing to set the zeros to nans? See stackoverflow.com/questions/27778299/… I am not familiar with rasterstats, but I assume it treats nan's as invisible. – Jon Oct 4 '17 at 14:45
1

The function help of zonal_stats links to gen_zonal_stats since all the parameters you pass to raster_stats are passed to gen_zonal_stats. I think the parameter you are looking for is nodata. The help for this parameter says: If raster is a GDAL source, this value overrides any NODATA value specified in the file’s metadata. If None, the file’s metadata’s NODATA value (if any) will be used. defaults to None.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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