如何在 Earth Engine 中将云遮罩应用于 mndwi 图像?

How can I apply cloud masking to mndwi image in Earth Engine?

我想对 MDNWI 图像应用云遮罩,但收到错误消息“s2SR.map 不是函数”。不知道怎么解决。


var geometry=ee.Geometry.Polygon([[41.55427215633343,41.57962485896675],
              [41.607143860434995,41.57962485896675],
              [41.607143860434995,41.62429558047125],
              [41.55427215633343,41.62429558047125],
              [41.55427215633343,41.57962485896675]]);

var s2SR = ee.ImageCollection('COPERNICUS/S2_SR')
              //filter start and end date
             .filter(ee.Filter.calendarRange(2018,2018,'year'))
             .filter(ee.Filter.calendarRange(9,10,'month'))
             //filter according to drawn boundary
             .filterBounds(geometry)
             .filterMetadata('CLOUD_COVERAGE_ASSESSMENT', 'less_than',1)
             .mean();
             
             
//print(typeof(s2SR))
//print("s2SR", s2SR);
//Map.addLayer(s2SR, {bands: ['B4', 'B3', 'B2'], min: 0, max: 2000}, 'Sentinel ');
Map.centerObject(geometry,10)

var Green = s2SR.select("B3");
var SWIR = s2SR.select("B11");
var mndwi = Green.subtract(SWIR).divide(Green.add(SWIR)).rename('MNDWI');





//Map.addLayer(mndwi, {min:0, max:1}, 'mndwı');


///// Cloud

  var S2maskedVeg = function(image) {
   var MNDWI = image.select(['MNDWI']);
     return image.addBands(ee.Image(1).updateMask(mndwi.gte(0.95)).rename('MNDVI_mask'));
  };

var S2collection = s2SR.map(mndwi).map(S2maskedVeg)

Map.addLayer(S2collection,{}, 'S2 NDWI mask');

(https://code.earthengine.google.com/6835ca74e985d40df906681039358ee1)

在这里,您已经计算了整个集合的 MNDWI:

var mndwi = Green.subtract(SWIR).divide(Green.add(SWIR)).rename('MNDWI');

因此,这一行意义不大:

var S2collection = s2SR.map(mndwi).map(S2maskedVeg)

map() 需要一个函数作为输入,但它是一个 ImageCollection。您可以跳过此部分并将 S2maskedVeg() 函数直接映射到 mndwi 上:

var S2collection = mndwi.map(S2maskedVeg)