GEE 01 -Sentinel2A Sentinel data download

The Google Earth Engine engine platform has a large amount of image data, Landsat series, Sentinel series, Modis series, which can query, obtain data, and process data online.

1. Engine introduction

First, you need to be able to access the engine (https://code.earthengine.google.com/). Second, you also need a Google account. Then, you can log in and access the Code online editor.
Insert picture description here

2. Download data

The operation here is to upload a vector data shapefile, query sentinel data within a certain range, select a combination of blue, green and red, export the GeoTiff file to Google Drive, and then download it from the Drive cloud disk to the local. (Drive free storage is only 15GB, so if there is too much data, you need to export and clean the cloud disk in batches; in addition, if the download data is too large, GEE itself has limitations, and a single task cannot be too large.)

1. Upload Shapefile file

Insert picture description here
You can see the uploaded Shapefile file in assets:
Insert picture description here

After the upload is complete, the Shapefile data can be loaded and displayed on the map:

var district = ee.FeatureCollection("users/xxxxx/data/nj");

var dsize = district.size();
print(dsize);

var district_geometry = district.geometry();

Map.centerObject(district_geometry,12);
Map.addLayer(district);

The effect shown on the figure:
Insert picture description here

2. Query sentinel data

Query for a specific period of time, control cloud content, and load on the map:

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);
}


// Map the function over one year of data.
// Load Sentinel-2 TOA reflectance data.
var dataset = ee.ImageCollection('COPERNICUS/S2')
                  .filterBounds(district_geometry)
                  .filterDate('2017-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');

For cloud mask control, it mainly comes from official data description: the
Insert picture description here
effect after the above picture is as follows:
Insert picture description here

3. Export download data

Export to Cloud Disk Drive.

//export data
var exportdataset =  ee.ImageCollection('COPERNICUS/S2')
                  .filterBounds(district_geometry)
                  .filterDate('2017-01-01', '2021-01-01')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
                  .map(maskS2clouds)
                  .select(['B4', 'B3', 'B2']);
                  
  var mosaic = exportdataset.mosaic();
  
  Export.image.toDrive({
    
    
      image:mosaic,
      description:'njimg',
      scale:10,
      maxPixels: 1e13,
      region:district_geometry,
      fileFormat: 'GeoTIFF',
      formatOptions: {
    
    
        cloudOptimized: true
      }
    });

Click run on the Task panel on the right to start the download task:
Insert picture description here
Note: If the data is too large, you can adjust it to a certain extent through the maxPixels parameter; but if it still exceeds the limit, you may need to consider downloading the SHP data partition based on the small administrative division.

Guess you like

Origin blog.csdn.net/suntongxue100/article/details/113374742