[Gdal-dev] LAYER_TYPE=thematic
Schumann, Eike, VF-DE
eike.schumann at vodafone.com
Fri May 13 11:11:04 EDT 2005
Hello GDAL professionals,
I have a problem (which might be trivial?) changing the metadatum
LAYER_TYPE.
I am using gdal 1.6.
I am creating a 16bit unsigned raster dataset from scretch and want to
save it as an ERDAS IMG file, catagorized as thematic.
But whatever I do the LAYER_TYPE doesn't change from the default
athematic to thematic.
Below is an excerpt from the code I wrote to perform the task. I
appreciate any hint to solve the problem.
Many thanks in advance,
Eike.
static const string strProjection = "PROJCS[\"Transverse
Mercator\",GEOGCS[\"Potsdam_IST_V2_0\",DATUM[\"Potsdam_IST_V2_0
\",SPHEROID[\"Bessel\",6377397.155,299.1528131060786],TOWGS84[583,68,399
.5,0,0,1.36e-05,1.13e-05]],PRIMEM[\"Greenwich
\",0],UNIT[\"degree\",0.0174532925199433]],UNIT[\"meter\",1],PROJECTION[
\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin
\",0],PARAMETER[\"central_meridian\",9],PARAMETER[\"scale_factor\",1],PA
RAMETER[\"false_easting \",3500000],PARAMETER[\"false_northing\",0]]";
const char* pszFormat = "HFA";
char** pMetaData;
GDALDataType type = GDT_UInt16;
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName(
pszFormat );
if( poDriver == NULL )
{
throw FailedToStore("Couldn't find HFA driver!");;
}
char **papszOptions = NULL;
papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "TRUE");
//festlegen der Optionen
GDALDataset* poDst = poDriver->Create( fileName.str().c_str(),
image.metaData.cols, image.metaData.rows, 1, type, papszOptions);
if( NULL == poDst) throw FailedToStore("Couldn't create IMG
image!");
double adfGeoTransform[6];
adfGeoTransform[1] = image.metaData.resolutionX;
adfGeoTransform[5] = -image.metaData.resolutionY;
adfGeoTransform[0] = image.metaData.coords.LL.x;
adfGeoTransform[3] = image.metaData.coords.UR.y;
adfGeoTransform[2] = 0;
adfGeoTransform[3] = 0;
poDst->SetGeoTransform( adfGeoTransform );
CPLErr error = poDst->SetProjection( strProjection.c_str() );
unsigned char* pixels = ...
//***************** Interesting part begin
******************************************
//**********************************************************************
*************
GDALRasterBand* poBand = poDst->GetRasterBand(1);
pMetaData = poBand->GetMetadata();
CSLSetNameValue( pMetaData, "LAYER_TYPE", "thematic");
poBand->RasterIO( GF_Write, 0, 0, image.metaData.cols,
image.metaData.rows, pixels, image.metaData.cols, image.metaData.rows,
GDT_UInt16,0,0);
//***************** Interesting part end
******************************************
//**********************************************************************
*************
More information about the Gdal-dev
mailing list