Geoscience Reference
In-Depth Information
//loop over all command line options
for ( int i=1;i<argc;i++){
...
...
}
We then test on the string of the destination image filename ( stlsDestImage -
Filename ). If empty, the input image needs to be updated in the same way as in
the first version. If not empty, the user has provided a filename for the output image
that needs to be created. We will use the GeoTIFF driver for this. A more flexible
solution is provided in our third version.
...
if (stlsDestImageFilename.empty()){//no output provided: update input
//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
poDataset->GetRasterBand(1)->SetColorTable(&oColorTable);
}
else {//create new data set with CreateCopy
//open input dataset in read only mode
GDALDataset *poSrcDataset;
poSrcDataset = (GDALDataset *)
GDALOpenShared(stlsSrcImageFilename.c_str(),
GA_ReadOnly);
GDALDriver *poDriver;
poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
//possibility to define some extra create options here...
char **papszOptions = NULL;
//create new data for output
poDataset = poDriver->CreateCopy(stlsDestImageFilename.c_str(),
poSrcDataset, FALSE, papszOptions, NULL, NULL);
//set the color table to the first raster band
poDataset->GetRasterBand(1)->SetColorTable(&oColorTable);
//clean up
CSLDestroy(papszOptions);
//close the read only dataset
GDALClose((GDALDataset*) poSrcDataset);
}
//close the dataset
GDALClose((GDALDataset*) poDataset);
The CreateCopy method takes six arguments. The first argument is the file-
name of the dataset to be created ( stlsDestImageFilename ). It is converted
to a C-style string to be compatible with the declaration of the method. The sec-
ond argument defines the source dataset to be copied ( poSrcDataset ). The third
argument is set to FALSE , indicating that the copy must not be strictly equivalent
 
Search WWH ::




Custom Search