GEE学习笔记:在Google Earth Engine(GEE)中批量下载Sentinel-2影像

        目标:批量下载研究区域满足一定条件的所有Sentinel-2影像。

        Sentienl-2A携带了一枚多光谱成像仪(MSI),具有三种不同的空间分辨率 ,10m空间分辨率下有四个波段( B2、B3、B4、B8),20m 空间分辨率下有六个波段( B5、B6、B7、B8A、B11、B12),剩余三个波段为 60m空间分辨率。

目录

一、分步介绍

1、去云

2、筛选影像

3、批量导出影像

二、完整代码


一、分步介绍

1、去云

var roi = table;//table为自己上传的矢量边界

//去云算法
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  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);
}

2、筛选影像

这里使用的是Level-2A数据

GEE学习笔记:在Google Earth Engine(GEE)中批量下载Sentinel-2影像_第1张图片

var s2_collection = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterBounds(roi)
                  .filterDate('2019-04-01', '2019-05-31')
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
                  .map(function(image){
                      return image.clip(roi)//按研究区域裁剪
                  })
                  .map(maskS2clouds);
             
print("s2_collection",s2_collection)
     
var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],
};

Map.addLayer(s2_collection, rgbVis, 's2_collection');
Map.centerObject(roi,7)

3、批量导出影像

function exportImageCollection(imgCol) {
  var indexList = imgCol.reduceColumns(ee.Reducer.toList(), ["system:index"])
                        .get("list");
  indexList.evaluate(function(indexs) {
    for (var i=0; i

二、完整代码

var roi = table;//table为自己上传的矢量边界

//去云算法
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  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 s2_collection = ee.ImageCollection('COPERNICUS/S2_SR')
                  .filterBounds(roi)
                  .filterDate('2019-04-01', '2019-05-31')
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
                  .map(function(image){
                      return image.clip(roi)//按研究区域裁剪
                  })
                  .map(maskS2clouds);
             
print("s2_collection",s2_collection)
     
var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],
};

Map.addLayer(s2_collection, rgbVis, 's2_collection');
Map.centerObject(roi,7)

//显示矢量边界
var styling = {color:"red",fillColor:"00000000"};
Map.addLayer(roi.style(styling),{},"boundary");

//影像集合导出方法
function exportImageCollection(imgCol) {
  var indexList = imgCol.reduceColumns(ee.Reducer.toList(), ["system:index"])
                        .get("list");
  indexList.evaluate(function(indexs) {
    for (var i=0; i

        结果显示:

GEE学习笔记:在Google Earth Engine(GEE)中批量下载Sentinel-2影像_第2张图片

        在【Console】下可查看每个影像的信息。

 GEE学习笔记:在Google Earth Engine(GEE)中批量下载Sentinel-2影像_第3张图片

        在【Tasks】下,点击【RUN】,等待上传完成。

 GEE学习笔记:在Google Earth Engine(GEE)中批量下载Sentinel-2影像_第4张图片

你可能感兴趣的:(GEE学习笔记,遥感,GEE,编程,Sentinel-2,数据下载)