Ferramentas do usuário

Ferramentas do site


05_curso_antigo:r2015:alunos:trabalho_final:jhon.sarria:start

Jhon Jairo Ospina Sarria

Trabalho final

Página de Ajuda

 
                                                                     R Documentation
 
 cut_raster()
 
 
        Extraction of specific area from the RasterLayer (Bioclimatic variables)
        
 
 Description
 
    cut_raster extract a specific area of the RasterLayer (Bioclimatic variables) 
    downloaded from Worldclim. See Note (Packages needed to manipulate geographic data). 
    
 Usage
 
    lapply(X, cut_raster)
    The function cut_rasteris applied to objects RasterLayer (X), thereby requiring the 
    function lapply to be executed (see Note).
    
 cut_raster =function(x) 
 { 
 function instructions
 return (results)
 }
 
 Arguments
 
 x	any R object.
 
 Details
 
    The purpose of this function is to extract a specific area of the RasterLayer 
    (Bioclimatic variables) downloaded from Worldclim (Hijmans et al. 2005). The 
    RasterLayer obtained from Worldclim (bioclimatic variables) are for particular 
    areas (Hijmans et al. 2005), which must be adjusted according to the area of 
    interest that will be used in ecological niche modeling (Warren and Stephanie 2011). 
    One way to do this procedure is to extract the area of interest one by one in the 
    19-bioclimatic variables. In addition is necessary also to modify the resolution of 
    each RasterLayer obtained in the cut. Finally it is also necessary export each new 
    RasterLayer to a specific format, because all environmental layers must be in ASCII 
    format to run MaxEnt (Young 2011). 
    
 The function cut_raster performed these three procedures simultaneously on RasterLayer 
 (Bioclimatic   variables),according to the supplied specifications (size of area, 
 resolution and format). 
 
 Value
 
    RasterLayer
    
 Note
    
    Packages needed to manipulate geographic data
    1. raster: Reading, writing,manipulating, analyzing and modeling of gridded spatial 
       data
    2. maptools: Set of tools for manipulating and reading geographic data
    3. rgeos: Used to tackle problems with several variables defined in a space of any dimensions 
    4. rgdal: It is a translator library for raster and vector geospatial data formats that is 
       released under an X/MIT style Open Source license by the Open Source Geospatial Foundation 
       
       
 lapply
     
     The function lapply (X, FUN) returns a list of the same length as X (RasterLayer), each 
     element of which is the result of applying the function (cut_raster) to the corresponding 
     element of X (RasterLayer). 
     
 Examples
     
     Input files in directory
     
     1. RasterLayer of bioclimatic variables of South America (see file: Annual Mean 
        Temperature in South America.asc).
     2. Shapefile of area to be extracted in each RasterLayer of South America 
        (see file: shape_brazil). 
        
     Load the input files
     
     list_RasterLayer=list.files("/name directory", pattern=".asc")   
     ## List elements with asc. format (RasterLayer) found in the directory
     
     shape=readShapePoly(file.choose())
     ##Interactively window for choose data from a polygon shapefile (Shapefile)
     
     plot(shape)
     ##Verify that the shapefile was loaded
     
     cut_raster =function(x) { 
     rasters=raster(x)
     cut=mask(rasters,shape)
     raster_final=aggregate(cut, fact=10)
     writeRaster(raster_final, filename=paste(rasters@data@names,"BRAZIL",".asc", sep=""), 
     format="ascii")
     }
     
     lapply(list_RasterLayer, cut_raster)
     
     ### The function lapply applies the function cut_raster on each RasterLayer present 
     in the list_RasterLayer. It takes some minutes per each RasterLayer
     
 References
     
     Warren, D.L. S. N. Seifert. 2011. Ecological niche modeling in Maxent: the importance 
     of model complexity and the performance of model selection criteria. Ecological 
     Applications 21(2): 335-342
     
     Hijmans, R.J., S.E. Cameron, J.L. Parra, P.G. Jones and A. Jarvis, 2005. Very high 
     resolution interpolated climate surfaces for global land areas. International Journal 
     of Climatology 25: 1965-1978.
     
     Young, N. 2011. A MaxEnt Model v3.3.3e Tutorial (ArcGIS v10). 
     [[http://ibis.colostate.edu/WebContent/WS/ColoradoView/TutorialsDownloads/A_Maxent_Model_v7.pdf|Tutorial]].

Código da Função

  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)

Arquivo da Função

05_curso_antigo/r2015/alunos/trabalho_final/jhon.sarria/start.txt · Última modificação: 2020/08/12 06:04 (edição externa)