1

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(
             qa.bitwiseAnd(cirrusBitMask).eq(0));

  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))
                  .filterBounds(ft)
                  .map(maskS2clouds)
                  .median();

// 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);
//print(newfc);
//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
});
print(training);
//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');
//Map.addLayer(newfc);
//Export the image to drive Storage.
Export.image.toDrive({
  image: classified ,
  description: 'classifiedRGB',
  scale: 20,
  maxPixels:350000000,
  region:ft
});
Export.table.toDrive({
  collection: newfc,
  description:'vectorsToDriveExample',
  fileFormat: 'KML'
});
2

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
});

Export.table.toAsset({
  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.