image collections 2

Use functions to create cloud free composites

step 1: create a geometry

srilanka8

Step 2: copy the code below

// import imagecollection
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR");

// filter for location
l8 = l8.filterBounds(??);

// print number of images
print(l8.size());

// filter for date;
l8 = l8.filterDate("??","??");

// print number of images
print(l8.size());

// sort based on cloud cover
l8 = l8.sort("??");

// print the image collection
print(l8);

// add first image to map
Map.addLayer(ee.Image(l8.first()),{min:0,max:3000,bands:"B4,B3,B2"});
function removeClouds(image){

// get QA band
var QA = image.select("pixel_qa");
var shadow = QA.bitwiseAnd(8).neq(0);
var cloud = QA.bitwiseAnd(32).neq(0);
return image.updateMask(shadow.not()).updateMask(cloud.not());
}

l8 = l8.map(removeClouds)
Map.addLayer(l8.median(),{min:0,max:3000,bands:"B4,B3,B2"})

Leave a Reply