isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
281 stars 26 forks source link

"count" as summary #39

Closed chljl closed 3 years ago

chljl commented 4 years ago

Can you give an example of using "count" as the summary operation. I'm not sure what the correct grammar is. exact_extract(rast, poly,'count', const), where const the the cell value I want to count? Also, what if I want to count cells with the value large than a given value?

dbaston commented 4 years ago

count counts all of the pixels, regardless of their value. If you want to count cells with a value larger than a given value you can use a custom function, like function(value, coverage_fraction) sum(coverage_fraction[value > threshold])

chljl commented 4 years ago

Thanks a lot. That works. The manual says "count- the sum of fractions of raster cells with defined values covered by the polygon“. I thought it means that count can accept user defined values.