[gdal-dev] Writing a Tiff

Henning Bredel henning.bredel at uni-muenster.de
Fri Jan 16 04:27:29 EST 2009


On Thu, 2009-01-15 at 16:57 -0500, Frank Warmerdam wrote:
> > ,-----------------------------------.
> > bm.writeTiff <- function(bm,filename) {
> >         
> >         # GTiff ist standard but show it here, though
> >         driver <- new('GDALDriver', 'GTiff')
> >         
> >         t <- new("GDALTransientDataset",driver,nrow(bm),ncol(bm),
> >                         type="Int32")
> > 
> >         for (row in 1:nrow(bm)-1) {
> >                 putRasterData(t,bm[row,1:(ncol(bm)-1)],offset=c(row,1))
> >         }
> >         
> >         saveDataset(t,filename)
> >         closeDataset(t)
> > }
> 
> Henning,
> 
> I am embarrassed to admit I don't even know what language the above is!
> Perl?  Ruby?

ups .. sorry, I was on the R-sig mailinglist before, so I forget to
point the language out explicitely. It's R -- I'm using GDAL with a
wrapper package called `rgdal' (Roger Bivand is involved in its 
development).

> 
> Normally there is a function to be called to register all the drivers
> with the drivermanager instance.  I think all the swig bindings call
> this automatically at load time.
> 
> Then you could normally call GetDriverByName() in the gdal "module" however
> that gets bound into your language.
> 

Well, rgdal offers also a `getGDALDriverByName() method. The output
says that there is GeoTiff creation support. 

> In Python the above would be something like:
> 
> driver = gdal.GetDriverByName('GTiff')
> dataset = driver.Create('file.tif', rows, columns, bands, gdal.Int32, None )
> ...
> 
> The main point I want to make is you don't actually create a driver object.
> You just get a reference to an existing one from the driver manager which
> is usually hidden by the global GetDriverByName() function
> (GDALGetDriverByName() in C).

I have read a satellite image into a matrix and now I would like
to write it into an image file again (maybe this sounds strange.
If you are interested in the background, I could tell ..).
The thing is, that I want to write into another file format than
the file I have read in, so how could I get the driver, if not
creating a new one?

My first try to write a GTiff with 

,--------------------------
bm.writeTiff <- function(bm,filename) {
        
        # GTiff ist standard but show it here, though
        driver <- new('GDALDriver', 'GTiff')
        
        t <- new("GDALTransientDataset",driver,nrow(bm),ncol(bm),
                        type="Int32")

        for (row in 1:nrow(bm)-1) {
                putRasterData(t,bm[row,1:(ncol(bm)-1)],offset=c(row,1))
        }
        
        saveDataset(t,filename)
        closeDataset(
`--------------------------

runs into the error (after approx. 30 sec.)

,--------------------------
 Wrong "StripByteCounts" field, ignoring and calculating from imagelength
`--------------------------

What does this error mean??

Another strange thing is, that there is no GTiff support after
that error anymore! The 2nd call of `getGDALDriverNames()' out-
put is missing the GTiff entry at all. Could this be a GDAL 
error or do I have to ask at the RGDAL mailinglist as well?

Thx for your help

  Henning

-- 
 . . . no signature
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090116/240c6ec3/attachment.bin


More information about the gdal-dev mailing list