map urban areas

Step 1: add your composite to the map

Map.addLayer(image,{min:0,max:3000,bands:"red,green,blue"})

Step 2: create training sample for urban

srilanka25

Step 3: add training samples

srilanka26

Step 4: create feature collection for non-urban

srilanka27

step 5: add points for non-urban

srilanka28.jpg

Step 6: merge the data points

// merge data
var trainingData = urban.merge(other);

Step 7:  set the prediction bands

// set the selection bands
var predictionBands = image.bandNames();

Step 8: create a training sample

// sample the regions
var classifierTraining = image.select(predictionBands).sampleRegions({collection: trainingData, properties: ['land_class'], scale: 30 });

Step 9: train the classifier

// train the classifier
var classifier = ee.Classifier.randomForest(10).train({features:classifierTraining, classProperty:'land_class', inputProperties: predictionBands});

Step 10: Classify the image

// get the classified image
var classified = image.select(predictionBands).classify(classifier);

Step 11: add the classified image to the map

Map.addLayer(classified,{min:0,max:1},"urban")

Step 12: Change the classifier to probablity

// train the classifier
var classifier = ee.Classifier.randomForest(100).setOutputMode('PROBABILITY').train({features:classifierTraining, classProperty:'land_class', inputProperties: predictionBands});
Advertisements