Geoscience Reference
In-Depth Information
entirely fit in your RAM. Reading and writing after processing each pixel should be
avoided at all times. The input and output (I/O) operations are very time consuming.
You should therefore try to avoid the number of times data are accessed, i.e. read
from/written to a file.
//buffer from type STL vector for reading and writing an
entire line of our dataset
vector< unsigned short >
stlvLineBuffer(
poBQAdataset->GetRasterXSize());
GDALRasterBand *poBQAband;//input band to read
poBQAband = poBQAdataset->GetRasterBand(1);//GDAL uses 1 based
index
GDALRasterBand *poCLDband;//output band to write
poCLDband = poCLDdataset->GetRasterBand(1);//GDAL uses 1 based
index
//process line per line
for ( int irow=0;irow<poBQAdataset->GetRasterYSize();++irow){
// read entire line in stlvLineBuffer buffer
poBQAband->RasterIO(GF_Read, 0, irow, stlvLineBuffer.size(), 1,
&(stlvLineBuffer[0]), stlvLineBuffer.size(), 1, GDT_UInt16, 0,
0);
//process per pixel
bool bCloud= false ;
bool bCirrus= false ;
short nconfidenceBits=0;
for ( int icol=0;icol<poBQAdataset->GetRasterXSize();++icol){
//interpret cloud mask here
}
//write buffer stlvLineBuffer to output file
poCLDband->RasterIO(GF_Write, 0, irow,
stlvLineBuffer.size(), 1, &(stlvLineBuffer[0]), stlvLineBuffer
.size(), 1, GDT_UInt16, 0, 0);
//advance progress bar
fprogress= static_cast < float >(irow+1) /
poBQAdataset->GetRasterYSize();
pfnProgress(fprogress,pszMessage,pProgressArg);
}
We start with interpreting the cloud confidence bits, i.e. 14 and 15. To get the
values of only two bits, we shift the band raster value 14 bits to the right ( »14 ),
followed by an AND operation with the binary value 11 ( &3 ). In the switch block
the pixel is assigned the status cloudy, if it has been detected with medium or high
confidence. 25 At this point, we can continue with the next pixel. If not cloudy, we
check for cirrus in a similar way.
25 You can adapt this to your needs.
 
Search WWH ::




Custom Search