-3

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?

green is my polygon, blue is the resulting mask

MikeJewski
  • 357
  • 2
  • 13

1 Answers1

0

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.

Source: Masking low quality raster with polygons in R gives weird overhang?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63