I am pretty new to R, and have been attempting to use the mask function on a raster image of 250mx250m resolution. My problem is that for some reason I am getting overhang, as there are pixels which lie both inside and outside of the polygon. Is there a way to tighten the tolerance level of mask so that only the pixels within a certain percentage inside the polygon are accepted?
1 Answer
When asking a question please show some of the code you have been using. In fact, you should try to create a self-contained reproducible example (there are many examples on how to that on this website). Otherwise it is almost impossible to help you.
I am guessing that you are using the rasterize
function from the raster
package.
The grid cells are rather large relative to the polygons you are using. rasterize uses the center of the cell to determine if it is covered. However, if you use argument getCover=TRUE
you will get a value between 1 to 100 indicating the percentage of each cell that is covered. You could then use a threshold of your choice.