0

I am working with Landsat-8 C1-Level 2 imagery and I need the information that NASA provides in the pixel_qa file. The information about the content of the pixel is given by turning on a certain bit, plus some eventual other bits to indicate the confidence of the class (e.g. clouds are indicated turning on the 5th bit, bits 6-7 give the confidence value for the cloud, pixels 8-9 the confidence for the cirrus). This means that there are several combinations of values that can indicate the same class. I know r.mapcalc has some bit-wise operators, but I haven't found what I'm looking for: is there a way to check if a specific bit (e.g. the 6th out of 16) is on or off?

Is there any more practical way to retrieve the information I need?

3
1

I have used r.mapcalc "flag_bit = (flag >> 6) & 1" to check if the 6th bit is set.

For debugging:

debug() { r.out.xyz -i input=$@  | cut -d"|" -f3 | xargs -n3; } 
g.region w=0 e=3 s=0 n=3 res=1 -pa
r.mapcalc "flag = row()*col()"; debug flag 
r.mapcalc "flag_bit = (flag >> 3) & 1"; debug flag; echo " "; debug flag_bit
# where "flag >> 3" checks the 3rd bit (starting at 0) or 2^3=8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.