Skip to main content
7 of 9
added 32 characters in body
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95

A one liner to get all drivers (GDAL + OGR) (more or less 210 drivers)

python -c "from osgeo import gdal;print('\n'.join(sorted([gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())])))"

You can also filter drivers to get only GDAL one using the following (or you will not get the same number of drivers output as gdal_translate --formats e.g 136 on my machine)

from osgeo import gdal 

all_driver_names = [gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())] 
gdal_driver_names = [
    ' - '.join([
        gdal.GetDriverByName(driver_name).ShortName, # Get short name
        ','.join([i.replace('DCAP_', '').lower() for i in  ['DCAP_RASTER', 'DCAP_VECTOR'] if gdal.GetDriverByName(driver_name).GetMetadataItem(i) == 'YES']), # Get if driver support raster and vector or only raster
        gdal.GetDriverByName(driver_name).LongName # Get Long name
    ]) for driver_name in all_driver_names
    if gdal.GetDriverByName(driver_name).GetMetadataItem('DCAP_RASTER') == 'YES']

print('\n'.join(gdal_driver_names))

My example returns something like GTiff - raster - GeoTIFF whereas the exact output in gdal_translate --formats is GTiff -raster- (rw+vs): GeoTIFF. What is missing in my code is how to get the read/write/vsi/... capabilities.

To understand how to get read write capabilities, you can look at C++ code to understand the complete rules https://github.com/OSGeo/gdal/blob/d0a12d1a74e08557605f57cf2d94dac82b9fdda9/gdal/gcore/gdal_misc.cpp#L3088.

For example, to get the info about r (read) https://github.com/OSGeo/gdal/blob/d0a12d1a74e08557605f57cf2d94dac82b9fdda9/gdal/gcore/gdal_misc.cpp#L3106, you need in Python, to check if gdal.GetDriverByName(driver_name).GetMetadataItem('DCAP_OPEN') == 'YES' and if OK, add 'r' letter

ThomasG77
  • 31.2k
  • 1
  • 55
  • 95