0

So I ran a Classification with Google Earth Engine, classifying forest and non-forest. After I prepared my ROI and declared some training points for each forest and non-forest (saved in the variable newfc) I ran the randomForest classification. The result is okay but my question now is if can access the variable classified to e.g. mask only the area that was classified as forest. I tried several things but can't find a solution for my problem.

Code:

var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  .filterDate('2015-02-01', '2015-12-01')
  .filterBounds(roi)
  .filter(ee.Filter.lte('CLOUD_COVER', 1));

var bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']
var composite = coll.mosaic(); 
var img = composite.clip(roi);

var newfc = forest.merge(no_forest);

var training = img.select(bands).sampleRegions({
  collection: newfc,
  properties: ['class'],
  scale: 30
});

var classifier = ee.Classifier.randomForest().train({
  features: training,
  classProperty: 'class',
  inputProperties: bands
});

var classified = img.select(bands).classify(classifier);

Map.addLayer(classified, {min:0, max: 1, palette: ['green', 'black']}, 'Forest-Classification');
2

Let's assume you need to keep only pixels in class n°1, which are for forest:

var forest_mask = classified.select('classification').eq(1)
var forest = img.updateMask(forest_mask)

Map.addLayer(forest, {bands:['B4','B3','B2'], min:0, max:0.3}, 'Forest')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.