5

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'

bands and bitmaps

  • Could you show the bands section from gdalinfo report of your image? Do you perhaps mean with the 5 bitmaps that there are 5 bands with 1-bit bit depth included in the image? – user30184 Sep 30 '14 at 12:55
  • so the pix image has 25 raster bands. When I use rasterCount it gives me 30 bands. So im making the assumption that it is including the 5 extra bitmaps that are on the pix image. So it is reading it as 30 layers (25 bands + 5 bitmaps). Also how do i use gdalinfo i tried raster_image.gdalinfo but that did not work – abhinav sharma Sep 30 '14 at 13:00
  • Use gdalinfo utility gdal.org/gdalinfo.html: gdalinfo image.tif – user30184 Sep 30 '14 at 13:07
  • I keep on getting dns server not authoritative for zone when i use cmd. I read somewhere that gdal info cant be called from the idle but only from cmd – abhinav sharma Sep 30 '14 at 13:14
1

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 the GDALDataset. Here's some example code in C++ (since that's where I'm most familiar with GDAL).

//create the dataset
const char *filename = "example.tif";
GDALDriver *pDriverTiff = GetGDALDriverManager->getDriverByName("GTiff");
GDALDataset *pRasterDS = pDriverTiff->create(filename, 300, 300, 25, GDT_Float32, NULL);//for create(filename, x size, ysize, number of bands, data type, options)

//fill each raster band
int bands = 25; //this would be the number of bands you want to copy i.e. total bands-bitmaps
int rows = 300; //rows in the raster or 3d array
int cols = 300; //cols in the raster or 3d array

for (int i=0; i<band; i++)
{
    for (int j=0; j<rows; j++)
    {
         for (int k=0; k<cols; k++)
         {
              //here is where you put the code to copy from your 3d array
              // copy array position [i,j,k] to band i, row j, col k, in the GDALDataset
         }

    }   
}

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.