isciences / exactextractr

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

Partial_mask #64

Closed maxmarumbwa closed 2 years ago

maxmarumbwa commented 2 years ago

Hi Iam trying to implement the example below that you provided on https://gis.stackexchange.com/questions/290925/how-to-clip-a-raster-and-exclude-pixels-that-overlap-the-edge-of-the-mask-layer

When i run the script (below) with my inputs iam getting this error: Error in partial_mask(elev, mexico) : could not find function "partial_mask"

What could be the problem

################### library(sf) library(raster) library(exactextractr)

countries <- st_read('ne_50m_admin_0_countries.shp') elev <- raster('gmted2010_05deg.tif')

mexico <- countries[countries$NAME=='Mexico', ]

Get a list with one mask for each input feature.

Each cell of the mask will have a value from 0 to 1

indicating the portion of the cell that is within the

feature.

We have only one input feature, so grab the first

element.

mask <- partial_mask(elev, mexico)[[1]]

Set values in the mask to NA where less than 100% of

the cell area is within the polygon

mask[mask < 1] <- NA

plot(st_geometry(mexico)) plot(mask*elev, add=TRUE)

dbaston commented 2 years ago

The function is now called coverage_fraction. I'll update the stack exchange answer to match. Thanks!