var district = table;
var dsize = district.size();
var district_geometry = district.geometry();
print(dsize);
Map.centerObject(district_geometry,7);
//去雲的範圍內的範圍內,
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 分別是雲和捲雲
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
//處理資料,生成資料集
var dataset = ee.ImageCollection("COPERNICUS/S2_SR")
.filterBounds(district_geometry)
.filterDate('2020-10-28', '2020-10-30')
// 選擇雲量真彩色真彩色,0到到100的範圍內
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.map(maskS2clouds)
.select(['B2', 'B3', 'B4','B5','B6','B7','B8A','B11','B12']);
//視覺化引數,按2,3,4波段合成真彩色
var rgbVis = {
min: 0.0,
max: 0.3,
bands: ['B2', 'B3', 'B4'],
};
//按中值合成指定指定時間段的影像
Map.addLayer(dataset.median(), rgbVis, 'RGB');
//設定顯示樣式:color代表邊界顏色;fillcolor代表填充顏色
var styling={color:'red',fillColor:'00000000'}
//FH就是向量邊界,這裡可以不用管
Map.addLayer(district.style(styling),{},"FH");
var IMAGE = dataset.mosaic();
//下載資料
Export.image.toDrive({
image:IMAGE,
description:'Sentinel2',
scale:30,
maxPixels: 1e13,
region:district_geometry,
crs: "EPSG:32649",
fileFormat: 'GeoTIFF',
formatOptions: {
cloudOptimized: true
}
});