![]() ![]() R <- mask(merge(r, mask.raster), mask.raster, filename = label, format = "GTiff",īelow is a trivial example based on some readily available data in the maptools and biomod2 packages. # merge the new raster with the mask raster and export to the working # set the cells associated with the shapfile to the specified value # convert the shapefile to a raster based on a standardised background # the output raster, setting om & proj.to to the appropriate # use transform=TRUE if the polygon is not in the same coordinate system as Shp2raster <- function(shp, mask.raster, label, value, transform = FALSE, om = NA, ![]() The more individual polygons that need to filtered through and extracted, the longer it will take. The function is relatively quick, although is somewhat dependant on how complicated your shapefile is. Return as an object in the global R environment.If desired, plot the new raster using map=TRUE.Export as a tiff file in the working directory with the label specified in the function call.Merge the raster with mask.raster, so that the background values are equal to the value of mask.raster.Set the value of the cells of the raster that represent the polygon to the desired value. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |