A simple tutorial to download Sentinel-2 images over a specific administrative area using Google Earth Engine platform.
The tutorial is for: new users of GEE, and want to extract Sentinel-2 (or any others) time series over a certain region. There are many useful repositories on github.com to download remote sensing images on GEE, such as
But as far as I know, none of them are designed for the purpose as this tutorial.
The first step is to generate a shape file of your ROIs, which can be in various format, such as .shp. There are many ways to do it. One of the ways (that I used) is downloading via DIVA-GIS.
- download the shape files from DIVA-GIS website.
- Load the shape file in QGIS, select the small ROI (eg. 'Bayern, Germany') and save to a shp. file.
It is suggested to read some guidelines for the new users of GEE before continuing read this tutorial. Some recommandations:
- https://www.google.com/earth/outreach/learn/introduction-to-google-earth-engine/
- https://blog.csdn.net/qq_22865459/article/details/80614822
Then, upload your shape file (in step 1) to GEE Assets. And create a new project and script.
Note: to access to GEE, you need an account; to save the downloaded data, you need a Google drive account.
This tutorial is based on the one posted at https://zhuanlan.zhihu.com/p/366744507.
Step a: load the shape file
var roi = ee.FeatureCollection("projects/bayernforest/assets/bayern");
Step b: load the necessary functions
var batch = require('users/fitoprincipe/geetools:batch')
var GuanMethod = require("users/GHX/share:function_Library.js")
Step c: mask-out clouds
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)
.set('system:time_start', image.get('system:time_start'));
}
Step d: collect Sentinel-2 data
var dataset = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')
.filterDate('2020-08-01', '2020-08-30')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',5))
.map(maskS2clouds)
.filterBounds(roi);
You can change the date range that you want to get a mosaic of Sentinel-2 image over the ROI.
Set the CLOUDY_PIXEL_PERCENTAGE
as the rate of cloud coverage.
Step e: save the data to your Google drive folder
Export.image.toDrive({
image: dataset.mean(),
description: 'bayern-2015-5-8',
folder: 'bayern-forest/2015-5-8',
scale: 10,
region: roi,
maxPixels:34e10
});