TransWikia.com

Inspect raster value of a pixel to see bits that are on/off in GRASS GIS

Geographic Information Systems Asked on April 25, 2021

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?

One Answer

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

Answered by mankoff on April 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP