-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path🟢 Sentinel-2A -- View, Filter & Download
73 lines (53 loc) · 2.17 KB
/
🟢 Sentinel-2A -- View, Filter & Download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* ========================= NOTE ==================================
This code considers that you have understood the basics of uploading your vector/shapefile into your 'Asset' folder
in your Google Earth Engine account. Example as shown below. The example uses a shapefile by the name 'daro'
===================================================================
*/
// This code is to pan the map to go to your area of interest
// Map.setCenter(111.41, 2.54);
//0. Conversion of shape table into feature collection
var daro_ply = ee.FeatureCollection(daro).geometry();
/** This is a function to mask out the clouds. Nothing serious, comes with the whole package if you import the image from the dataset page
* Function to mask clouds using the Sentinel-2 QA Band
* @param {ee.Image} image Sentinel-2 image
* @return {ee.Image} cloud masked Sentinel-2 image
*/
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);
}
// 1. Load Sentinel-2
var s2_col = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
.filterDate('2023-01-01', '2023-12-31')
.filterBounds(daro_ply)
.sort('CLOUD_PIXEL_PERCENTAGE')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 25))
.map(maskS2clouds);
print(s2_col) // Check out the collection at the 'Console' panel
// 2. Set visualization parameter
var visParamsTrue = {
bands: ['B4', 'B3', 'B2'],
min:0.0,
max:0.15,
gamma:0.9
};
//3. Mosaic to combine the different contiguous image
var mosaik = s2_col.mosaic().clip(daro_ply);
print(mosaik);
Map.addLayer(mosaik, visParamsTrue, 'Mosaic');
/* DELETE THIS LINE IF YOU WANT TO EXPORT THE IMAGE OUT WHEN YOU CLICK 'RUN'
// 3. Exporting Sentinel 2 images
Export.image.toDrive({
image: mosaik,
description: 'Sentinel2_2023_Daro',
scale: 10,
region: daro_ply,
maxPixels: 1e13
});
DELETE THIS LINE IF YOU WANT TO EXPORT THE IMAGE OUT WHEN YOU CLICK 'RUN' */