GeoEco.Datasets.GDAL.GDALDataset.GetRasterBand

classmethod GDALDataset.GetRasterBand(path, band=1, updatable=False, decompressedFileToReturn=None, displayName=None, cacheDirectory=None)

Opens a GDAL dataset and returns a GDALRasterBand for the specified band.

This is a convenience function that is equivalent to:

from GeoEco.Datasets.GDAL import GDALDataset

with GDALDataset(path, updatable=updatable, decompressedFileToReturn=decompressedFileToReturn, displayName=displayName, cacheDirectory=cacheDirectory) as dataset:
    grids = dataset.QueryDatasets('Band = %i' % band, reportProgress=False)
    if len(grids) <= 0:
        raise ValueError(_('Cannot retrieve band %(band)i from %(dn)s. The band does not exist.') % {'band': band, 'dn': dataset.DisplayName})
    gdalRasterBand = grids[0]

# Now do something with the gdalRasterBand object...
Parameters:
  • path (str) – Full path to the dataset to open. If the path points to compressed file, it will be decompressed automatically. If a cache directory is provided, it will be checked first for an existing decompressed file. If none is found the file will be decompressed there. If the compressed file is an archive (e.g. .zip or .tar), you must also specify a decompressed file to return. Minimum length꞉ 1.

  • band (int, optional) – The band to get. Minimum value꞉ 1.

  • updatable (bool, optional) –

    Indicates whether the dataset should be opened in update mode, allowing the data within its bands to be changed.

    GDAL does not allow all formats to be opened in update mode. For more about this, please see https://www.gdal.org/formats_list.html.

  • decompressedFileToReturn (str, optional) –

    glob() expression that identifies the extracted file to open when the path points to an archive (e.g. a .zip or .tar file).

    This expression must select exactly one of the extracted files. Be sure to leave it as None when the path does not point to an archive.

    Minimum length꞉ 1.

  • displayName (str, optional) – Name for this dataset to be displayed to the user. If a display name is not provided, a generic one will be generated automatically. Minimum length꞉ 1.

  • cacheDirectory (str, optional) –

    Directory to cache a copy of the downloaded or decompressed file.

    If provided, this directory will be checked for the file prior to download or decompression. If the file is found, the download and decompression will be skipped. Thus, when performing repetitive processing with remote or compressed datasets, you can speed up processing considerably by providing a cache directory.

    Minimum length꞉ 1.

Returns:

GDALRasterBand instance.

Return type:

GDALRasterBand