[gdal-dev] updating a HFA image
Limei Ran
lran at unc.edu
Tue Apr 1 14:56:41 EDT 2008
Hi:
I opened an HFA image and got a band from it (only 1 band image). I
read a region from the band and update the band with the updated array.
But, for somehow, I can not view the updated HFA image in arcGIS due to
building pyramids failed. Could you give me some ideas about what may
go wrong? Here are codes related:
======================
//open the new copied data set for the following updating
poRDataset = (GDALDataset *) GDALOpen( newFileName.c_str(),
GA_Update );
if( poRDataset == NULL )
{
printf( "Open raster file failed: %s.\n", newFileName.c_str() );
exit( 1 );
}
poBand = poRDataset->GetRasterBand( 1 ); // band 1
GByte *poImage = (GByte *)
CPLCalloc(sizeof(GByte),c_nXSize*c_nYSize);
if ( (poBand->RasterIO(GF_Read, c_col1-1,c_row1-1,c_nXSize,c_nYSize,
poImage,c_nXSize,c_nYSize,GDT_Byte,0,0)) == CE_Failure)
{
printf( "Error: reading band 1 data error from image i:
%s.\n", newFileName.c_str() );
CPLFree (poImage);
exit( 1 );
}
for (int k=0; k<c_nXSize; k++)
{
if (poImage[k] == 127)
{
poImage[k] = 0;
}
}
//write back to the current image i
if ( (poBand->RasterIO(GF_Write,
c_col1-1,c_row1-1,c_nXSize,c_nYSize,
poImage,c_nXSize,c_nYSize,GDT_Byte,0,0)) == CE_Failure)
{
printf( "Error: Writing band 1 data error to image i:
%s.\n", newFileName.c_str() );
CPLFree (poImage);
exit( 1 );
}
poRDataset->FlushCache();
GDALClose( (GDALDatasetH) poRDataset );
CPLFree (poImage);
==========================================
Thanks,
Limei
More information about the gdal-dev
mailing list