Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

ACT 2

// Unsupervised Clustering using wekaKMeans


// on LANDSAT 8 image collection

// Region of interest
// change the coordinates below (xmin,ymin,xmax,ymax)
// a 45km (x) by 20km (y) ROI is manageable (~600kb when exported)
// var reion = ee.Geometry.Rectangle(121.5047, 16.8282,121.9194, 17.0922);

// Load full LANDSAT 8 collection


var landsat = ee.Algorithms.Landsat
.simpleComposite({
collection:ee.ImageCollection('LANDSAT/LC8_LL1T'),
asFloat:true
})
.select('B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7');

// Clip to ROI
var image = landsat.clip(region);

var training = image.sample({


region: region,
scale: 30,
numPixels: 5000
});

var clusterer = ee.Clusterer.wekaKMeans(7).train(training);


// (7) in wekaKMeans is the number of clusters
// and can be changed depending on the need

var vis = {min: 0, max: 10, palette: [


'023B01', 'CE7E45', 'FCD163', '66A000', '207401',
'056201', '004C00', '023B01', '012E01', '011301']};

var result = image.cluster(clusterer);


Map.centerObject(region,14);
Map.addLayer(result,vis);
//Map.addLayer(result.randomVisualizer(vis)); default if paletter is not provided

// Export an image (size: ~600kb)

Export.image.toDrive({
image: result,
region: region,
description: 'classified',
scale: 30
});

You might also like