GEE下载Sentinel-2A数据

2023-10-16 19:04:26 浏览数 (2)

代码语言:javascript复制
Map.centerObject(table,7);
//这里可调整加载时影像的显示大小
Map.addLayer(table)
function maskS2clouds(image) {
  var qa = image.select('QA60');
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
  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(table)
                  .filterDate('2022-07-05', '2022-07-07')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
                  .map(maskS2clouds);
                  
var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],
};
 
 
Map.addLayer(dataset.median(), rgbVis, 'RGB');                 
var exportdataset =  ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterBounds(table)
                  .filterDate('2022-07-05', '2022-07-07')
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
                  .map(maskS2clouds)
                  .select(['B4', 'B3', 'B2']);
//镶嵌裁剪函数,减少之后的工作量
var mosaic = exportdataset.mosaic().clip(table);
  
  Export.image.toDrive({
      image:mosaic,
      description:'2022',
      scale:10,
      maxPixels: 1e13,
      region:table,
      fileFormat: 'GeoTIFF',
      formatOptions: {
        cloudOptimized: true
      }
    });

运行代码时仅需将shp导入,然后修改你所需的时间和波段,点击运行即可,最后下载后的影像是已经过shp裁剪过的影像,无需后续再使用Arcmap等软件裁剪。

0 人点赞