i'm read tiff data using under code.
ds = 'path' , gdal.GA_ReadOnly)
and i find gdal API, i cna't find to read number of bands.
(ex) i have a 3 bands image, then read number of bands and return 3 in case)
is a any way to find number of bands?
Raster Band. A raster band is represented in GDAL with the GDALRasterBand class. It represents a single raster band/channel/layer. It does not necessarily represent a whole image. For instance, a 24bit RGB image would normally be represented as a dataset with three bands, one for red, one for green and one for blue.
The Geospatial Data Abstraction Library (GDAL) is a computer software library for reading and writing raster and vector geospatial data formats (e.g. shapefile), and is released under the permissive X/MIT style free software license by the Open Source Geospatial Foundation.
The gdalinfo program lists various information about a GDAL supported raster dataset. -json Display the output in json format. -mm Force computation of the actual min/max values for each band in the dataset. -stats Read and display image statistics. Force computation if no statistics are stored in an image.
Description. gdalinfo program lists various information about a GDAL supported raster dataset. Display the output in json format. Since GDAL 3.6, this includes key-value pairs useful for building a STAC item , including statistics and histograms if -stats or -hist flags are passed, respectively.
The RasterCount attribute gives the band count. Here's a simple example:
src_ds = gdal.Open("INPUT.tif")
if src_ds is not None:
print ("band count: " + str(src_ds.RasterCount))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With