====R Function: Function to extract a specific area of the RasterLayer (Bioclimatic variables) downloaded from Worldclim=== ====Author: Jhon Jairo Ospina-Sarria==== **Packages required**: install.packages("raster") install.packages("maptools") install.packages("rgeos") install.packages("rgdal") **Function** **cut_raster =function(x)** ### Argument is any R object { **rasters=raster(x)** ### Create a RasterLayer which is applied to the R object (x) cut=mask(rasters, raster/shape) ### Create a file mask (cut) that has the same values as the raster, except for the cells that are NA (or other maskvalue) in a 'mask'. The mask can be either another RasterLayer of the same extent and resolution, or a Spatial object in which case all cells that are not covered by the Spatial object are set to updatevalue. **raster_final=aggregate(cut, fact=X)** #### Adjusting resolution of the RasterLayer created with the function mask (cut). The function aggregate carry out the aggregation of rectangular areas (cells) causing lower resolution (larger cells) in the new RasterLayer created (raster_final). The function (fact=) expressed as number of cells in each direction (horizontally and vertically), therefore this function to adjust the resolution of the raster (example: fact=10 result in 10*10=100 times fewer cells in the RasterLayer object). **writeRaster(raster_final, filename=paste(rasters@data@names,"NAME",".asc", sep=""), format="ascii")** ### Write an entire RasterLayer object based on the file created in the previous command line (raster_final). The function paste() indicates that each RasterLayer must have the same name plus the inclusion of the word "NAME". With this function also indicates that the output files (RasterLayer) must have the asc. format. } === The function cut_raster is applied to objects RasterLayer (X), thereby requiring the function lapply to be executed (see Help) ===