[R-sig-Geo] gdal error 1 (execution halted)

Roger Bivand Roger.Bivand at nhh.no
Sun Mar 16 12:36:54 CET 2008


On Fri, 14 Mar 2008, Lienert  Christophe wrote:

> Dear All, Parts of the he following email have been already posted on 
> the R-devel list, but is supplemented with the code that may cause the 
> error discussed below and put on the R-sig-geo list at the suggestion of 
> Mr. Bivand.
>
> I am using R 2.6.2 on my Redhat AS4. I installed the RPM offered on the 
> cran website. I would like to use R from my bash console with the 
> following command:
>
> /path/to/R --vanilla --slave --args < /data/myscript.R
>
> this script invokes a range of functions and tools, among others to 
> process a bunch of raster images in a loop using GDAL. The thing is that 
> releasing this command in the bash results in the following error:

The possibilities are almost endless. Without having any idea of the 
classes of the arguments to your function, it is hard to know why the 
object passed to writeGDAL() may be corrupt.

Only write a script when you have a good practical understanding of all 
the steps you are taking. Your script indicates that this is not the case. 
You have not even explained that what you seem to be trying to do is to 
take a SpatialGridDataFrame with one column, and to convert it into a 
four-column SpatialGridDataFrame with red, green, blue, and alpha columns, 
based on a classification of the input variable given in a numeric vector 
breaks.


>
> ERROR:
> *************************************
>
> Error in GDAL.close(tds.out) :
>        GDAL Error 1: TIFFReadDirectory:/tmp/RtmpBgrSyt/file2ef6a5b2: 
> cannot handle zero scanline size
> Calls: plot.georef -> GDAL.close -> .Call
> Execution halted
>
>
>
> CODE:
> *************************************
>
>
> plot.georef=function(grid.sp,graph.file,col.palette,breaks){

grid.sp is what? A SpatialGridDataFrame?
graph.file is what? A file name - single element character vector?
col.palette is what? A character vector?
breaks is what? A numeric vector?

>
>  require("sp")
>  require("rgdal")
>
>  # get desired picture type
>  base.name=strsplit(graph.file,"/")[[1]]
       [length(strsplit(graph.file,"/")[[1]])]

Do you know that base.name is what you think it is? Did you consider using 
the basename() function?

>  ft=0
>  ft=sum(c(ft,grep(".tiff",base.name)))

See ?grep - "." means something.

>  if (ft==1){ file.typ="TIFF" }
>  ft=0
>  ft=sum(c(ft,grep(".jpg",base.name)))
>  if (ft==1){ file.typ="JPG" }
>  ft=0
>  ft=sum(c(ft,grep(".png",base.name)))
>  if (ft==1){ file.typ="PNG" }
>
>  # create RGB bands
>  names(grid.sp)=c("band1","band2")

How many columns did grid.sp have when it came into the function, do you 
know that there were two? If not, this will not create them.

>  grid.sp$band3=grid.sp$band2
>  grid.sp$band4=grid.sp$band2

If band2 wasn't created above, this won't create band3 or band4.

>
>  col.class=as.vector(cut(grid.sp$band1,br = breaks, labels=col.palette))

Curious use of cut:

col.class <- col.palette[findInterval(grid.sp$band1, vec=breaks,
     all.inside=TRUE)]

seems more natural, and avoids creating a factor (which is what cut() is 
for).

>  col.class[is.na(col.class)]="#FFFFFF"

Do you know how many are NAs?

>  col.class.rgb=col2rgb(col.class)

Assuming that you have full control of col.class, this should work.

>
>  grid.sp$band1=col.class.rgb["red",]

Here you are overwriting the input object - do you need to? Wouldn't it be 
cleaner to start a fresh object?

>  grid.sp$band2=col.class.rgb["green",]
>  grid.sp$band3=col.class.rgb["blue",]
>  grid.sp$band4[]=256
>

Should the alpha band run 0-255 or 1-256? col2rgb() uses 0-255 (and can 
also add an alpha column).

>  if (file.typ=="TIFF"){
>
>    #writeGDAL(grid.sp, graph.file,drivername = "GTiff",
         type = "band",options="ALPHA=YES")

The two versions are equivalent. Most likely, the cause of your problems 
is type = "band", which is not a valid type, being passed to underlying 
GDAL functions as "Unknown". My guess would be that you mean "Byte".

The full list of GDAL data types is on www.gdal.org (down now for me, so 
no specific link), and from the R prompt as:

rgdal:::.GDALDataTypes

Finally, wouldn't it be easier to use the vec2RGB() function in rgdal, see 
the example using the meuse.grid data set at the foot of the example on 
the help page?

Hope this helps,

Roger


>    tds.out <- create2GDAL(dataset=grid.sp,drivername="GTiff",type="band")
>    saveDataset(tds.out,graph.file)
>    GDAL.close(tds.out)
>  }
> }
>
>
>
>
> The error is most likely in the if control. Both variants (the with only the commented line and the one with only the three following lines) produce the error.
> Thanks for any help!
>
> Ciao,
>
> Chris
>
> _______________________________________________
> Christophe Lienert
> ETH Zurich
> Institute of Cartography
> Wolfgang-Pauli-Str. 15
> HIL G 13.3
> CH-8093 Zurich
> SWITZERLAND
>
> Fon: +41-44-6333036
> Fax: +41-44-6331153
> www.karto.ethz.ch
> lienert at karto.baug.ethz.ch
>
> _______________________________________________
> 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