isciences / exactextract

Fast and accurate raster zonal statistics
Apache License 2.0
255 stars 33 forks source link

value type distribution within a polygon #11

Closed scra88le closed 4 years ago

scra88le commented 4 years ago

If I have a raster contain cells with integer values (say 1 to 10), and I'd like to know the percentage cover for each value type, from a subset of the raster as determined by an sf polygon, how should I go about doing this? I'd like to return a vector containing percentages (one for each value type), for a given bounding polygon. I thought it would be something along the lines of:

exact_extract(raster, poly_sf, function(value) count(value)/no_of_cells_in_poly_sf)

But I'm not sure how to extend this to return a vector for the % cover for each value type. Thank you

scra88le commented 4 years ago

I've moved this to exactextractr