Problem reading a '.bil' file
Aleksey Naumov
naumov at a...
Mon Oct 30 03:08:30 EST 2000
Hi all,
I am having a hard time trying to read a '.bil' file. The file came with a
corresponding
'.hdr' file, so I assume that it's an ESRI .hdr Labelled file (EHdr driver).
Here's the content of the .hdr file:
byteorder M
layout bil
nbands 1
nbits 32
ncols 304
nrows 364
ulxmap -115.717083
ulymap 43.449583
xdim 0.033333
ydim 0.033333
I tried to read it with a simple C++ code borrowed from API tutorial (the exect
code
used is included below). Here's the output I get upon running:
Driver: EHdr/ESRI .hdr Labelled
Block=304x1 Type=UInt32, ColorInterp=Undefined
Min=0.000000, Max=4294967295.000000
Computing min/max...
Min=0.000000, Max=0.000000
Here the last line is supposed to show the actual values, since I force
GDALComputeRasterMinMax() to recompute and take all numbers into account.
I can't understand why I get all zeroes (I get the same in OpenEv - obviously,
it's based on GDAL)! I used Python to read the .bil file pixel by pixel and I know
that there are real numbers there...
I then thought that it't the byte order that's screwing things up (indeed, the
numbers as read in Python were unrealistically huge). So I converted
the original 'cbw00003.bil' to another one, reversing the bytes with
pack() and unpack() from the struct module. Now the numbers are
within the range 0 - 3611 (and 2147483648, must indicate no data or
something...).
So I have this new '.bil' file and the corresponding '.hdr' file (I tried it both
with "byteorder M" line and without it) and I still get only zeroes!
What am I doing wrong? Any clue would be appreciated...
Thanks
Aleksey
P.S. I use the latest GDAL from CVS (as of 2-3 days ago...)
-------------------------------
#include <iostream.h>
#include <stdlib.h>
#include <gdal_priv.h>
int main(int argc, char *argv[])
{
char* pszFilename="/home/lesha/Geog/Data/cbw00003.hdr";
GDALDataset *poDataset;
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
if( poDataset == NULL )
{
cout << "It didn't work..." << endl;
}
printf( "\n\nDriver: %s/%s", poDataset->GetDriver()->pszShortName,
poDataset->GetDriver()->pszLongName );
// borrowed from API tutorial
GDALRasterBand *poBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
poBand = poDataset->GetRasterBand( 1 );
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
printf( "\nBlock=%dx%d Type=%s, ColorInterp=%s", nBlockXSize, nBlockYSize,
GDALGetDataTypeName(poBand->GetRasterDataType()),
GDALGetColorInterpretationName(poBand->GetColorInterpretation()) );
adfMinMax[0] = poBand->GetMinimum( &bGotMin );
adfMinMax[1] = poBand->GetMaximum( &bGotMax );
printf( "\nMin=%.6f, Max=%.6f", adfMinMax[0], adfMinMax[1] );
if( ! (bGotMin && bGotMax) )
{
cout << "\nComputing min/max... ";
GDALComputeRasterMinMax((GDALRasterBandH)poBand, FALSE, adfMinMax);
}
printf( "\nMin=%.6f, Max=%.6f", adfMinMax[0], adfMinMax[1] );
return EXIT_SUCCESS;
}
More information about the Gdal-dev
mailing list