[R-sig-Geo] creating a raster using import.asc() nd raster()

Robert Hijmans r.hijmans at gmail.com
Fri Jul 8 15:57:56 CEST 2011


> I am converting an .asc object into a raster object in order to use
functions from the raster package. I 
> then use the converted file to populate an array called FishModel for the
> purpose of modeling. In the 
> process the columns and rows seem to be confused 

Juliane, 

It is easier to answer questions if you send real code that can be
replicated. 

library(adehabitat)
library(raster)
file <-  paste(system.file(package = "adehabitat"),
"ascfiles/elevation.asc", sep = "/")

b <- import.asc(file) 
r <- raster(b) 
par(mfrow=c(1,2))
image(b)
image(r)
dim(b) 
dim(r) 

The plot shows essentially the same thing, but dims are reversed. This is
because the 'asc' object stores the transposed matrix and dim for these
objects returns (ncol, nrow). You can get a "normal" matrix of the values of
an 'asc' object like this:

d <- t(b[])
d <- d[nrow(d):1, ]

Hth, Robert

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/creating-a-raster-using-import-asc-nd-raster-tp6561802p6562582.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list