[R-sig-Geo] help to save a "SpatialPixelsDataFrame" in several image format via writeGDAL
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Tue Sep 21 12:05:16 CEST 2010
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
--
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman
More information about the R-sig-Geo
mailing list