Export Matrix to ESRI Grid or tif file
Hi,
here an alternative approach using RSAGA to write ASCII grids:
library(RSAGA)
x <- matrix(rep(seq(11,13,0.5), 5), byrow=T, nrow=5)
y <- matrix(rep(seq(3,5,0.5), 5), byrow=F, nrow=5)
z = 0.0052 + 0.001*x - 0.00023*y + 0.0011*x*y
hdr = list(
ncols = ncol(z), nrows = nrow(z),
xllcenter = min(x), yllcenter = min(y),
cellsize = 0.5, nodata_value = -9999)
write.ascii.grid(x, "x.asc", header = hdr, digits = 1, georef = "center")
write.ascii.grid(y, "y.asc", header = hdr, digits = 1, georef = "center")
write.ascii.grid(z, "z.asc", header = hdr, digits = 6, georef = "center")
--
Alexander Brenning
Department of Geography and Environmental Management
University of Waterloo
200 University Ave. W - Waterloo, ON - Canada N2L 3G1
http://www.environment.uwaterloo.ca/geography/faculty/brenning/
----- Urspr?ngliche Mail ----
Von: Roger Bivand <Roger.Bivand at nhh.no>
An: Jean-Paul Kibambe Lubamba <jean-paul.kibambe at uclouvain.be>
CC: r-sig-geo at stat.math.ethz.ch
Gesendet: Montag, den 1. September 2008, 13:50:41 Uhr
Betreff: Re: [R-sig-Geo] Export Matrix to ESRI Grid or tif file
On Mon, 1 Sep 2008, Jean-Paul Kibambe Lubamba wrote:
Hi, I am a new R User and I am trying to write an Ascii grid file or tiff file from a matrix created in R. This is what I am doing : 1. write a matrix of x-coordinates (in degrees): x<-matrix(rep(seq(11,13,0.5), by row=T, nrow=5) 2. write a matrix of y-coordinates (in degrees): y<-matrix(rep(seq(3,5,0.5), by row=T, nrow=5) 3. I have a function which combine my coordinates (x and y) in the following way: z = 0.0052 + 0.001x - 0.00023y + 0.0011xy z is my variable of interest and I want to put it in a GIS software, ArcGIS for example, for an analysis with other geographical dataset.
library(sp) grd <- GridTopology(cellcentre.offset=c(11,3), cellsize=c(0.5, 0.5), cells.dim=c(5, 5)) crds <- coordinates(grd) z <- 0.0052 + 0.001*crds[,1] - 0.0023*crds[,2] + 0.0011*crds[,1]*crds[,2] SGDF <- SpatialGridDataFrame(grd, data=data.frame(z=z)) spplot(SGDF) library(rgdal) writeGDAL(SGDF, "SGDF.tif") or other drivers for writeGDAL() if you prefer. Hope this helps, Roger
So, I want to have my matrix z as a esri grid file (or tif file or any kind of image format file), with a cell size equal to the interval (0.5) I gave in the 'seq' function I have previously used for x and y coordinates. How can I proceed ? Thanks a lot for your help. Jean-Paul Kibambe
Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no _______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo __________________________________________________ Do You Yahoo!? Sie sind Spam leid? http://mail.yahoo.com