[R-sig-Geo] converting dataframe to rasterformate

Roger Bivand Roger.Bivand at nhh.no
Thu Mar 8 15:19:50 CET 2007


On Thu, 8 Mar 2007, Paul Magdon wrote:

> Hello,
> I'm using R for classifying remote sensed data. I finally managed to apply
> different knn-methods to the data. Now I have a Dataframe with X, Y, and Z
> columns.
> Exp.:
>   X             Y       Z
> 475477.1  7485303.29  46.62
> 
> 
> Is there an easy way to export such dataframe into am Esri compatible
> format like Arcgrid, img, tiff etc.??
> 

Yes, for example:

library(sp)
data(meuse.grid)
class(meuse.grid)
names(meuse.grid)
coordinates(meuse.grid) <- c("x", "y")
class(meuse.grid)
gridded(meuse.grid) <- TRUE 
class(meuse.grid)
fullgrid(meuse.grid) <- TRUE
class(meuse.grid)
library(rgdal)
writeGDAL(meuse.grid["dist"], "dist.tif", drivername="GTiff")

This of course will not work if the points are not regularly spaced; 
there are plenty of different drivers for GDAL. For OSX either install 
rgdal on GDAL/PROJ.4 from source (see Rgeo site linked from Spatial Task 
View on CRAN for details) or write an Arc ASCII grid using 
writeAsciiGrid() in the maptools package, which does not depend on 
external libraries.

Roger

> 
> Many thanks,
> 
> Paul
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
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