[Biomod-commits] RasterStack

César Capinha nrevistada at yahoo.co.uk
Wed Jul 7 20:06:16 CEST 2010



It all
worked well but I have one more (hopefully last) doubt though.


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 =


Error in
.rasterObjectFromFile(x, band = band, objecttype =
"RasterLayer",  :

  Cannot create a RasterLayer object from this
Thanks again

--- 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="_")

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,


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

More information about the Biomod-commits mailing list