[gdal-dev] reading large image files
stephen tan
sts5678 at yahoo.com
Wed Jul 16 11:53:21 EDT 2008
I have a nitf image that I am trying to read into an array using gdal-1.5.1. The file is about 1.5G .
gdalinfo returns the following information:
Size is 27552, 25196
...
Band 1 Block=1024x1024 Type=UInt16, ColorInterp=Undefined
I have tried to read the image into an array using the following code:
GDALDataset *poDataset;
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpenShared( fname.c_str(),
GA_ReadOnly );
if( poDataset == NULL )
{
cerr << "Could not open file: " << fname << endl;
exit(1);
}
int width = poDataset->GetRasterXSize();
int height = poDataset->GetRasterYSize();
int bands = poDataset->GetRasterCount();
GDALRasterBand *poBand;
int nBlockXSize, nBlockYSize;
poBand = poDataset->GetRasterBand( 1 );
poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
//float* data;
//data = (float *) CPLMalloc(sizeof(float)*width*height*bands);
float* data;
data = new float[width*height*bands];
//GByte* data;
//data = (GByte *) CPLMalloc(sizeof(float)*width*height*bands);
//GByte data[width*height*bands];
if(poBand->RasterIO( GF_Read, 0, 0, width, height, data, width,
height, GDT_Byte, 0, 0 ))
{
cerr << "Error: Could not read image data." << endl;
exit(1);
}
GDALClose(poDataset);
No errors are returned. I let it run for several mins before I hit CTRL+C.
Any C++ suggestions on getting the image into a 1D array and/or 2D array
would be most helpful. The above code works for smaller images. I have also tried different GDALSetCacheMax with no success.
Thanks
More information about the gdal-dev
mailing list