[R-sig-Geo] Array to GeoTiff

Edzer Pebesma edzer.pebesma at uni-muenster.de
Tue Apr 13 08:28:23 CEST 2010

Hi Isabella,

you haven't told us how exactly your data are organized, what the first
two dimensions mean, and whether e.g. an increase in the second
dimension relates to x (long) or y (lat), and whether increase in the y
index means going north or south. This all matters. Below is a quick
example that only works, but may be not useful for your particular data

nr = nc = 100; nb = 3
x = array(runif(nr*nc*3) * 255, c(nc,nr,nb))
summary(data.frame(apply(x, 3, as.vector)))
df = data.frame(apply(x, 3, as.vector))
gt = GridTopology(c(0,0), c(1,1), c(nc,nr))
sgdf = SpatialGridDataFrame(gt, data.frame(apply(x, 3, as.vector)))
writeGDAL(sgdf, "out.tif", "GTiff")

GridTopology defines the topology of a geographic grid: the offset, cell
size and dimensions of the grid. To the function SpatialGridDataFrame
you can further more pass information about the coordinate reference
system, so that the GeoTiff could be related to some place on the earth,
and could be handled sensibly by a GIS.


Isabella Ghement wrote:
> Hi everyone,
> I need to create a multi-band GeoTiff file from a 3-dimensional R array
> whose 3rd dimension is
> used to represent bands.  Can anyone let me know how to best proceed?
> I played around with writeRGDAL but was unable to figure out how to
> manipulate the array
> in order to get writeRGDAL to recognize it.
> Any ideas would be greatly appreciated.
> Sincerely,
> Isabella
> Isabella R. Ghement, Ph.D.
> Ghement Statistical Consulting Company
> 301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5
> Tel: 604-767-1250
> Fax: 604-270-3922
> E-mail: isabella at ghement.ca
> Web: www.ghement.ca
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de

More information about the R-sig-Geo mailing list