-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgee.js
151 lines (109 loc) · 3.85 KB
/
gee.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var geometry =
/* color: #d63000 */
/* shown: false */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[88.23215756023906, 22.164375317717916],
[88.23215756023906, 21.47082196140555],
[89.12754330242656, 21.47082196140555],
[89.12754330242656, 22.164375317717916]]], null, false);
/// Geometry has been drawn
/// Define bands of interest here
var L8bands = ['B2','B3','B4']
var L7bands =['B3']
var L5bands = ['B3']
///////// Visualisation parameters
var L8vis = {
bands: L8bands,
min: 0,
max: 0.5,
};
var L7vis = {
bands: L7bands,
min: 0,
max: 0.5,
//gamma: [0.95, 1.1, 1]
};
var L5vis = {
bands: L5bands,
min: 0,
max: 0.5,
//gamma: [0.95, 1.1, 1]
};
//mask clouds
function maskLandsatclouds(image) {
var qa = image.select('BQA')
var cloudBitMask = ee.Number(2).pow(4).int()
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
return image.updateMask(mask)
.select("B.*")
.copyProperties(image, ["system:time_start"])
}
//Landsat 5 TM, available from 1984-2012
//1985-1986
var L5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_TOA")
.filterDate('1985-01-01', '1989-12-30') // you can change date here
.filter(ee.Filter.lt("CLOUD_COVER", 0.5))
.filterBounds(geometry)
.map(maskLandsatclouds)
.select(L5bands)
var mosaic_L5 = L5.median().clip(geometry); // here we are taking the median at each pixel in the collection
Map.addLayer(mosaic_L5, L5vis, "mosaic_L5")
//Landsat 7, available from 1999.
//Nb striping is due to the scan line corrector
// on the satellite failing, median compositor smooths that out but be aware
var L7 = ee.ImageCollection("LANDSAT/LE07/C01/T1_TOA")
.filterDate('2000-01-01', '2001-12-30') // you can change date here
.filter(ee.Filter.lt("CLOUD_COVER", 0.5))
.filterBounds(geometry)
.map(maskLandsatclouds)
.select(L7bands)
var mosaic_L7 = L7.median().clip(geometry); // here we are taking the median at each pixel in the collection
Map.addLayer(mosaic_L7, L7vis, "mosaic_L7")
//Landsat 8. Avalable from 2013
////2017-2018
var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
.filterDate('2019-01-01', '2020-01-01') // you can change date here
.filter(ee.Filter.lt("CLOUD_COVER", 0.5))
.filterBounds(geometry)
.map(maskLandsatclouds)
.select(L8bands)
var best = ee.Image(L5.sort('CLOUD_COVER').first());
//print('Least Cloudy Image is ', best);
//get specific metadata from image
var date_taken = best.get('DATE_ACQUIRED');
print('Date taken is', date_taken);
var mosaic_L8 = L8.median().clip(geometry); // here we are taking the median at each pixel in the collection
Map.addLayer(mosaic_L8, L8vis, "mosaic_L8")
Map.centerObject(geometry)
//Print the area of the selected mosaic
// Print polygon area in square kilometers
print('Polygon area in square km : ', geometry.area(10).divide(1000 * 1000));
// Print polygon perimeter length in kilometers.
print('Polygon perimeter: ', geometry.perimeter(10).divide(1000));
//// For Exporting mosaic images to drive
Export.image.toDrive({
image: mosaic_L5, /// To choose which imagery to export change the number (e.g. L5, L7 or L8)
description: 'L_RED_band', //give correct name
scale: 30,
maxPixels: 1e13,
region: geometry
});
Export.image.toDrive({
image: mosaic_L8, /// To choose which imagery to export change the number (e.g. L5, L7 or L8)
description: 'L7_RED_band', //give correct name
scale: 30,
maxPixels: 1e13,
region: geometry
});
Export.image.toDrive({
image: mosaic_L8, /// To choose which imagery to export change the number (e.g. L5, L7 or L8)
description: 'L8_RGB_new', //give correct name
scale: 30,
maxPixels: 1e13,
region: geometry
});