Geoscience Reference
In-Depth Information
components correspond to the RGB triplet ( c1, c2, c3 ) and the alpha component
( c4 ).
GDALColorTable oColorTable;
//read color table from ASCII file
if (stlsCtFilename!="none"){
GDALColorEntry oEntry;
ifstream ftable(stlsCtFilename.c_str(),ios::in);
string line;
short nline=0;
while (getline(ftable,line)){
++nline;
istringstream ist(line);
GDALColorEntry oEntry;
short nid;
ist >> nid >> oEntry.c1 >> oEntry.c2 >> oEntry.c3 >>
oEntry.c4;
oColorTable.SetColorEntry(nid,&oEntry);
}
}
GDALDataset *poDataset;
GDALAllRegister();
//open input dataset in update mode (not supported by all drivers)
The input image is opened in update mode. In case the driver does not support this
mode, an error message is sent to the console by the GDAL API. In a more elaborated
version of the utility, it is possible to handle this error yourself. If successful, the
color table is added to the first raster band of the opened dataset. Finally, the dataset
is closed.
//open input dataset in update mode (not supported by all drivers)
poDataset = (GDALDataset *)
GDALOpen
(stlsSrcImageFilename.c_str(), GA_Update);
//set the color table to the first raster band
//setting an empty color table removes an existing color table
poDataset->GetRasterBand(1)->SetColorTable(&oColorTable);
//close the dataset
GDALClose((GDALDataset*) poDataset);
To create the utility, addct , the code must be be compiled and linked with the
GDAL library. Make sure that you set the include path according to your installation
and that the library can be found on your system.
g++ -o addct addct.cc -I/usr/include/gdal -L/usr/lib -lgdal
We can check the usage by invoking the help information with the option -h .
 
Search WWH ::




Custom Search