Modular landcover system step-8: Machine learning

Classify your image using Random Forest

1. Upload the re-arranged training data as a fusion table or use the fusion table below.

trainingData_nghean.csv

// import fusion table
var ft = ee.FeatureCollection("ft:1VgrIQUIZQUzrWxTat8LQisj27wkZdQtaOB1l-akP")

 

2. Use the script below to classify the image.

// import the module
var covariates = require("users/username/landcoverS2:covariate_module");

// set variables
var vietnam = ee.FeatureCollection("users/servirmekong/countries/VNM_adm1");
var NgheAn = vietnam.filter(ee.Filter.eq("ID_1",41));
var region = NgheAn.geometry();

// import the composite
var img = ee.Image("projects/servir-mekong/NgheAnComposite2017");

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

var bandNames = ee.List(["EVI","IBI","ND_blue_green","ND_blue_nir","ND_blue_red","ND_blue_swir1","ND_blue_swir2","ND_green_nir","ND_green_red","ND_green_swir1","ND_green_swir2","ND_nir_red","ND_nir_swir1","ND_nir_swir2","ND_red_swir1","ND_red_swir2","ND_swir1_swir2","SAVI","aspect","blue","brightness","change_abs","change_norm","eastness","elevation","fifth","fourth","green","greenness","max_extent","nir","northness","occurrence","re1","re2","re3","re4","red","seasonality","sixth","slope","swir1","swir2","tcAngleBG","tcAngleBW","tcAngleGW","tcDistanceBG","tcDistanceBW","tcDistanceGW","transition","wetness"])

var classifier = ee.Classifier.randomForest(10,0).train(trainingData,"land_class",bandNames);

var classification = img.classify(classifier,'Mode').clip(region);

/*
0 forest
1 urban
2 rice
3 water
4 crop */
Map.addLayer(classification,{min:0,max:4,palette:"green,red,yellow,blue,orange"},"classified image")

click

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s