Skip to main content
deleted 1 character in body
Source Link
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)

I also display if driver support only raster or both raster and vector, I also display the other capabilities (read/write, support vsi,...). The logic is a port of the equivalent C++ code

from osgeo import gdal 

all_driver_names = [gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())] 

gdal_driver_names = [ driver_name[driver_name for driver_name in all_driver_names if gdal.GetDriverByName(driver_name).GetMetadataItem('DCAP_RASTER') == 'YES']

driver_type = {
    'DCAP_RASTER': 'raster',
    'DCAP_MULTIDIM_RASTER': 'multidimensional raster',
    'DCAP_VECTOR': 'vector',
    'DCAP_GNM': 'geography network'
}

for driver_name in gdal_driver_names:
    driver = gdal.GetDriverByName(driver_name)
    driver_shortname = driver.ShortName # Get short name
    driver_types = ','.join([driver_type[t] for t in driver_type.keys() if driver.GetMetadataItem(t) == 'YES']) # Get if driver support raster and vector or only raster

    pszRFlag = ""
    if driver.GetMetadataItem('DCAP_OPEN') == 'YES':
        pszRFlag = "r";
    
    pszWFlag = ""
    if driver.GetMetadataItem('DCAP_CREATE') == 'YES':
        pszWFlag = "w+";
    elif driver.GetMetadataItem('DCAP_CREATECOPY') == 'YES':
        pszWFlag = "w";
    else:
        pszWFlag = "o";

    pszVirtualIO = ""
    if driver.GetMetadataItem('DCAP_VIRTUALIO') == 'YES':
        pszVirtualIO = "v";
    else:
        pszVirtualIO = "";
    
    pszSubdatasets = ""
    if driver.GetMetadataItem('DMD_SUBDATASETS') == 'YES':
        pszSubdatasets = "s";

    driver_longname = driver.LongName # Get Long name
    print(f"{driver_shortname} -{driver_types}- ({pszRFlag}{pszWFlag}{pszVirtualIO}{pszSubdatasets}): {driver_longname}")

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)

I also display if driver support only raster or both raster and vector, I also display the other capabilities (read/write, support vsi,...). The logic is a port of the equivalent C++ code

from osgeo import gdal 

all_driver_names = [gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())] 

gdal_driver_names = [ driver_name for driver_name in all_driver_names if gdal.GetDriverByName(driver_name).GetMetadataItem('DCAP_RASTER') == 'YES']

driver_type = {
    'DCAP_RASTER': 'raster',
    'DCAP_MULTIDIM_RASTER': 'multidimensional raster',
    'DCAP_VECTOR': 'vector',
    'DCAP_GNM': 'geography network'
}

for driver_name in gdal_driver_names:
    driver = gdal.GetDriverByName(driver_name)
    driver_shortname = driver.ShortName # Get short name
    driver_types = ','.join([driver_type[t] for t in driver_type.keys() if driver.GetMetadataItem(t) == 'YES']) # Get if driver support raster and vector or only raster

    pszRFlag = ""
    if driver.GetMetadataItem('DCAP_OPEN') == 'YES':
        pszRFlag = "r";
    
    pszWFlag = ""
    if driver.GetMetadataItem('DCAP_CREATE') == 'YES':
        pszWFlag = "w+";
    elif driver.GetMetadataItem('DCAP_CREATECOPY') == 'YES':
        pszWFlag = "w";
    else:
        pszWFlag = "o";

    pszVirtualIO = ""
    if driver.GetMetadataItem('DCAP_VIRTUALIO') == 'YES':
        pszVirtualIO = "v";
    else:
        pszVirtualIO = "";
    
    pszSubdatasets = ""
    if driver.GetMetadataItem('DMD_SUBDATASETS') == 'YES':
        pszSubdatasets = "s";

    driver_longname = driver.LongName # Get Long name
    print(f"{driver_shortname} -{driver_types}- ({pszRFlag}{pszWFlag}{pszVirtualIO}{pszSubdatasets}): {driver_longname}")

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)

I also display if driver support only raster or both raster and vector, I also display the other capabilities (read/write, support vsi,...). The logic is a port of the equivalent C++ code

from osgeo import gdal 

all_driver_names = [gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())] 

gdal_driver_names = [driver_name for driver_name in all_driver_names if gdal.GetDriverByName(driver_name).GetMetadataItem('DCAP_RASTER') == 'YES']

driver_type = {
    'DCAP_RASTER': 'raster',
    'DCAP_MULTIDIM_RASTER': 'multidimensional raster',
    'DCAP_VECTOR': 'vector',
    'DCAP_GNM': 'geography network'
}

for driver_name in gdal_driver_names:
    driver = gdal.GetDriverByName(driver_name)
    driver_shortname = driver.ShortName # Get short name
    driver_types = ','.join([driver_type[t] for t in driver_type.keys() if driver.GetMetadataItem(t) == 'YES']) # Get if driver support raster and vector or only raster

    pszRFlag = ""
    if driver.GetMetadataItem('DCAP_OPEN') == 'YES':
        pszRFlag = "r";
    
    pszWFlag = ""
    if driver.GetMetadataItem('DCAP_CREATE') == 'YES':
        pszWFlag = "w+";
    elif driver.GetMetadataItem('DCAP_CREATECOPY') == 'YES':
        pszWFlag = "w";
    else:
        pszWFlag = "o";

    pszVirtualIO = ""
    if driver.GetMetadataItem('DCAP_VIRTUALIO') == 'YES':
        pszVirtualIO = "v";
    
    pszSubdatasets = ""
    if driver.GetMetadataItem('DMD_SUBDATASETS') == 'YES':
        pszSubdatasets = "s";

    driver_longname = driver.LongName # Get Long name
    print(f"{driver_shortname} -{driver_types}- ({pszRFlag}{pszWFlag}{pszVirtualIO}{pszSubdatasets}): {driver_longname}")
