Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the number of bands in gdal in python?

Tags:

python

gdal

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?

like image 298
송준석 Avatar asked May 10 '18 05:05

송준석


People also ask

What is a raster band GDAL?

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.

What is GDAL dataset?

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.

What is Gdalinfo?

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.

What does GDAL open do?

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.


1 Answers

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))
like image 184
Eran Avatar answered Oct 21 '22 18:10

Eran