I am trying to improve image classification in GEE by using the STM of the mean. I first calculated the mean of the four bands.

Then I added the new column with mean to the image.

Then I used the new image with 5 bands (including the mean) to classify.

However, I keep getting errors in my classification. Here is my code:

Map.addLayer(image, imageVisParam);

//select the bands 
var bands = ['b1', 'b2', 'b3', 'b4'];

var stm = image.select(bands).reduce(ee.Reducer.mean()).rename('STM')

var classNames = Water.merge(BuiltupArea).merge(Cropland).merge(Vegetation).merge(Wetland).merge(clouds)

var imageWithSTM = image.addBands(stm)

var classifier = ee.Classifier.smileRandomForest(50)
    features: classNames,
    classProperty: 'Class', 
    inputProperties: bands.concat(['STM'])
print(classifier, 'classifier')

var classified = imageWithSTM.classify(classifier)

print(classified, 'classified');

//Add the classification to the map view, specify colours for classes
{min: 0, max: 5, palette: ['0000FF', 'FF0000', '008000','FFFF00','98ff00','ffc82d']},

I get this error when I run the codes: Image (Error) Property 'b1' of feature '0' is missing. classification: Layer error: Property 'b1' of feature '0' is missing.

How can I change my code to use all five bands or more in the classification without getting an error?

  • 2
    What error do you get? Include your asset and training data in the code, so the error can be replicated. Make sure the assets are shared. Sep 18 at 11:05
  • Please share the particular code snippet rather the whole repository link.
    – Padmanabha
    Sep 18 at 14:19
  • @Padmanabha I have edited the question with the code snippet Sep 18 at 18:48
  • Perhaps feature 0 is outside the bounds of the image? check developers.google.com/earth-engine/guides/… Sep 25 at 13:32
  • It seems like that's not the case. When I run the classification using the same training data but without the additional STM column, it functions perfectly. The issue seems to have been introduced when I added the new field. Sep 26 at 9:50


Your Answer

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