An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20100921/c4aa20fd/attachment.pl>
help to save a "SpatialPixelsDataFrame" in several image format via writeGDAL
2 messages · gianni lavaredo, Barry Rowlingson
On Tue, Sep 21, 2010 at 10:33 AM, gianni lavaredo
<gianni.lavaredo at gmail.com> wrote:
Dear Reseachers, I wish to save a "SpatialPixelsDataFrame" in several format (ascii, tiff, jpg, ect ect) using writeGDAL, but I don't understand my error (it's the first time I use this function) str(grid.aggr) Formal class 'SpatialPixelsDataFrame' [package "sp"] with 7 slots ?..@ data ? ? ? :'data.frame': 10816 obs. of ?2 variables: ?.. ..$ ID: Factor w/ 10816 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ... ?.. ..$ H : num [1:10816] 0.298 0.385 0.378 0.539 0.372 ...
writeGDAL(grid.aggr,tf, drivername="GTiff", type="Byte", options=NULL)
*Errore in create2GDAL(dataset = dataset, drivername = drivername, type = type, : Numeric bands required* thanks in advance and sorry for desturb
Error is "Numeric bands required" and at least one of your bands
("ID") is a Factor - you cant have factors (or character variables) in
GTiffs. Convert them or drop them:
> m = SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")],
data = meuse.grid)
> writeGDAL(m,"junk.tiff",drivername="GTiff", type="Byte", options=NULL)
Error in create2GDAL(dataset = dataset, drivername = drivername, type
= type, :
Numeric bands required
- so lets convert the ffreq variable to numeric:
> m$ffreq=as.numeric(m$ffreq)
> writeGDAL(m,"junk.tiff",drivername="GTiff", type="Byte", options=NULL)
- and that works.
Barry