[gdal-dev] Writing a Tiff

Frank Warmerdam warmerdam at pobox.com
Thu Jan 15 16:57:01 EST 2009


Henning Bredel wrote:
> Hi there,
> 
> (not sure if my last mail came through)
> 
> I have read http://www.gdal.org/frmt_gtiff.html and I am
> wondering if I have to build GDAL on my own to get the
> possibility writing tiffs ..
> 
> I tried something like
> 
> ,-----------------------------------.
> 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?

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.

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).

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list