-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lagos.js
74 lines (63 loc) · 2.94 KB
/
Lagos.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
// Define the area of interest (AOI) around Lagos, Nigeria
var customBounds = ee.Geometry.Polygon(
[[
[3.271448, 6.330422], // southwest corner
[3.541448, 6.330422], // southeast corner
[3.541448, 6.600422], // northeast corner
[3.271448, 6.600422] // northwest corner
]]
);
// Add the AOI to the map
Map.addLayer(customBounds, {color: 'red'}, 'Custom Bounds');
Map.centerObject(customBounds, 10); // Adjust zoom level if necessary
// Define the date range and the list of years
var startYear = 2014;
var endYear = 2024;
var years = ee.List.sequence(startYear, endYear);
// Access the Landsat 8 Surface Reflectance dataset
var dataset = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterBounds(customBounds)
.sort('CLOUDY_PIXEL_PERCENTAGE');
// Function to export bands for each year
var exportBandsForYear = function(year) {
var yearStr = ee.Number(year).format('%04d');
var startDate = ee.Date.fromYMD(year, 1, 1);
var endDate = ee.Date.fromYMD(year, 12, 31);
// Filter dataset for the specific year
var yearlyData = dataset.filterDate(startDate, endDate).first();
// Check if an image exists for that year
if (yearlyData) {
var bands = yearlyData.select(['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7']);
// Define visualization parameters for debugging
var visParams = {
min: 0,
max: 0.3
};
// Display each band in the Earth Engine Code Editor with specific palettes
Map.addLayer(bands.select('SR_B2'), {min: 0, max: 0.3, palette: ['black', 'blue']}, 'Band 2 (Blue)');
Map.addLayer(bands.select('SR_B3'), {min: 0, max: 0.3, palette: ['black', 'green']}, 'Band 3 (Green)');
Map.addLayer(bands.select('SR_B4'), {min: 0, max: 0.3, palette: ['black', 'red']}, 'Band 4 (Red)');
Map.addLayer(bands.select('SR_B5'), {min: 0, max: 0.3, palette: ['black', 'gray']}, 'Band 5 (NIR)');
Map.addLayer(bands.select('SR_B6'), {min: 0, max: 0.3, palette: ['black', 'gray']}, 'Band 6 (SWIR1)');
Map.addLayer(bands.select('SR_B7'), {min: 0, max: 0.3, palette: ['black', 'gray']}, 'Band 7 (SWIR2)');
// Export each band separately with correct file name formatting
['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7'].forEach(function(band) {
Export.image.toDrive({
image: bands.select([band]),
description: 'Landsat8_Lagos_' + yearStr.getInfo() + '_' + band,
scale: 30,
region: customBounds,
fileNamePrefix: 'Landsat8_Lagos_' + yearStr.getInfo() + '_' + band,
formatOptions: {
cloudOptimized: true
}
});
});
}
};
// Apply the export function to each year
years.evaluate(function(yearList) {
yearList.forEach(function(year) {
exportBandsForYear(year);
});
});