About raster bands đź”—

Posted by MĂ©dĂ©ric Ribreux 🗓 In blog/Qgis/

I have taken some time to deal with raster bands. I just wanted to understand the concept. Here is what I have found…

A band can be understood as a sort of layer inside the raster data. A raster is a matrix representation of some data with each cell a discrete value. The matrix has got X and Y size, and, of course, the matrix is georeferenced in the space: the position of the 0,0 and sizeX, sizeY cells are translated into the chosen coordinate reference system. So now, 0,0 cell points to an lat,long place. From then, you can deduce the resolution of the image in meters.

A raster with multiple bands is a raster with multiple matrices. Each matrix covers the same cells than the others. The area is the same for each band, but the values are not (well, they are independent).

What are the different use cases of bands? Well, plenty of different uses actually:

How are the bands stored into the raster file? Well it depends on the format. For example, for tiffs files, the cells are storing all data for each band next to the other band. It means that when you want to display only one band, you have to seek N bytes just to get the data you want. For other formats, the data of each band is stored in a different part of the file.

By the way, I have built some tools to deal with raster bands. They are coded in Python3 with the gdal library and you can use numpy to deal with the matrices and you can read the code in this public repository.