added 434 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95

I also display if driver support only raster or both raster and vector, I also display the other capabilities (read/write, support vsi,...). The logic is a port of the equivalent C++ code

from osgeo import gdal 

all_driver_names = [gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())]  

gdal_driver_names = [
  driver_name for driver_name 'in -all_driver_names 'if gdal.joinGetDriverByName([driver_name).GetMetadataItem('DCAP_RASTER') == 'YES']

driver_type = {
    'DCAP_RASTER': 'raster',
    'DCAP_MULTIDIM_RASTER': 'multidimensional raster',
    'DCAP_VECTOR': 'vector',
    'DCAP_GNM': 'geography network'
}

for driver_name in gdal_driver_names:
    driver = gdal.GetDriverByName(driver_name)
    driver_shortname = driver.ShortName, # Get short name
      driver_types = ','.join([i.replace('DCAP_', '').lower()[driver_type[t] for it in  ['DCAP_RASTER', 'DCAP_VECTOR'] if gdaldriver_type.GetDriverByNamekeys(driver_name) if driver.GetMetadataItem(it) == 'YES']), # Get if driver support raster and vector or only raster 

    pszRFlag = ""
   gdal if driver.GetDriverByNameGetMetadataItem(driver_name'DCAP_OPEN') == 'YES':
        pszRFlag = "r";
    
    pszWFlag = ""
    if driver.LongNameGetMetadataItem('DCAP_CREATE') #== Get'YES':
 Long name      pszWFlag = "w+";
    ]elif driver.GetMetadataItem('DCAP_CREATECOPY') for== driver_name'YES':
 in all_driver_names      pszWFlag = "w";
    else:
        pszWFlag = "o";

    pszVirtualIO = ""
    if gdaldriver.GetDriverByNameGetMetadataItem(driver_name'DCAP_VIRTUALIO') == 'YES':
        pszVirtualIO = "v";
    else:
        pszVirtualIO = "";
    
    pszSubdatasets = ""
    if driver.GetMetadataItem('DCAP_RASTER''DMD_SUBDATASETS') == 'YES']'YES':
        pszSubdatasets = "s";

    driver_longname = driver.LongName # Get Long name
    print('\n'.joinf"{driver_shortname} -{driver_types}- (gdal_driver_names{pszRFlag}{pszWFlag}{pszVirtualIO}{pszSubdatasets}): {driver_longname}")

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

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

I also display if driver support only raster or both raster and vector, I also display the other capabilities (read/write, support vsi,...). The logic is a port of the equivalent C++ code

from osgeo import gdal 

all_driver_names = [gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())]  

gdal_driver_names = [ driver_name for driver_name in all_driver_names if gdal.GetDriverByName(driver_name).GetMetadataItem('DCAP_RASTER') == 'YES']

driver_type = {
    'DCAP_RASTER': 'raster',
    'DCAP_MULTIDIM_RASTER': 'multidimensional raster',
    'DCAP_VECTOR': 'vector',
    'DCAP_GNM': 'geography network'
}

for driver_name in gdal_driver_names:
    driver = gdal.GetDriverByName(driver_name)
    driver_shortname = driver.ShortName # Get short name
    driver_types = ','.join([driver_type[t] for t in driver_type.keys() if driver.GetMetadataItem(t) == 'YES']) # Get if driver support raster and vector or only raster 

    pszRFlag = ""
    if driver.GetMetadataItem('DCAP_OPEN') == 'YES':
        pszRFlag = "r";
    
    pszWFlag = ""
    if driver.GetMetadataItem('DCAP_CREATE') == 'YES':
        pszWFlag = "w+";
    elif driver.GetMetadataItem('DCAP_CREATECOPY') == 'YES':
        pszWFlag = "w";
    else:
        pszWFlag = "o";

    pszVirtualIO = ""
    if driver.GetMetadataItem('DCAP_VIRTUALIO') == 'YES':
        pszVirtualIO = "v";
    else:
        pszVirtualIO = "";
    
    pszSubdatasets = ""
    if driver.GetMetadataItem('DMD_SUBDATASETS') == 'YES':
        pszSubdatasets = "s";

    driver_longname = driver.LongName # Get Long name
    print(f"{driver_shortname} -{driver_types}- ({pszRFlag}{pszWFlag}{pszVirtualIO}{pszSubdatasets}): {driver_longname}")
added 32 characters in body
Source Link
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

A one liner to get all drivers (GDAL + OGR)

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

from osgeo import gdal 

all_driver_names = [gdal.GetDriver(i).GetDescription() for i in range(gdal.GetDriverCount())] 
gdal_driver_names = [
    ' - '.join([
        driver_name, # 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

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

added 742 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95
Loading
added 35 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95
Loading
added 35 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95
Loading
added 234 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95
Loading
added 234 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95
Loading
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95
Loading