Preparing WorldClim data using R raster package

1,359 views
Skip to first unread message

Érica Fonseca

unread,
Jun 2, 2014, 12:19:24 PM6/2/14
to max...@googlegroups.com

Dear all, I’m new in the group and a newbie in modeling too.  I need to convert the bioclimatic variables of Worldclim (.bil) to (.asc) in R software. It's a silly question, but I coudn't do it.  When I open the layer,  the ArcGis (10.1) warns me there's no spatial data on it. How can I convert without losing it and any other information? Thanks in advance.

Érica

Jason Brown

unread,
Jun 2, 2014, 1:17:01 PM6/2/14
to max...@googlegroups.com
Hi Érica-
  Since you have access to AcrGIS, know you can easily do this in that program using SDMtoolbox (see previous post regarding this, www.SDMtoolbox.org).  The toolbox can batch clip and convert raster files to your desired format (i.e. as ASCIIs). The warning regarding 'no spatial data' likely has to do with the projection not defined in the GIS files (note SDMtoolbox also has a tool to quick define all projections, here the data is WGS1984). Of course you can post more questions here or email me directly regarding SDMtoolbox (SDMtool...@gmail.com).
Cheers,
Jason

p.s. a R solution is also somewhat simple, but I allow others to clarify that.

Manuel Spínola

unread,
Jun 2, 2014, 1:25:06 PM6/2/14
to max...@googlegroups.com
You need to use the function wirteRaster from the Raster package.

Best,

Manuel Spínola


--
You received this message because you are subscribed to the Google Groups "Maxent" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maxent+un...@googlegroups.com.
To post to this group, send email to max...@googlegroups.com.
Visit this group at http://groups.google.com/group/maxent.
For more options, visit https://groups.google.com/d/optout.



--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS

Érica Fonseca

unread,
Jun 3, 2014, 10:33:17 AM6/3/14
to max...@googlegroups.com
Thanks Jason and Manuel!
 
Jason, my first attempt was using the Arc toolbox seemed easier, but always presented the same error and I decided to use R software. I don't know all toolbox functions, if necessary I will ask for help again. Thanks.
 
Manuel, I used the writeRaster function, but the saved file (.asc) presented the problem I said above.
Anyway, thanks for the help!
 
Érica

Jamie Kass

unread,
Jun 4, 2014, 2:02:51 PM6/4/14
to max...@googlegroups.com
First off, why not just download the bioclim variables in Arc GRID format? That would solve the problem right away.
If you want to use R, follow this protocol:

## before you do this, make sure the numbers below 10 for filenames have a prefix 0, e.g. bio_1 -> bio_01
## this is important, as the order in the stack will get messed up if there are no prefix 0's

library(raster) # if you don't have this package already, first do: install.packages('raster')
setwd('C:/Users/Johnny/Downloads/bio_10m_bil') # this is the directory that has the .bil files
envs <- stack(sapply(list.files(pattern='bil$'), raster)) # this makes a list of all the .bil files, then calls raster() on them, then stacks them together
envs # when you look at your new stack, you'll see all the rasters and some stats on them
envs[[1]] # this will give you just the first raster
writeRaster(envs, 'C:/Users/Johnny/bio.asc', bylayer=TRUE) # this writes all the rasters in the stack as 'bio_*' where * is the order number in the stack

This code will convert your .bil files to .asc. Alternatively, you can simply work with your rasterStack in an R session and use the functions from the 'dismo' package to do some modeling.

-Jamie

John Baumgartner

unread,
Jun 4, 2014, 6:22:34 PM6/4/14
to maxent
Or just use .bil - Maxent accepts them and the files are smaller.


--

Jamie Kass

unread,
Jun 5, 2014, 9:48:51 AM6/5/14
to max...@googlegroups.com
Interesting! Was this always the case? I thought Maxent only accepted ASCII files for the GUI. I know that if you're running it through dismo in R, any raster() object works.

John Baumgartner

unread,
Jun 5, 2014, 2:16:44 PM6/5/14
to maxent
As far as I know. The help file says: 

The layers must either be in ESRI ASCII grid format (described below), with filenames ending in ".asc", or Diva-GIS grid format, with filenames ending in ".grd" and ".gri".

But bil does work as well. 

No tif though :(



Reply all
Reply to author
Forward
0 new messages