Professional Documents
Culture Documents
Unsupervised Classification
Unsupervised Classification
// Create region
var region = ee.Geometry.Rectangle(31.56, -26.24, 31.78, -26.09);
Map.addLayer(region, {}, "Region");
Map.centerObject(region, 10);
/*******************************************
Proccess Landsat 8 data
/*******************************************/
// Function to mask clouds based on the pixel_qa band of Landsat 8 SR data.
function maskL8sr(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = (1 << 3);
var cloudsBitMask = (1 << 5);
// Get the pixel QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return image.updateMask(mask);
}
/*******************************************
Run supervised classification (clustering)
/*******************************************/
// Create training dataset.
var training = landsat2016.sample({
region: region,
scale: 30,
numPixels: 5000
});