0

I am relatively new to utilizing the Google Earth Engine (GEE) platform, although I possess some experience in generating Land Use and Land Cover (LULC) maps using GIS software. Recently, I encountered challenges while attempting to create a LULC map using Landsat 5 and Landsat 8 imagery within Google Earth Engine (GEE).

I specified six classes for the classification, yet the resulting classified images only display four.

var images= L5.filterBounds(roi)
              .filterMetadata('CLOUD_COVER','less_than',10)
              .filterDate('2000-01-01', '2000-12-31')
              .sort('CLOUD_COVER', true);
              
              
              
  print(images)
var image = images.median().clip(roi);
var visualization = {
  bands: ['B3', 'B2', 'B1'],
  min: 0.0,
  max: 0.4, 
  gamma: 1.40,
};
 Map.centerObject(roi, 10);
 Map.addLayer(image, visualization, 'True Color (321)');
 


// Band map for index calculation
var bandMap = {
  BLUE: image.select('B1'),
  GREEN: image.select('B2'),
  RED: image.select('B3'),
  NIR: image.select('B4'),
  SWIR1: image.select('B5'),
  SWIR2: image.select('B7')
};


// eternal bands
var indices = ee.Image([
  { name: 'EVI', formula: '(2.5 * (NIR - RED)) / (NIR + 6 * RED - 7.5 * BLUE + 1)' },
  { name: 'NBR', formula: '(NIR - SWIR2) / (NIR + SWIR2)' },
  { name: 'NDMI', formula: '(NIR - SWIR1) / (NIR + SWIR1)' },
  { name: 'NDWI', formula: '(GREEN - NIR) / (GREEN + NIR)' },
  { name: 'NDBI', formula: '(SWIR1 - NIR) / (SWIR1 + NIR)' },
  { name: 'NDBaI', formula: '(SWIR1 - SWIR2) / (SWIR1 + SWIR2)' },
].map(function(dict){
  var indexImage = image.expression(dict.formula, bandMap).rename(dict.name);
  return indexImage;
}));

// Add index & SRTM to image
image = image.addBands(indices).addBands(srtm.clip(roi));

// samples
  
var training = Water1.merge(Builtup1).merge(Barrenland1).merge(Marsh_ricefield1).merge(Natural_plantation_forest1).merge(Floodedvegetation1);
// Split samples to train and test per class

var bands = ['B1','B2','B3','B4','B5','B6','B7', 'EVI', 'NBR', 'NDMI', 'NDWI', 'NDBI', 'NDBaI', 'elevation'];
var input = image.select(bands);
var label = 'Class';
var trainImage= input.sampleRegions({
  collection:training, 
  // properties:[label], 
  scale:30});
print(training);

var trainingData = trainImage.randomColumn();
var trainSet = trainingData.filter(ee.Filter.lessThan('random',0.8));
var testSet= trainingData.filter(ee.Filter.greaterThanOrEquals('random',0.8));

// classification 

// var  classifier = ee.Classifier.smileCart().train(trainSet, label, bands);
var classifier = ee.Classifier.smileRandomForest(64).train({features:trainSet,
  classProperty: 'Class',
  inputProperties:bands
  
});
//classify the landsat image
var classified = image.classify(classifier);

// difine visulization


// Map.addLayer(classified,{min:0, max:4, palette:['#0b9fd6','#d6d6d6','#2eb708','#d63000','#eae81e','#b7ff19','#d6b054','#ffa37e']},'Study 2000' );

// Map.addLayer(classified,{min:0, max:4, palette:['#08a8d6', 'F08080', 'D2B48C', '90EE90',  '228B22', '808000']},'Study 2000' );

Map.addLayer(classified,{min:0, max:4, palette:['blue', 'blue', 'red', 'brown',  'yellow', 'green']},'Study 2000' );







1
  • As per the Tour there should be only one question asked per question. Also, please include code as formatted text rather than links.
    – PolyGeo
    Commented Feb 21 at 5:55

1 Answer 1

0

Your current visualization parameters are only set to view min: 0 to max:4 classes. Could you try to expand that range and visualize again:

  Map.addLayer(classified, 
             {min: 0, max: 6, 
              palette:['blue', 'blue', 'red', 'brown',  'yellow', 'green']},'Study 2000' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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