用GEE下载哨兵-2数据

1.先把自己需要的研究区的矢量文件存入个人文件中,详细内容见我的另一篇文章

2.代码如下

var district = ee.FeatureCollection("users/2309012038/whq")  //此处填入所导入shp文件的tabel id
var dsize = district.size();
print(dsize);
 
var district_geometry = district.geometry();
 
Map.centerObject(district_geometry,1);
Map.addLayer(district);
 
 
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')
                  .filterBounds(district_geometry)
                  .filterDate('2020-01-01', '2021-01-01')   //查询的时间段
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))  //云量设置
                  .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')
                  .filterBounds(district_geometry)
                  .filterDate('2020-01-01', '2021-01-01')     //此处应与前部分一致
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))  //同上
                  .map(maskS2clouds)
                  .select(['B4', 'B3', 'B2','B5','B6','B7','B8','B9']);   
                 //输出影像所含波段数(根据个人需求更改)
 
var mosaic = exportdataset.mosaic();
  
  Export.image.toDrive({
      image:mosaic,
      description:'Sentinel2-whq',   //此处修改输出名字
      scale:10,
      maxPixels: 1e13,
      region:district_geometry,
      fileFormat: 'GeoTIFF',   //输出格式(无需修改)
      formatOptions: {
        cloudOptimized: true
      }
    });

3.tasks处选择run,下好之后会有提示

4。在网盘里面打开运行出来的数据并下载

你可能感兴趣的:(java,前端,javascript)