Geoscience Reference
In-Depth Information
//register all drivers
GDALAllRegister();
//open BQA dataset in read only mode
GDALDataset *poBQAdataset;
poBQAdataset = (GDALDataset *)
GDALOpen(stlsBQAimageFilename.c_str(), GA_ReadOnly);
//create a new dataset for the cloud mask in CreateCopy mode
GDALDriver *poDriver;
poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset *poCLDdataset;
//define some extra create options
char **papszOptions = NULL;
papszOptions = CSLSetNameValue(papszOptions,"TILED","YES");
papszOptions = CSLSetNameValue(papszOptions,"COMPRESS",
"LZW");
GDALProgressFunc pfnProgress=GDALTermProgress;
float fprogress=0;
const char * pszMessage;
void * pProgressArg=NULL;
pfnProgress(fprogress,pszMessage,pProgressArg);
//create a copy of the source dataset
poCLDdataset =
poDriver->CreateCopy(stlsCLDimageFilename.c_str(),
poBQAdataset, FALSE, papszOptions, NULL, NULL);
//process datasets here...
//clean up
CSLDestroy(papszOptions);
//close the datasets
GDALClose((GDALDataset*)poBQAdataset);
GDALClose((GDALDataset*)poCLDdataset);
Before we can process a raster band from a dataset, we need to extract it first
by calling the dataset member function GetRasterBand . We select the first (and
only) raster band (index starts from1).We need to do this for both the input and output
raster bands. The GDAL API provides a number of useful progress functions. They
can be used to show the progress of the processing. You can implement your custom
progress function, but it is more convenient to just use one of the predefined ones
such as GDALTermProgress . The progress is reported in the variable associated
with the argument dfComplete . In our code, we use the variable progress for
this. It is initialized to 0 (start of the progress) and will gradually be increased each
time one line as processed until it reaches the value 1 (completion).
We process line per line by always reading one entire line into a buffer. We
use a vector from the standard template library of type unsigned short , which
matches the data type of the raster band ( GDT_UInt16 ). Reading and writing line
per line provides a good balance between performance (speed) and memory usage.
Depending on the amount of random access memory (RAM) in your computer, it
can be a valid option to read the entire image into memory.Large images might not
 
 
Search WWH ::




Custom Search