[R-sig-Geo] Antw: Writing Raster values to .txt file
Matteo Mattiuzzi
matteo.mattiuzzi at boku.ac.at
Thu Oct 4 01:05:33 CEST 2012
Hi,
the only way I can see is to use ?xyFromCell
r <- raster()
r[] <- 1:ncell(r)
r <- brick(r,r*2)
vals <- getValues(r)
coords <- xyFromCell(r,1:ncell(r))
res <- cbind(coords,vals)
write.table(res,"file1.txt")
Matteo
>>> Tiffany Smith 03.10.12 22.34 Uhr >>>
Hello,
I'm trying to write out the values of a RasterBrick to a .txt file. Here's what I have:
b<-brick("file1.nc")
vals<-getValues(b)
write.table(vals,"file1.txt")
Where 'b' is a RasterBrick with dimensions [224,464,33] which corresponds to [lat,lon,time]. The output, 'vals' has dimensions [103936,33] which correspond to [cell#,time].
'b' has actual lat & lon associated with it's extent; I would like to write the .txt file so that it included 'vals' and the associated lat & lon. Right now, the output file has columns filled with cell# (lat*lon) and time, I would like for there to also be columns for lat and lon.
Any ideas?
Thanks,
Tiffany
[[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