1

The code of my problem is as follows:

var image = ee.Image(sent2
 .filterBounds(geometry2)
 .filterDate('2016-01-01', '2016-03-31')
 .sort("CLOUD_COVERAGE_ASSESSMENT")
 .first());

// print the image to the console.

    print("A Sentinel-2 scene:", image);

Clip a geometry of study area

var image1=image.clip(geometry2)

//merging the feature collection collected 

var newfc = forest.merge(gram2).merge(baresoil).merge(wheat2).merge(mustard2);

var bands = [ 'B8', 'B4', 'B3'];

var training = image1.select(bands).sampleRegions({collection: newfc, properties: ['landcover'], scale: 10});

Train the classifier using CART

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

Run the classification

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

Map.addLayer(classified, {min: 0, max: 4, palette: '0D5D07','B47610','F7C537','7CE72E','EFF60E']},'classification');

//0 forest 1 baresoil 2 gram 3 wheat 4 mustard

var PIXEL_SCALE = 10; // Meters. Resolution of most sentinel bands

var PIXEL_AREA = PIXEL_SCALE * PIXEL_SCALE; // Square meters.

Calculate the number of pixels of each classification in our polygon

var regionCoverHistogram = image1.select('classifier') .reduceRegion(ee.Reducer.frequencyHistogram(), geometry2, PIXEL_SCALE);

print('classified class pixel count within region', regionCoverHistogram);

var wheatPixelCount =ee.Dictionary(regionCoverHistogram.get('wheat2')).get(wheat2.toString());

var wheatArea = ee.Number(wheatPixelCount).multiply(PIXEL_AREA);

print('Wheat Area (sq meters) in region', wheatArea);

showing error as follows:

classified class pixel count within region Dictionary (Error) Image.select: Pattern 'classifier' did not match any bands. Wheat Area (sq meters) in region Number (Error) Image.select: Pattern 'classifier' did not match any bands.

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
neetu rathi
  • 11
  • 1
  • 3

1 Answers1

0

Without the script it will be difficult to tell but my guess would be that the band('classifier) you are trying to select for your histogram is not inside image1 but inside your result image: 'classified'.

Change image1 to classified would be a first suggestion.

Jobbo90
  • 175
  • 1
  • 11