I've been trying to run this code on Google Earth Engine, however I get the following error and I'm not sure how I can resolve this issue:
//Set map centre
Map.setCenter(159.9737, -9.4336, 12.5)
//Import Sentinel-2 Imagery
var S2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2017-01-01', '2021-01-01')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
//clip to region of interest
var median = S2.median();
var clipped = median.clip(roi);
//add different visualisations to map
Map.addLayer(clipped, {bands: ['B4', 'B3', 'B2'], min: 301.55555555555554, max: 2162}, 'True Colour')
Map.addLayer(clipped, {bands: ['B8', 'B4', 'B3'], min: 215.9245283018868, max: 4181.5}, 'False Colour')
Map.addLayer(clipped, {bands: ['B12', 'B8', 'B4'], min: 68.14285714285714, max: 3633}, 'SWIR')
//add NDVI to map
var maskcloud1 = function(image) {
var QA60 = image.select(['QA60']);
return image.updateMask(QA60.lt(1));
};
var addNDVI = function(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']));
};
var S2 = S2.map(addNDVI);
var NDVI = S2.select(['nd']);
var NDVI = NDVI.median();
var ndvi_pal = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901', '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01', '012E01', '011D01', '011301'];
Map.addLayer(NDVI.clip(roi), {min:-0.5, max:0.9, palette: ndvi_pal}, 'NDVI');
//merge training points
var points = Water.merge(BuiltUp).merge(Road).merge(TreeShrub).merge(GrassBare)
print(points,'points');
var bands = ["B1","B2","B3","B4","B5","B6","B7","B10","B11","B12"];
var label = 'LandCover';
//sample training points to generate training data
var training = clipped.select(bands).sampleRegions({
collection: points,
properties: ['LC'],
scale: 30
});
print(training, 'training');
//train a CART classifier
var classifier = ee.Classifier.smileCart().train({
features: training,
classProperty: "LandCover",
inputProperties: bands});
//run final classification
var classified_image = clipped.select(bands).classify(classifier);
print(classifier,'classifier')
Map.addLayer(classified_image, {palette: ['blue','green', 'red']},
'Classified');
How can I resolve this?