function calculateIndices(img) {
// 选择所需波段
var nir = img.select("nir");
var swir1 = img.select("swir1");
var red = img.select("red");
var blue = img.select("blue");
var green = img.select("green");
var swir2 = img.select("swir2");
// 计算 NBR
var nbr = img.expression(
"(nir - swir1) / (nir + swir1)",
{
"nir": nir,
"swir1": swir1
}
).rename('NBR');
// 计算 NDVI
var ndvi = img.expression(
"(nir - red) / (nir + red)",
{
"nir": nir,
"red": red
}
).rename('NDVI');
var wet = img.expression(
"blue*(0.1509) + green*(0.1973) + red*(0.3279) + nir*(0.3406) + SWIR1*(-0.7112) + SWIR2*(-0.4572)",
{
'blue': blue,
'green': green,
'red': red,
'nir': nir,
'SWIR1': swir1,
'SWIR2': swir2
}
).rename('WET');
// 将两个指数组合成一个影像返回
return img.addBands([nbr, ndvi,wet]);
}