-1

I am attempting to calculate NDVI from NAIP imagery, add the NDVI band as an additional band to the NAIP imagery and then chart it. I am easily able to calculate NDVI from NAIP imagery with the below code

var willowspring = table2
var naipspring = ee.ImageCollection("USDA/NAIP/DOQQ")
                          .filterDate('2011-01-01','2011-12-31')
                           .filterBounds(willowspring)
var naipmosaic = naipspring.mosaic();
Map.addLayer(naipmosaic.clip(willowspring), {bands: ['R', 'G', 'B']}, 'NAIP'); 
var naipndvi = naipmosaic.normalizedDifference(['N','R'])
var ndviParams = {min: -1, max: 1, palette: ['8B0000','FF0000', 'FF4500', 'FFFF00', '00FF00','008000', '006400']};
Map.addLayer(naipndvi.clip(willowspring), ndviParams, 'NAIP NDVI 2011');

I am running into problems adding the NDVI band onto the NAIP imagery. I've tried a variety of different ways but it never seems to add the band correctly and then when I try and create a chart I received errors saying that no bands match 'ndvi'.

1

You can map ndvi over the collection and then create the mosaic including the ndvi:

var willowspring = table2

var naipspring = ee.ImageCollection("USDA/NAIP/DOQQ")
                          .filterDate('2011-01-01','2011-12-31')
                          .filterBounds(willowspring);
// function to add ndvi to the collection
var NDVI = function(image) {
  var index= image.normalizedDifference(['N','R']).rename('NDVI');
  return image.addBands(index);
};
//add NDVI
var naipspring_ndvi= naipspring.map(NDVI);

var naipmosaic = naipspring_ndvi.mosaic();
Map.addLayer(naipmosaic.clip(geometry), {bands: ['R', 'G', 'B']}, 'NAIP'); 
var ndviParams = {min: -1, max: 1, palette: ['8B0000','FF0000', 'FF4500', 'FFFF00', '00FF00','008000', '006400']};
Map.addLayer(naipmosaic.select(['NDVI']).clip(willowspring), ndviParams, 'NAIP NDVI 2011');

Or You can just add the NDVI to the mosaic:

var naipmosaic_ndvi= naipmosaic.addBands(naipmosaic.normalizedDifference(['N','R']).rename('NDVI'));
  • Thank you! I am still having trouble charting this however. Below is my code and each time I try and create the chart I get a 'no features contains non-null values of "system:time_start"'. code.earthengine.google.com/e2b743d32730fd8c1478890c29079ffc – Lydia Keenan Oct 29 at 14:36
  • Perhaps what you´d like to print is the collection rather than the mosaic, in that case you need to change the variable called in the chart. Also the images have the same date on 2011. When you print 2011 dates only, no lines are shown, however, if you widen your selected dates (i.e. filterDate('2011-01-01','2012-12-31')) the line chart shows. !example chart – Oscar Oct 29 at 15:40

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.