[Gdal-dev] supported formats list

Frank Warmerdam warmerdam at pobox.com
Wed Jul 23 22:18:42 EDT 2003


McDonald, Brian J wrote:
> Hi there,
> 
> I'm a newbie here and we are thinking of using GDAL for some additional 
> format support.  I was wondering though if there is a method available 
> to get the list of supported formats at run time (and their extension(s))?

Brian,

Yes.  The following C code from gdalinfo shows how to visit all the drivers.

         else if( EQUAL(argv[i], "--formats") )
         {
             int iDr;

             printf( "Supported Formats:\n" );
             for( iDr = 0; iDr < GDALGetDriverCount(); iDr++ )
             {
                 GDALDriverH hDriver = GDALGetDriver(iDr);

                 printf( "  %s: %s\n",
                         GDALGetDriverShortName( hDriver ),
                         GDALGetDriverLongName( hDriver ) );
             }

             exit( 0 );
         }

The extension, for format drivers for which it is available, can be fetched
from the driver metadata with a call something like this (untested):

   const cha* pszExtension;

   pszExtension = GDALGetMetadataItem( hDriver, GDAL_DMD_EXTENSION, "" );

The returned extension would either be NULL (if there isn't an obvious
preferred extension), or the extension text itself, such as "tif" for the
GTiff driver.  It is primarily intended for applications that wish to
auto-add format appropriate extensions to filenames.  It isn't very good
for detecting formats.

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