-
Notifications
You must be signed in to change notification settings - Fork 0
/
Download Image and ImageCollection
100 lines (73 loc) · 6.14 KB
/
Download Image and ImageCollection
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Download Image and ImageCollection in Google Earth Engine [ JavaScript API ]
// Organizer: Izaias de Souza Silva
// Date: 31-08-2023
// OBJECTIVE: demonstrate how to download Image and ImageCollection.
// The examples are demonstrated using MSI data (Sentinel-2).
// ==================================================================================================================================================================================
// Import your .shp data into the code or else draw it
// ==================================================================================================================================================================================
var study_area = geometry;
// ==================================================================================================================================================================================
// Center the Map on the study area, zoom 12
// ==================================================================================================================================================================================
Map.centerObject(study_area, 13);
// ==================================================================================================================================================================================
// View the study area on the Map
// ==================================================================================================================================================================================
Map.addLayer(study_area, {}, 'STUDY AREA');
// ==================================================================================================================================================================================
// Create a function to map clouds
// ==================================================================================================================================================================================
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)
.copyProperties(image, ['system:time_start']);
}
// ==================================================================================================================================================================================
// Access and import the OLI-Landsat 8 collection
// ==================================================================================================================================================================================
var S2 = ee.ImageCollection('COPERNICUS/S2') // Here is the collection.
.filterDate('2019-08-10','2019-08-31') // Filter to date.
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))// Filter to cloud cover.
.filterBounds(study_area) // Filter for images that touch the study area.
.map(maskS2clouds);
// ==================================================================================================================================================================================
// Access the MSI-Sentinel 2 collection metadate
// ==================================================================================================================================================================================
print('Quantas imagens foram encontradas?',S2.size());
print('Metadados da Coleção Sentinel 2:', S2);
// ==================================================================================================================================================================================
// Plot a specific image
// ==================================================================================================================================================================================
var imagem = ee.Image('COPERNICUS/S2/20190828T132239_20190828T132237_T23LKD');
Map.addLayer(imagem.clip(geometry),{bands: ['B4', 'B3', 'B2'], min: 529, max: 3058},'IMAGE CLIPED');
Map.addLayer(imagem,{bands: ['B4', 'B3', 'B2'], min: 529, max: 3058},'IMAGE', false);
// ==================================================================================================================================================================================
// Apply the reducer (.median) on collection and generate the compute
// ==================================================================================================================================================================================
var S2_median = S2.median();
var S2_median_cliped = S2.median().clip(study_area);
// ==================================================================================================================================================================================
// View the median image comput on the Map
// ==================================================================================================================================================================================
Map.addLayer(S2_median,{bands: ['B4', 'B3', 'B2'], min: 581, max: 2887},'MEDIAN IMAGE COMPUTATION', false);
Map.addLayer(S2_median_cliped,{bands: ['B4', 'B3', 'B2'], min: 581, max: 2887},'CLIPED MEDIAN IMAGE COMPUTATION', false);
// ==================================================================================================================================================================================
// Export the data you are interested in
// ==================================================================================================================================================================================
Export.image.toDrive({
image: S2_median_cliped,
description: 'S2',
scale: 10,
maxPixels: 1e13,
region: study_area,
crs: 'EPSG:31983',
folder: 'S2_DOWNLOAD'
});
// Thank you.