land cover classification

in Cambodia using machine learning

step 1: add the Landsat composite to the map and clip for the area of interest

var image = ee.Image("projects/servir-mekong/regionalComposites/2020").divide(10000);
var cambodia = ee.FeatureCollection("users/servirmekong/countries/KHM_adm1");
var KampongThum = cambodia.filter(ee.Filter.eq("NAME_1","Kâmpóng Thum")).geometry();

image = image.clip(KampongThum);


step 2: Create a new feature collection for water and add markers on water pixels

Step 2: do the same for forest

Step 3: do the same for rubber, urban, wetlands and agriculture

Step 4: combine the data into a single feature collection

var TrainingData = water.merge(forest).merge(rubber).merge(urban).merge(wetlands).merge(agriculture);

Step 5: sample the composite

var trainingSample = image.sampleRegions(TrainingData,["land_class"],30);


Step 6: train the random forest model

var bandNames = image.bandNames();
var classifier = ee.Classifier.smileRandomForest(30).train(trainingSample,"land_class",bandNames);

Step 7: classify the image

var classification = image.classify(classifier,'Mode');


Step 8: print the variable importance using the code below

var dict = classifier.explain();
var variable_importance = ee.Feature(null, ee.Dictionary(dict).get('importance'));
var chart =
title: 'Random Forest Variable Importance',
legend: {position: 'none'},
hAxis: {title: 'Bands'},
vAxis: {title: 'Importance'}

Step 9: add the code below after the image import and study the variable importance again.

var covariates = require("users/servirmekong/mrc:covariate_module");

image = covariates.addJRCAndTopo(image);
image = covariates.addCovariates(image);

Leave a Reply