I have been working on a multiband raster image. It is a pix image. I need to just work on the 26 bands that are raster files and not the 4 bitmaps that are are also included in the pix image. I could force the loop that will be going through it to only go through 25 times but that wont work when the pix images change and the number of bands change. Right now I am using gdal and have it all in a 3D array. I am pretty sure the bitmaps would be the last five layers of the array. I do not have anything to tackle this problem so I have no code.
Basically I just need to delete 4 layers from the pix image and work with 26 layers. When I call raster_image.rastercount
, instead of it printing 30, I want it to print 26. I have gone through the gdal library, I may have missed something but I couldn't find anything. Is there a way to delete entire bands using gdal?
I have attached a screenshot of how the bands looks and what one of the bitmaps look like when displayed. Is there anyone that can help? Or just tell me it is impossible.
I am trying to use the GetGeomType
just to see how it works and if it will work for me. But it does not seem to work:
raster_image = gdal.Open(in_raster)
band3 = raster_image.GetGeomType(3)
print band3
Above is how I am calling it but it gives me the error:
AttributeError: 'Dataset' object has no attribute 'GetGeomType'
Then trying it by first getting the raster band and then checking the geom type I get:
band3 = raster_image.GetRasterBand(3).GetGeomType()
print band3
AttributeError: 'Band' object has no attribute 'GetGeomType'
Best Answer
You could create a
GDALDataset
with as many bands as you have raster bands, then copy the data from each of your bands into the corresponding band in theGDALDataset
. Here's some example code in C++ (since that's where I'm most familiar with GDAL).There might be a more efficient way to do this that I am not aware of, but I have used this method many times to add and delete bands from raster datasets.