Uploaded by li jingtai

Provide a brief introduction to the data preprocessing and feature extraction process on the GEE platform

advertisement
Provide a brief introduction to the data preprocessing and feature extraction process on the GEE
platform
var max_extent = ee.Image('JRC/GSW1_4/GlobalSurfaceWater').select("max_extent").eq(1);
//Map.addLayer(max_extent, {}, 'max_extent');
var region = ee.FeatureCollection(table).filterMetadata('number','equals','250')
//print("region",region);
Map.centerObject(region);
Map.addLayer(region,{},"region",false);
// Apply scaling factors.
function applyScaleFactors(image) {
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(0.2);
var thermalBands = image.select('ST_B.*').multiply(0.00341802)
.add(149.0);
return image.addBands(opticalBands, null, true)
.addBands(thermalBands, null, true);
}
// Define the cloud mask function.
function maskSrClouds(image) {
// Bit 0 - Fill
// Bit 1 - Dilated Cloud
// Bit 2 - Cirrus
// Bit 3 - Cloud
// Bit 4 - Cloud Shadow
var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111',
2)).eq(0);
var saturationMask = image.select('QA_RADSAT').eq(0);
return image.updateMask(qaMask)
.updateMask(saturationMask);
}
function mask(image) {
var img = image.updateMask(max_extent);
return img;
}
// Load and filter the Landsat 8 collection.
var maskCloud = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2022-03-01', '2022-10-31')
.filter(ee.Filter.lte("CLOUD_COVER", 20))
.filterBounds(region)
.map(applyScaleFactors)
.map(maskSrClouds)
.map(mask)
.select(
[ 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5','SR_B6', 'SR_B7'],
[ 'B2', 'B3', 'B4', 'B5', 'B6','B7']);
// Print size of collections, for comparison.
print('maskCloud', maskCloud);
// Create a composite.
var landsat8compositeMasked = maskCloud.median().clip(region);
//print('landsat8compositeMasked', landsat8compositeMasked);
//Map.addLayer(landsat8compositeMasked, {bands: ['B5', 'B4', 'B3']}, 'L8 compositemasked');
//////greenest and wettest
// adding NDVI band function
var addNDVI = function(image) {
var ndvi = ee.Image(image).normalizedDifference(['B5', 'B4']).rename('NDVI');
return ee.Image(image).addBands(ndvi);
};
// adding mNDWI function
var addMNDWI = function(image) {
var mndwi = ee.Image(image).normalizedDifference(['B3', 'B6']).rename('MNDWI');
return ee.Image(image).addBands(mndwi);
};
// adding LSWI function
var addLSWI = function(image) {
var lswi = ee.Image(image).normalizedDifference(['B5', 'B6']).rename('LSWI');
return ee.Image(image).addBands(lswi);
};
// adding AWEI function
var addAWEI = function(image) {
var awei= image.expression(
'4*(green-SWIR1)-(0.25*NIR+2.75*SWIR2)',{
green:image.select('B3'),
NIR:image.select('B5'),
SWIR1:image.select('B6'),
SWIR2:image.select('B7'),
}).rename('AWEI')
return ee.Image(image).addBands(awei);
};
// adding EVI function
var addEVI = function(image) {
var evi= image.expression(
'2.5*(NIR-red)/(NIR+6*red-7.5*blue+1)',{
red:image.select('B4'),
NIR:image.select('B5'),
blue:image.select('B2'),
}).rename('EVI')
return ee.Image(image).addBands(evi);
};
//add NDVI、MNDWI、AWEI
var with2WaterIndex = ee.ImageCollection(maskCloud).filterBounds(region)
.map(addNDVI)
.map(addMNDWI)
.map(addAWEI)
.map(addEVI)
.map(addLSWI)
.map(function(image) {
var img= image.clip(region)
return img;
});
print('with2WaterIndex',with2WaterIndex);
Map.addLayer(with2WaterIndex,{bands: ['B5', 'B4', 'B3']},'with2WaterIndex');
// 计算 greenest: qualityMosaic with max NDVI
var greenest = with2WaterIndex.qualityMosaic('NDVI').clip(region);
// print('greenest',greenest);
Map.addLayer(greenest,{bands: ['B5', 'B4', 'B3']},'greenest');
// 计算 wettest: qualityMosaic with max MNDWI
var wettest = with2WaterIndex.qualityMosaic('MNDWI').clip(region);
//print ('wettest',wettest);
//Map.addLayer(wettest,{bands: ['B5', 'B4', 'B3']},'wettest');
Download