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:
Hi Robert and Pascal,
thanks for the tips, but my problem isn't completely solved. The explicit
laebling of x and y works, but doesn't change the rotation.
I followed Pascals hint:
My raster*-Object has the dimensons: "220 171 x".
When I export this raster*-Obejct as posted below as nc-file and reimport
it with the ncdf-Package, the dimensions are: "171 220 x". The explicit
labeling doesn't change that. The first dimension is always 171 in the
nc-file, no matter if its names 'easting' or 'northing'. To me it looks
like raster and ncdf interpret x and y differently?!
Beste regards
Philipp
Philipp,
You are right, the labels easting and northing are reversed. I will fix
that. You can set them yourself as illustrated below:
library(raster)
tmp<- raster(nr=5, nc=10,crs='+proj=utm +zone=12')
tmp[] <- 1:ncell(tmp)
writeRaster(tmp, filename='export.nc', format="CDF", overwrite=TRUE,
xname='easting', yname='northing')
raster('export.nc')
nc <- open.ncdf("export.nc")
get.var.ncdf(nc,"easting")
Robert
On Fri, Mar 22, 2013 at 7:17 AM, <amock at gmx.li> wrote:
Hey there, I?ve got a problem concerning exporting a raster*-Object as nc-File: When exporting rasterLayers or rasterBricks as nc-Files with writeRaster from the raster-Package, easting and northing in the resulting nc-File
are
switched, which results in a rotated plot. I can correct this afterwards,
but it should be possible to be correct right away?!
Example code for a rasterLayer:
tmp <- raster(readGDAL(?example.asc?,p4s="+init=epsg:31467"))
writeRaster(tmp, filename=?export.nc?, format="CDF", overwrite=TRUE)
nc <- open.ncdf("export.nc")
x <- get.var.ncdf(nc,?easting?)
y <- get.var.ncdf(nc,?northing?)
R version 2.15.3 (2013-03-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
ncdf_1.6.6 raster_2.1-16 rgdal_0.8-5 sp_1.0-6
I hope someone can give me a hint! Thanks in advance!
Philipp
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo[https://3c.gmx.net/mail/client/dereferrer?redirectUrl=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&selection=tfol11b9dc8701907a64][https://3c.gmx.net/mail/client/dereferrer?redirectUrl=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&selection=tfol11b9dc8701907a64[https://3c.gmx.net/mail/client/dereferrer?redirectUrl=https%3A%2F%2F3c.gmx.net%2Fmail%2Fclient%2Fdereferrer%3FredirectUrl%3Dhttps%253A%252F%252Fstat.ethz.ch%252Fmailman%252Flistinfo%252Fr-sig-geo%26selection%3Dtfol11b9dc8701907a64&selection=tfol11b9dc8701907a64]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo[https://3c.gmx.net/mail/client/dereferrer?redirectUrl=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&selection=tfol11b9dc8701907a64][https://3c.gmx.net/mail/client/dereferrer?redirectUrl=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&selection=tfol11b9dc8701907a64[https://3c.gmx.net/mail/client/dereferrer?redirectUrl=https%3A%2F%2F3c.gmx.net%2Fmail%2Fclient%2Fdereferrer%3FredirectUrl%3Dhttps%253A%252F%252Fstat.ethz.ch%252Fmailman%252Flistinfo%252Fr-sig-geo%26selection%3Dtfol11b9dc8701907a64&selection=tfol11b9dc8701907a64]]