[R-sig-Geo] Read .dat file as raster

Robert J. Hijmans r.hijmans at gmail.com
Mon Jul 22 22:04:16 CEST 2013


Thiago, it would be useful the mention the source (I am guessing CRU),
as others might then benefit from this discussion. Perhaps the below
does it (I have not checked this):

f <- 'ccld6190.dat'
d <- readLines(f)
d <- d[-c(1:2)]
d <- lapply(d, function(r) lapply(0:719, function(i) substr(r, i*5+1,(i+1)*5)))
d <- as.numeric(unlist(d))
d[d==-9999] <- NA
d <- matrix(d, ncol=12)

library(raster)
b <- brick(xmn=0, xmx=360, nl=12)
res(b) <- 0.5
values(b) <- d
b <- rotate(b)

Robert

On Mon, Jul 22, 2013 at 7:41 AM, Thiago V. dos Santos
<thi_veloso at yahoo.com.br> wrote:
> Dear all,
>
> Today I came across with a raster file formatted as ascii that looks like this: https://dl.dropboxusercontent.com/u/27700634/ccld6190.dat (17Mb)
>
> The question is: what is the best approach to read a file like this into R and convert it to a raster object?
>
>
> Thanks in advance,
> --
> Thiago V. dos Santos
> PhD student
> Land and Atmospheric Science
> University of Minnesota
> http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
> Phone: (612) 323 9898
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list