TransWikia.com

Sentinel 2A Classification in Google Earth Engine

Geographic Information Systems Asked by SAKTHIVEL. R on December 27, 2020

I tried to get classify image for my region of interest using Sentinel 2 data. I got the result, but I am getting an error.

enter image description here

var roi = ee.Geometry.Rectangle([82.5,18,83,18.5]);


//this comment for filtering the sentinel2 images in order to cloud cover , date,roi
var data = sentinel2.filterBounds(roi)
      .filterDate ('2020-05-01','2020-06-01')
      .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',10))
      .select('B2','B3','B4','B8')
      .median();

print(data);


Map.addLayer(roi);
Map.centerObject(roi);
// Map.addLayer(data);


var cliproi = data.clip(roi);


Map.addLayer (cliproi);

var training = waterbody.merge(agriculture).merge(forest).merge(buildup);

// taking training samples
var training = cliproi.sampleRegions({
  collection: training,
  properties: ['landcover'],
  geometries:true,
  scale: 10
  });
  
print (training);
  
// Extract training data from select bands of the image, print to console
var bands = ['B2', 'B3', 'B4', 'B8'];
var training = cliproi.select(bands).sampleRegions({
  collection: training,
  properties: ['landcover'],
  scale: 10
});  

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



//Run the classification
var classified = cliproi.select(bands).classify(classifier);

//Add the classification to the map view, specify colours for classes
Map.addLayer(classified,{min: 0, max: 3, palette: ['#0f1ad6', '#98ff00', '#037b3b','#ff4d4d','#ffb570']},'Classified');

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP