Opened 21 years ago
Last modified 21 years ago
#401 closed defect (fixed)
Problem reading BIL files
Reported by: | Owned by: | warmerdam | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | GDAL_Raster | Version: | unspecified |
Severity: | normal | Keywords: | |
Cc: |
Description
If I read a spectral component from a BIL file using GDALRasterBand::RasterIO I get the data values for the first spectral component regardless of which component I ask for. I am using GDAL version 1.1.9 on Windows 2000. The file that is causing problems is a 602x630 pixel RGB BIL file. Here is the header file BYTEORDER I LAYOUT BIL NROWS 630 NCOLS 602 NBANDS 3 NBITS 8 BANDROWBYTES 602 TOTALROWBYTES 1806 BANDGAPBYTES 0 Below is a short example program that illustrates the problem. This program extracts a single band from the input file and writes it to a file called "x.raw". The index of the spectral band is specified at line 35 and must be set to 1, 2, or 3. I tried running this test program with a TIFF version of the ubiquitous Lena image and that works fine. #include <string> #include "vrtdataset.h" #include "cpl_vsi.h" #include "cpl_conv.h" #include "cpl_string.h" #include "gdal_priv.h" #include <iostream> #include <fstream> int main( void ) { GDALAllRegister(); const std::string filename( "sub2807.bil" ); // const std::string filename( "lena.tif" ); // the Lena image works OK!!! GDALDatasetH hDataset = GDALOpen( filename.c_str(), GA_ReadOnly ); const int width = GDALGetRasterXSize( hDataset ); const int height = GDALGetRasterYSize( hDataset ); const int samples_per_pixel = GDALGetRasterCount( hDataset ); unsigned char *buffer = new unsigned char[ width * height ]; const GDALDataType data_type = GDT_Byte; const GDALRWFlag eRWFlag = GF_Read; const int nXOff = 0; const int nYOff = 0; const int nXSize = width; const int nYSize = height; const int nBufXSize = width; const int nBufYSize = height; const int nPixelSpace = 0; // use default, i.e., sizeof(GDT_Byte) const int nLineSpace = width; const int comp_idx = 1; // SET THE COMPONENT INDEX HERE TO 1, 2 OR 3 GDALRasterBand *band = ((GDALDataset*)hDataset)->GetRasterBand (comp_idx); // extract the specified component CPLErr error = band->RasterIO ( eRWFlag, nXOff, nYOff, nXSize, nYSize, buffer, nBufXSize, nBufYSize, data_type, nPixelSpace, nLineSpace ); if( error == CE_Failure ) { std::cerr << "Error reading data.\n"; return 1; } // write the component to the file "x.raw" std::ofstream ofs( "x.raw", std::ios::binary ); ofs.write( (char*)buffer, width * height ); if( ofs.fail() ) { std::cerr << "Error writing data.\n"; return 1; } return 0; }
Note:
See TracTickets
for help on using tickets.