提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
最近在使用GEE批量下载Landsat8数据,发现网上很多关于Landsat8的去云代码都有点错误,因此在这分享一下最新的去云下载代码。
一、去云
代码如下:
function maskL8sr(image) {
// The third bit is cloud and the fourth bit is cloudshadow。
var cloudShadowBitMask = 1 << 4;
var cloudsBitMask = 1 << 3;
// Get QA_PIXEL band.
var qa = image.select('QA_PIXEL');
// Set the cloud mask to zero
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
// Update the cloudmask
return image.updateMask(mask)
.select("SR_B.*")
.copyProperties(image, ["system:time_start"]);
}
首先,网上大部分代码去云时选择的“pixel_qa”波段,现在实际上为“QA_PIXEL”波段,此外很多代码选择的是Bit3和Bit5,而我特地看了下数据介绍,明确写着是Bit3是云,Bit4是云阴影,而Bit5是雪。
如图:
二、数据获取与导出下载
1.获取数据
代码如下:
// Map the function over 3 months of data and take the median.
// Load Landsat-8 surface reflectance data.
var landsat8 = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.filterBounds(table)
.filterDate('2020-12-01','2021-2-28')
// Pre-filter to get less cloudy granules.
.filter(ee.Filter.lte('CLOUD_COVER',5))
.map(maskL8sr)
.median()
.clip(table);
landsat8 = landsat8.uint16();
print(landsat8);// visualize the datasets
var rgbVis = {
min: 8400,
max: 15000,
gamma:1.5,
bands: ['SR_B4', 'SR_B3', 'SR_B2'],
};
Map.addLayer(landsat8,rgbVis,'landsat8');
var imgselect = landsat8.select('SR_B2','SR_B3','SR_B4','SR_B5');
这里的时间、云量都可以自己进行设置,table是自己导入的shapefile,用于对影像进行裁切。
2.导出数据
代码如下:
//Export image to google drive and then download
Export.image.toDrive({
image:imgselect,
description:'s4',
scale:30,
region:table,
folder:"result",
crs: "EPSG:4326",
maxPixels: 1e13
});