Skip to content
Prev 14831 / 29559 Next

Export images from list of pixel images

Here's one way:

library(spatstat)

data(lansing)
rrisklan <- relrisk(lansing))

names(rrisklan)
[1] "blackoak" "hickory"  "maple"    "misc"     "redoak"   "whiteoak"

library(maptools)
## set up first grid, with first attribute "blackoak"
g <- as(rrisklan[[1]], "SpatialGridDataFrame")

names(g) <- "blackoak"

if (length(rrisklan) > 1) {  ## safety check
   for (i in 2:length(rrisklan)) {
     g[[names(rrisklan)[i]]] <- as(rrisklan[[i]], "SpatialGridDataFrame")[[1]]
  }
}

Compare:

plot(rrisklan)
spplot(g)

With the rgdal package you can now writeGDAL(g, "myfile.tif") but
whether your target can handle multi-attribute GeoTIFF is another
matter (the last few releases of ArcGIS use GDAL anyway so presumably
it would be fine).

Cheers, Mike.
On Sun, Apr 15, 2012 at 1:41 PM, Jose Funes <jefunes at gmail.com> wrote: