[R-sig-Geo] Export Matrix to ESRI Grid or tif file

Roger Bivand Roger.Bivand at nhh.no
Mon Sep 1 19:50:41 CEST 2008


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




More information about the R-sig-Geo mailing list