Skip to content
Prev 17859 / 29559 Next

writeRaster - netcdf - Rotation

Hi Robert,
?
sure, m x n can be represented by n x m, but I was confused that after reimporting data as nc I have to transpose and rasterize it first before plotting. Because normally I don't have to do any of those two.
?
?
When I plot the examples from you,
?
image(tmp)
equals
image(writeRaster(tmp, filename='export.nc', format="CDF", overwrite=TRUE, xname='easting', yname='northing'))
and also equals
image(raster('export.nc'))
?
but
image(get.var.ncdf(nc,"layer")) doesn't and I have to transpose and rasterize it first:
image(t(raster(get.var.ncdf(nc,"layer"))))? # Now the plot is correct
?
The last plot is what got me confused. Maybe u can tell me why in this case the transposition and rasterize is needed?
?
Regards,
Philipp
?
?
?
Philipp,

A matrix of dimensions n x m can be represented as m x n, and my example
shows that the data are clearly equivalent (please build on this example if
you have further queries; it is not very helpful to refer to data we cannot
see):

library(raster)
tmp<- raster(nr=5, nc=10,crs='+proj=utm +zone=12')
tmp[] <- 1:ncell(tmp)
r <- writeRaster(tmp, filename='export.nc', format="CDF", overwrite=TRUE,
xname='easting', yname='northing')
all(values(tmp) == values(r))

nc <- open.ncdf("export.nc")
get.var.ncdf(nc,"easting")
get.var.ncdf(nc,"layer")

# result is the same as:
r <- raster('export.nc')
t(as.matrix(r))


Robert
On Mon, Mar 25, 2013 at 3:55 AM, Philipp Reiter <amock at gmx.li> wrote: