QA60 band to mask clouds
step 1: import the image
// import image var image = ee.Image("COPERNICUS/S2/20170101T050212_20170101T050737_T44NLN");
step 2: select the qa band
// get QA band var QA = image.select("??");
step 3: Get the cloud and cirrus mask
// Bits 10 and 11 are clouds and cirrus, respectively. var clouds = QA.bitwiseAnd(Math.pow(2, 10)).eq(0); var cirrus = QA.bitwiseAnd(Math.pow(2, 11)).eq(0);
step 4: mask the clouds and cirrus
// mask clouds and cirrus var imageNoClouds = image.updateMask(clouds).updateMask(cirrus);
step 5: display the bands
// add image to layer Map.addLayer(image,{min:0,max:3000,bands:"B4,B3,B2"}); Map.addLayer(clouds,{min:0,max:??},"cloud mask"); Map.addLayer(cirrus,{min:0,max:??},"cirrus mask"); Map.addLayer(imageNoClouds,{min:0,max:3000,bands:"??"},"masked image");