2

I would like to get the normalized difference of each image within an image collection (In this case Sentinel-2) for a specific polygon/geometry and then chart the values calculated for each image.

Is there a way I can do this?

The bands for which I would like to get the normalized difference are B8 and B4.


Sources

example


Code for the current chart

var filterDate = new Date();
  filterDate = filterDate.getFullYear() 
    + '-' + (filterDate.getMonth() + 1) 
    + '-' + filterDate.getDate();

  var kcAccum = imageCollection3.filterBounds(Lixin).filterDate('2019-01-01',filterDate);
  var kcChart = ui.Chart.image.series(kcAccum, geom, ee.Reducer.mean());
  print(kcChart);

Results of script

example2


EDIT

I changed the code to use the map function to compute the normalized difference for each image in the original collection. However, now when I try to chart the computed collection, I get an error message. The computed image collection is correct. It's just when I try to chart it that it gives problems.

Code Edited

var kcAccum = imageCollection3.filterBounds(Lixin).filterDate('2019-01-01',filterDate).map(function(kcimage) {
    return kcimage.normalizedDifference(['B8', 'B4']).rename('kc');
  });
print(kcAccum);
var kcChart = ui.Chart.image.series(kcAccum, geom);
print(kcChart);

Error Message

example3

  • You need to look at the docs. You should add an NDVI band to each image (developers.google.com/earth-engine/tutorial_api_06) then call your Reducer on the NDVI band only (currently you are calling for the mean of each band, hence the many lines on your chart). E.g. in your ui.Chart call, try kcAccum.select('B1') and you'll only get the B1 results. – Jon Jun 27 at 21:29
  • I now used the map function to create an image collection where each image has the normalized difference calculation. However, when I try to chart this new image collection, I get an error message. Do you know what I'm doing wrong? This is the new code: var kcAccum = imageCollection3.filterBounds(Lixin).filterDate('2019-01-01',filterDate).map(function(kcimage) { return kcimage.normalizedDifference(['B8', 'B4']).rename('Kc'); }); print(kcAccum); var kcChart = ui.Chart.image.series(kcAccum, geom); print(kcChart); – cdcerv Jun 28 at 4:43
  • 1
    Add the system:time_start property link – Kuik Jun 28 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.