1

I am preparing parameters for the RF classification model. I calculated the NDVI,NDWI,EVI,NDBI from landsat8 time series. Then I calculated the minimum image colletcion (var min) and maximum image colletion (var max1) of the time series. Both of the two image collections include NDVI,NDWI,EVI,NDBI.

I define a function (DIFF) to further calculate the difference between the maximum and minimum image collection (including the difference between maximum value and minimum value of NDVI,NDWI,NDBI,EVI), but made mistakes in the codes (telling maxmin.map is not a function).

I think there should be easier way to calculate the difference, but I am still not practiced in GEE...

Link: https://code.earthengine.google.com/1fe1753f49d5ebbbb7aa4d86040e839c

var s2col = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filter(ee.Filter.calendarRange(2018, 2019, 'year'))
  .filter(ee.Filter.calendarRange(1, 3, 'month')).filterBounds(Linzhi);
  
//NDVI
function NDVI(image) {
  return image.addBands(image.normalizedDifference(["B5", "B4"]).rename("NDVI"));
}

//NDWI
function NDWI(image) {
  return image.addBands(
    image.normalizedDifference(["B3", "B5"])
         .rename("NDWI"));
}
  
//NDBI
function NDBI(image) {
  return image.addBands(
    image.normalizedDifference(["B6", "B5"])
         .rename("NDBI"));
}

//difference
function DIFF(image){
  return image.addBands(ee.Image.cat([image.select("NDVI_max").subtract(image.select("NDVI_min")).rename("NDVI_diff"),
        image.select("NDWI_max").subtract(image.select("NDWI_min")).rename("NDWI_diff"),
        image.select("NDBI_max").subtract(image.select("NDBI_min")).rename("NDBI_diff"),
        image.select("EVI_max").subtract(image.select("EVI_min")).rename("EVI_diff")]));
   }
   
//EVI
function EVI(image){
  return image.addBands(image.expression(
              '2.5*(NIR-RED)/(NIR+6*RED-7.5*BLUE+10000)',{
              NIR:image.select('B5'),
              RED:image.select('B4'),
              BLUE:image.select('B2'),
            }).float().rename('EVI')); 
}

var l8Col = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
              .filterBounds(Linzhi)
              .filterDate("2018-1-1", "2020-10-13")
              .filter(ee.Filter.lte("CLOUD_COVER", 50))
              .map(NDVI)
              .map(NDWI)
              .map(NDBI)
              .map(EVI);


var min = l8Col.reduce(ee.Reducer.intervalMean(0,5)).select(["NDVI_mean","NDWI_mean","NDBI_mean","EVI_mean"],["NDVI_min","NDWI_min","NDBI_min","EVI_min"]);
print(min,"min");
var max1 = l8Col.reduce(ee.Reducer.intervalMean(95,100)).select(["NDVI_mean","NDWI_mean","NDBI_mean","EVI_mean"],["NDVI_max","NDWI_max","NDBI_max","EVI_max"]);
print(max1,"max");

var maxmin = min.addBands(max1);
var maxmin1 = maxmin.map(DIFF);
print(maxmin,"maxmin");

1 Answer 1

0

If you want the difference you can subtract the two images (max and min) right away. This would work:

var diff = max1.subtract(min);
print(diff,"diff, max min");

However be aware that the bands won't be renamed like this.

2
  • Thankyou for sovling my problem! I got the result according to your sugestion! Oct 15, 2020 at 1:40
  • In this case you can hit the check mark next to my answer to mark your question as solved
    – JonasV
    Oct 15, 2020 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.