I am fairly new in R and I am trying to create a new raster by using a spatial polygon layer. I have the code written by using the mask function and the output is essentially what I want, but I'm missing some areas of the raster I need (see image). I noticed that the areas missing from the resulted raster are polygons that are either an "island" or a polygon within a polygon. I've been searching the web and R documentation to see if there's a better function out there than mask() but I can't find anything. Is there a different function that would do the same exact thing as the mask function but also include those areas currently missing? Do I need to add something to my code so that the mask function includes all polygons?
library(raster) library(rgdal) library(sp) dsm_sa <- raster("small_area_dem3.tif") shapefile <- readOGR("disagg.shp") maskDSM <- mask(dsm_sa, shapefile, inverse=FALSE, updatevalue=NA, updateNA=FALSE) writeRaster(mask_DSM,"dsm_sa.tif","GTiff")
The brown raster is the input raster while the black is my output raster. The green polygons are my polygon layer. The blue numbers represent polygons within polygons and the blue x is an "island" - the surrounding area should not be included in my final raster