I am very new to GEE. I have been trying to figure out how to assign different colours to different NDVI values. Let's say, in following code, I want to assign 'red' for NDVI value of 0.2-0.4, 'orange' for 0.4-0.6, 'yellow' for 0.6-0.8, and 'green' for 0.8-1. When I use following code, I feel that I do not have full control over the colours that are being assigned to the NDVI values. The colours I get are gradual based on the NDVI value at certain pixel. What I am trying to do is displaying all pixels that fall in the respective NDVI range in the same colour (something that is done in symbology of ArcMap or QGIS). link to the code: https://code.earthengine.google.com/1f92036224ea8e7e193820ca30c1cef7
Code I have:
// Point for filterbound
var roi = ee.Geometry.Point([92.1339935642684,21.19472665398992])
// Center the display to ROI.
Map.centerObject(roi, 11);
// Function to get NDVI.
var getNDVI = function(image){
var NDVI = image.normalizedDifference(['B8', 'B4']).rename('NDVI')
var clouds = image.select('QA60').gte(1024).unmask().not().rename('CloudMask')
return image.addBands(NDVI).select('NDVI');
//.addBands(clouds).mask(clouds)
};
// Gets the current time.
var eeNow = ee.Date(Date.now());
// SET OBSERVATION PERIOD
var startDate = '2018-02-15';
var endDate = eeNow;
// Gets image collection of Observation Period
var series = ee.ImageCollection('COPERNICUS/S2').filterDate(startDate, endDate)
.filterBounds(roi)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
// APPLY NDVI FUNCTION TO OBSERVATIONS
series = series.map(getNDVI)
Map.addLayer(series.first(), {bands: ['NDVI'], min:0.2, max: 1, palette: ['red', 'orange', 'yellow', 'green']}, 'first')