Link to Earth Engine code:https://code.earthengine.google.com/4da2d54d1ece4229b76c52a9d921ca70 Below I have pasted my code:

function maskS2clouds(image) {
  var qa = image.select('QA60');
  var cloudBitMask = ee.Number(2).pow(10).int();
  var cirrusBitMask = ee.Number(2).pow(11).int();
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(

  return image.updateMask(mask).divide(10000);

// Map the function over one year of data and take the median.
var composite = s2.filterDate('2018-03-01', '2018-03-31')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))

// Display the results.

Map.setCenter(87.32,22.40, 6);
//Map.addLayer(composite, {bands: ['B6', 'B4', 'B3'], min: 0, max: 0.3},'fcc');

var landcover_roi = composite.clip(ft);

Map.addLayer(landcover_roi, {bands: ['B6', 'B4', 'B3'], min: 0, max: 0.3},'clip');
Map.addLayer(ft, {}, 'From Fusion Table');

// Make a palette: a list of hex strings.
//var newfc = waterbody.merge(river).merge(fallow).merge(builtup).merge(forest).merge(agriland);
var newfc=waterbody.merge(agriland).merge(built_up);
//create training data
var bands = ['B2','B3','B4','B5','B6','B7','B8', 'B8A'];
var training = landcover_roi.select(bands).sampleRegions({
  collection: newfc, 
  properties: ['class'], 
  scale: 30
//Train the classifier
var classifier = ee.Classifier.cart().train({
  features: training, 
  classProperty: 'class', 
  inputProperties: bands
var classified = landcover_roi.select(bands).classify(classifier);
//Display classification
Map.centerObject(newfc, 8);
var trainAccuracy = classifier.confusionMatrix();
print('Resubstitution error matrix: ', trainAccuracy);
print('Training overall accuracy: ', trainAccuracy.accuracy());

//Map.addLayer(sentinel, {bands: ['B6', 'B4', 'B3'], max: 0.3}, 'sentinel image');
Map.addLayer(classified, {min: 1, max: 3, palette: ['#0f1cbf', '#3df6ff', '#dfc723','#d87cf0','#335124','#81ff41']}, 'classification');
//Export the image to drive Storage.
  image: classified ,
  description: 'classifiedRGB',
  scale: 20,
  collection: newfc,
  fileFormat: 'KML'

Set geometries to true, then export to a table asset. Snippet:

var training = landcover_roi.select(bands).sampleRegions({
  collection: newfc, 
  properties: ['class'], 
  scale: 30,
  geometries: true

  collection: training, 
  description: 'foo', 
  assetId: 'foo'
  • Please upvote the answer if this solves your problem. – Nicholas Clinton Oct 3 '18 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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