Quiero clasificar mi raster NDVI utilizando datos de entrenamiento en Google Earth Engine. Para ello estoy utilizando el siguiente código. Pero está devolviendo algún error como ndvi no es una banda utilizable. Por favor, ayuda en esto
// Cloud Masking function
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = ee.Number(2).pow(10).int();
var cirrusBitMask = ee.Number(2).pow(11).int();
// Both flags should be set to zero, indicating clear conditions
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0));
// Return the masked and scaled data.
return image.updateMask(mask).divide(10000);
}
// AOI of Study Area
var boundary = ee.FeatureCollection('ft:1rbhNtC1TqDBvY9Rt2BZR-DjhpIPuC3nU5kmz49WW');//Jorhat Boundary
//var boundary = ee.FeatureCollection('ft:1ABffZYEE4XhMTOXsoSfWENKXBK2fQfOrdMplEaVo');//Midnapur Boundary
// Import of Images (Sentinel 2 multispectral)
var image = ee.ImageCollection(sent2img
.filterDate("2017-12-01","2018-01-30")
.filterBounds(boundary)
.map(maskS2clouds)
.sort("CLOUD_COVERAGE_ASSESSMENT")
.median()
);
// Preprocessing
var mosaic = image.mosaic()
var clip = mosaic.clip(boundary);
print(clip);
// FCC creation and visualisation of AOI
Map.addLayer(clip, {bands: ['B8','B4','B3'], min: 0, max: 0.3},'clip');
// NDVI calculation
var ndvi = clip.expression(
' ((NIR - RED) / (NIR + RED))', {
'NIR': clip.select('B8'),
'RED': clip.select('B4'),
}).rename('nd');
print(ndvi);
// Colour Palette
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
'004C00', '023B01', '012E01', '011D01', '011301'];
// Map display
Map.addLayer(ndvi, {min:0, max:1, palette: palette},"NDVI");
// Training Classes
var newfc = wb.merge(plantation)
.merge(agriland1)
.merge(agriland2)
.merge(habitation)
.merge(sandyarea)
.merge(deepplantation);
var bands = ['nd'];
var training = clip.select(bands).sampleRegions({
collection: newfc,
properties: ['class'],
scale: 20,
geometries:true
});
var classifier = ee.Classifier.cart().train({
features: training,
classProperty: 'class',
inputProperties: bands
});
var classified = clip.select(bands).classify(classifier);
Map.addLayer(
classified,
{min: 1, max: 7, palette: ['#0d1898', '#ff0841', '#138b11','#fff81c','#154c17','#529400','#F1B555']},
'classification');