-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathndvi_calculator.js
More file actions
168 lines (146 loc) · 5.75 KB
/
ndvi_calculator.js
File metadata and controls
168 lines (146 loc) · 5.75 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Script de Cálculo de NDVI (Normalized Difference Vegetation Index)
*
* Autor: Tássia Parada Sampaio
* Instituição: Universidade Federal de Pelotas (UFPEL)
* Curso: Engenharia Ambiental e Sanitária
* Data: 2023
*
* Descrição: Este script calcula o Índice de Vegetação por Diferença Normalizada (NDVI)
* usando imagens do Sentinel-2 para monitoramento da saúde da vegetação.
*
* Referência: Sampaio, T. P. (2023). Análise Automatizada da Severidade de
* Queimadas em Área de Banhado com índices de vegetação (NDVI e NBR) através
* de JavaScript: Um Estudo de Caso em Pelotas, RS.
*/
// ============================================================================
// DEFINIÇÃO DA REGIÃO DE INTERESSE (ROI)
// ============================================================================
// Pontal da Barra, Pelotas/RS - Coordenadas em WGS84
var roi = ee.Geometry.Polygon([
[-52.23242174143157, -31.78621134386096],
[-52.23242174143157, -31.78127497081573],
[-52.22064979507719, -31.78127497081573],
[-52.22064979507719, -31.78621134386096]
]);
// ============================================================================
// IMPORTAR IMAGENS DO SENTINEL-2
// ============================================================================
// Período: Novembro 2022 a Maio 2023
var collection = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(roi)
.filterDate('2022-11-01', '2023-05-31');
// ============================================================================
// FUNÇÃO PARA CALCULAR NDVI
// ============================================================================
/**
* Calcula o Índice de Vegetação por Diferença Normalizada (NDVI)
* Fórmula: NDVI = (NIR - RED) / (NIR + RED)
* Onde:
* - NIR (Near Infrared): Banda 8 do Sentinel-2
* - RED (Vermelho): Banda 4 do Sentinel-2
*
* Valores:
* - Próximo de 1: Vegetação densa e saudável
* - Próximo de 0: Rochas e solo descoberto
* - Próximo de -1: Água, nuvens e neve
*/
var calculateNDVI = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4'])
.rename('NDVI')
.clamp(-1, 1);
return image.addBands(ndvi);
};
// Mapear a função de cálculo de NDVI na coleção de imagens
var ndviCollection = collection.map(calculateNDVI);
// ============================================================================
// FUNÇÃO PARA VISUALIZAR IMAGEM
// ============================================================================
var visualizeImage = function(image) {
var ndvi = image.select('NDVI').visualize({
min: -1,
max: 1,
palette: ['red', 'yellow', 'green']
});
return ndvi;
};
// ============================================================================
// FILTRAR POR ANO E MÊS
// ============================================================================
var filteredCollection = ndviCollection
.filter(ee.Filter.calendarRange({
start: 2022,
end: 2023,
field: 'year'
}))
.filter(ee.Filter.calendarRange({
start: 11,
end: 5,
field: 'month'
}));
// ============================================================================
// CALCULAR MEDIANA E VISUALIZAR
// ============================================================================
var image = ee.Image(filteredCollection.median());
var visualization = visualizeImage(image);
// Adicionar a imagem à visualização do Mapa
Map.addLayer(visualization, {}, 'NDVI - Período Analisado');
Map.centerObject(roi, 16);
// ============================================================================
// CALCULAR ESTATÍSTICAS DO NDVI
// ============================================================================
var ndviStats = image.select('NDVI').reduceRegion({
reducer: ee.Reducer.mean(),
geometry: roi,
scale: 10
});
// Imprimir os valores do NDVI
print('Valores do NDVI (Média):', ndviStats.get('NDVI'));
// ============================================================================
// FUNÇÃO PARA CALCULAR NDVI MENSAL
// ============================================================================
/**
* Calcula a média mensal do NDVI para um período específico
*/
var calculateMonthlyNDVI = function(year, month) {
var startDate = ee.Date.fromYMD(year, month, 1);
var endDate = startDate.advance(1, 'month');
var monthlyCollection = ndviCollection
.filterDate(startDate, endDate);
var monthlyImage = monthlyCollection.mean();
var monthlyStats = monthlyImage.select('NDVI').reduceRegion({
reducer: ee.Reducer.mean(),
geometry: roi,
scale: 10
});
return monthlyStats.get('NDVI');
};
// ============================================================================
// INTERFACE DO USUÁRIO PARA SELEÇÃO MENSAL
// ============================================================================
var monthSelect = ui.Select({
items: ['11', '12', '01', '02', '03', '04', '05'],
onChange: function(month) {
var year = (parseInt(month, 10) === 1 || parseInt(month, 10) === 2) ? 2023 : 2022;
var monthlyNDVI = calculateMonthlyNDVI(year, parseInt(month, 10));
print('Média do NDVI para o mês ' + month + '/' + year + ':', monthlyNDVI.getInfo());
}
});
var panel = ui.Panel({
widgets: [
ui.Label('Selecione o mês para análise de NDVI:'),
monthSelect
],
style: {width: '250px', padding: '10px'}
});
ui.root.add(panel);
// ============================================================================
// INFORMAÇÕES TÉCNICAS
// ============================================================================
// Satélite: Sentinel-2A e Sentinel-2B
// Resolução Espacial: 10-60 metros
// Resolução Temporal: 5 dias
// Bandas Utilizadas: B4 (Vermelho) e B8 (NIR)
// Período de Análise: Novembro 2022 a Maio 2023
// Área de Estudo: Pontal da Barra, Pelotas/RS
// Bioma: Pampa (Banhado)