[Biomod-commits] RasterStack

Wilfried Thuiller wilfried.thuiller at ujf-grenoble.fr
Wed Jul 7 20:36:32 CEST 2010


Dear César,

Like all exports from BIOMOD, raster data are stored in binary R format. These files are thus compressed and easy to load in R. The main advantage of this format is that the "class" of the object is kept. 

The only thing to do is: 

load("I:/Var/Prec_GAM.raster")   ###The data are automatically loaded in the R workspace with the name BIOMOD gave to the binary file. The class of the object is then rasterLayer/rasterStack. 

library(raster)
plot(Prec_GAM.raster)

You can even zoom in using :

zoom(Prec_GAM.raster)
and then make a selection on the plot. 

Do not forget that in case your data are stacked together, you need to unstack them before exporting them in ASCII files for instance.
However, I'd rather encourage you to look at the different tools in raster, rdgal and maptools packages, because as far as I am concerned, I am not using any GIS software anymore, excepted for computationally intense work. 

HIH,

Wilfried




Le 7 juil. 2010 à 20:06, César Capinha a écrit :

> Thanks Wilfried,
>  
> It all worked well but I have one more (hopefully last) doubt though.
>  
> Predictions are stored in a .raster format which I guess is the native format of the raster library. I need to import these predictions to GIS. Still I cant find the correct method used to load them as a raster layer so I can then export them in a GIS compatible format using the "writeRaster" command.
>  
> Ex. using "raster" command
>  
> pred = raster("I:/Var/Prec_GAM.raster")
>  
> Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  :
>   Cannot create a RasterLayer object from this file.
> 
> Thanks again
> 
> César
> 
> 
> 
> 
> 
> 
> --- On Mon, 5/7/10, Wilfried Thuiller <wilfried.thuiller at ujf-grenoble.fr> wrote:
> 
> From: Wilfried Thuiller <wilfried.thuiller at ujf-grenoble.fr>
> Subject: Re: [Biomod-commits] RasterStack
> To: "César Capinha" <nrevistada at yahoo.co.uk>
> Cc: biomod-commits at r-forge.wu-wien.ac.at
> Date: Monday, 5 July, 2010, 17:39
> 
> Hi again,
> 
> RasterStack is like a list of raster objects. A raster object is an object from package "raster" that can be loaded from grid ascii files, or ESRI grids, or IMG files. 
> For each environmental variable, there is one raster object. Thus to make a projection, you need to to group them together (as you can do when you have multiple vectors for the environmental layers and the group them in a dataframe) in order to make tell BIOMOD or whatever model where are the data. 
> 
> I gather everyone knows the Worldclim data (http://www.worldclim.org/). They can be downloaded easily from the web in different format. Let's say we have them in ESRI grids. 
> 
> library(raster)
> bio1 = raster("/Data/Wordclim/bio1")
> bio2 = raster("/Data/Wordclim/bio2")
> ....
> 
> bio19 = raster("/Data/Worldclim/bio19")
> 
> 
> Then you can create a stack from these 19 variables
> 
> worldclim=stack(bio_1, bio_2, bio_3, bio_4, bio_5, bio_6, bio_7, bio_8, bio_9, bio_10, bio_11, bio_12, bio_13,
> 
> 	bio_14, bio_15, bio_16, bio_17, bio_18, bio_19)
> 
> 
> Now you have a stack a raster that you can use to project the models (if calibrated on the same data of varuables!!)
> 
> 
> A more sexy way of doing that is: 
> 
> bio <- paste(rep('bio', times=19), seq(1:19), sep="_")
> 
> library(raster)
> 
> for(i in bio) 
> 	eval(parse(text=paste(i, "<- raster('/Data/Wordclim/", i,"')", sep="")))
> 	
> worldclim=stack(bio_1, bio_2, bio_3, bio_4, bio_5, bio_6, bio_7, bio_8, bio_9, bio_10, bio_11, bio_12, bio_13,
> 
> 	bio_14, bio_15, bio_16, bio_17, bio_18, bio_19)
> 
> 
> ********** Important********
> 1] The rasters must have the same extent (Xmin, Ymin, Xmas, Ymax) to be stacked. 
> Use the function "crop", "mask' or "resample" from package raster to make sure. 
> 
> 2] You can plot the rasters or stack very easily
> 
> > plot(worldclim)
>  and then add your points if you have the coordinates (make sure the projections is the same. Worldclim is in WGS84) 
> > points(X,Y)
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Le 5 juil. 2010 à 18:05, César Capinha a écrit :
> 
>> 
>> 
>> Hi all again,
>> 
>> Can someone provide a deeper insight on how to define and create the class 'RasterStack' needed to make the raster projections? 
>> 
>> Best of wishes,
>> 
>> César
> 
> _______________________________________________
> Biomod-commits mailing list
> Biomod-commits at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/biomod-commits

--------------------------
Dr. Wilfried Thuiller
Laboratoire d'Ecologie Alpine, UMR CNRS 5553
Université Joseph Fourier
BP53, 38041 Grenoble cedex 9, France
tel: +33 (0)4 76 51 44 97
fax: +33 (0)4 76 51 42 79

Email: wilfried.thuiller at ujf-grenoble.fr
Home page: http://www.will.chez-alice.fr
Website: http://www-leca.ujf-grenoble.fr/equipes/tde.htm

FP6 European MACIS project: http://www.macis-project.net
FP6 European EcoChange project: http://www.ecochange-project.eu





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/biomod-commits/attachments/20100707/7d6509fa/attachment-0001.htm>


More information about the Biomod-commits mailing list