I want to apply and examine random forest classification results on landsat 8 image collection in Google Earth Engine (as modified from the origin code in Earth Engine Tutorials)

Accordingly I developed such a code:

var classNames = urban.merge(water).merge(forest);

var roi = ee.Geometry.Point(30.8814, 37.8253);

function scaleFactor(image) {

  // Apply the scaling factors to the appropriate bands.
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);

  // Replace the original bands with the scaled ones and apply the masks.
  return image.addBands(opticalBands, null, true)
      .addBands(thermalBands, null, true)

// Map the function over one year of data.
var collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
                     .filterDate('2021-01-01', '2021-11-15')
                     .select(['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7','ST_B10'])

// Display the results.
Map.centerObject(roi, 12);  
Map.addLayer(collection.clip(roi), {bands: ['SR_B4', 'SR_B3', 'SR_B2'], min: 0, max: 0.3},'Landsat 8 Imagary');

var landsat = ee.Image(collection);

var training = landsat.addBands(classNames).sample({
  numPixels: 5000,
  seed: 0
var classifier = ee.Classifier.smileRandomForest(10)
      features: training,
      classProperty: 'landcover',
      inputProperties: ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7','ST_B10']
 var classified = landsat.classify(classifier);

Map.addLayer(landsat, {bands: ['SR_B4', 'SR_B3', 'SR_B2'], max: 0.4}, 'landsat');
Map.addLayer(classified, {}, 'Random Forest Classification');  

but the code stoped by error:

FeatureCollection (Error)
Image.addBands, argument 'srcImg': Invalid type.
Expected type: Image<unknown bands>.
Actual type: FeatureCollection.

i try to convert my feature class to image type but that does not worked any way

Is there any suggesstion for me to solve that?



Your Answer

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