Below is the script and I've also put an image of what it's meant to look like and what my image ends up looking like

// The Landsat 8 top of atmosphere reflectance data
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA");

// ROI

// filter the data collection 
var filtered = l8.filterDate('2013-04-01', Date.now())

// Get a cloud free image
var cloudFreeImage = filtered.sort('CLOUD_COVER').first();

// add the cloud free true colour image to mapping layer
var rgb_vis = {min: 0, max: 0.3, bands:['B4', 'B3', 'B2']};
Map.addLayer(cloudFreeImage, rgb_vis, 'True color');

// add the cloud-free false-colour image to the mapping layer
Map.addLayer(cloudFreeImage, {min: 0, max: 0.3, bands:['B5', 'B4', 'B3']}, 'False Color');

// add the median image to the mapping layer
Map.addLayer(filtered.median(), rgb_vis, 'median RGB');

// compute NDVI and add the NDVI image to the mapping area
var ndvi = cloudFreeImage.normalizedDifference(['B5', 'B4']);
Map.addLayer(ndvi, {min: 0, max: 1, palette:['brown','yellow','green']}, 'NDVI');

// add a new ndvi band a single l8 image
function addNDVIband(anImage) {
  var ndviTemp = anImage.normalizedDifference(['B5', 'B4']);
  return anImage.addBands(ndviTemp.rename('NDVI'));}

// test the function on a single image
var ndviAdded = addNDVIband(cloudFreeImage);
print ('Before adding NDVI', cloudFreeImage);
print ('After adding NDVI', ndviAdded);

// map the function to the image collection
var ndviMapped = filtered.map(addNDVIband);
print ('After mapping NDVI', ndviMapped);

// apply temporal reducer to the NDVI band that has been added to the image collection. 
Map.addLayer(ndviMapped.median(), {bands: 'NDVI', min: 0, max: 1, palette:['brown','yellow','green']}, 'median ndvi');

/*// chart the ndvi over time
var ndviChart = ui.Chart.image.series({
  region: roi,
  reducer: ee.Reducer.median(),
  scale: 90,

[NDVI over region][1

what mine looks like with the code I'm using


You haven't said exactly what you want to change about your output, but the two most obvious differences are:

  • The resulting image should be clipped to the polygon. So use Image.clip:

        {bands: 'NDVI', min: 0.1, max: 0.4, palette: ['brown','yellow','green']}, 
        'median ndvi');
  • There is a black border. So draw the border using FeatureCollection.style:

    Map.addLayer(ee.FeatureCollection([roi]).style({fillColor: '00000000'}), {}, 'ROI');

You may also need to adjust your min and max to get more contrast. You didn't provide your roi polygon so I can't match the coastline, but here's what I get with a simple drawn polygon and min: 0.1, max: 0.4:

Screenshot of modified script


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.