TP3
Exercice 1
// Objectif: Familiarisation avec l'interface et visualisation simple
var point = [Link]([-6.8498, 33.9716]); // Rabat
var buffer = [Link](20000);
// Afficher une image Sentinel-2
var s2 = [Link]('COPERNICUS/S2_SR_HARMONIZED')
.filterBounds(buffer)
.filterDate('2023-01-01', '2023-12-31')
.filter([Link]('CLOUDY_PIXEL_PERCENTAGE', 20))
.median();
[Link](buffer, 10);
[Link](s2, {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000}, 'RGB');
Exercice 2
// Objectif: Calcul et visualisation d'indices spectraux
function calculateIndices(image) {
var ndvi = [Link](['B8', 'B4']).rename('NDVI');
return [Link]([ndvi]);
var imageWithIndices = calculateIndices(s2);
// Visualisation des indices
var ndviVis = {min: -1, max: 1, palette: ['red', 'yellow', 'green']};
[Link]([Link]('NDVI'), ndviVis, 'NDVI');
Exercice 3 Analyse de series temporelles
// Objectif: Analyse de séries temporelles
function getNDVITimeSeries() {
return [Link]('COPERNICUS/S2_SR_HARMONIZED')
.filterBounds(buffer)
.filterDate('2023-01-01', '2023-12-31')
.map(function(image) {
var ndvi = [Link](['B8', 'B4']).rename('NDVI');
return [Link]('system:time_start', [Link]('system:time_start'));
});
var chart = [Link]({
imageCollection: getNDVITimeSeries(),
region: buffer,
reducer: [Link](),
scale: 30
});
print(chart);
//Multisources
// EXERCICE : ANALYSE MULTI-SOURCE DE LA TEMPÉRATURE ET FACTEURS
ENVIRONNEMENTAUX
// Objectif : Analyser les variations de température en fonction de différents facteurs
// 1. Définition de la zone d'étude
var cityCenter = [Link]([-7.6166, 33.5933]); // Casablanca
var studyArea = [Link](25000);
// 2. Fonction pour obtenir les données de température MODIS
function getMODISTemperature(startDate, endDate) {
return [Link]('MODIS/061/MOD11A2')
.filterDate(startDate, endDate)
.filterBounds(studyArea)
.select('LST_Day_1km')
.map(function(image) {
return [Link](0.02).subtract(273.15); // Conversion en Celsius
})
.median();
// 3. Fonction pour obtenir les données Landsat
function getLandsatData(startDate, endDate) {
return [Link]('LANDSAT/LC08/C02/T1_L2')
.filterDate(startDate, endDate)
.filterBounds(studyArea)
.filter([Link]('CLOUD_COVER', 20))
.map(function(image) {
// Indices spectraux
var ndvi = [Link](['SR_B5', 'SR_B4']).rename('NDVI');
var ndbi = [Link](['SR_B6', 'SR_B5']).rename('NDBI');
// Température de surface
var lst = [Link]('ST_B10')
.multiply(0.00341802)
.add(149.0)
.subtract(273.15)
.rename('LST');
return [Link]([ndvi, ndbi, lst]);
})
.median();
// 4. Obtenir les données d'élévation
var elevation = [Link]('USGS/SRTMGL1_003').clip(studyArea);
var slope = [Link](elevation);
var aspect = [Link](elevation);
// 5. Obtenir les données pour les saisons
var summerData = getLandsatData('2023-06-01', '2023-08-31');
var winterData = getLandsatData('2023-12-01', '2024-02-28');
var summerTemp = getMODISTemperature('2023-06-01', '2023-08-31');
var winterTemp = getMODISTemperature('2023-12-01', '2024-02-28');
// 6. Calculer les différences saisonnières
var tempDifference = [Link](winterTemp).rename('temp_diff');
// 7. Création d'une grille d'analyse
var grid = [Link]([Link]('EPSG:4326'), 1000);
// 8. Fonction pour l'analyse des points chauds
function getHotSpots(tempImage) {
var neighborhoodMean = [Link]({
reducer: [Link](),
kernel: [Link](3),
});
var neighborhoodStdDev = [Link]({
reducer: [Link](),
kernel: [Link](3),
});
var zScore = [Link](neighborhoodMean)
.divide(neighborhoodStdDev);
return [Link](2);
// 9. Analyse des facteurs environnementaux
var environmentalFactors = [Link]([
[Link]('elevation'),
[Link]('slope'),
[Link]('aspect'),
[Link]('NDVI'),
[Link]('NDBI'),
[Link]('LST')
]);
// 10. Visualisation
[Link](studyArea, 11);
// Palettes de couleurs
var tempVis = {
min: 20,
max: 45,
palette: ['blue', 'yellow', 'orange', 'red']
};
var diffVis = {
min: -10,
max: 10,
palette: ['blue', 'white', 'red']
};
// Ajouter les couches
[Link]([Link]('LST'), tempVis, 'Température été');
[Link]([Link]('LST'), tempVis, 'Température hiver');
[Link](tempDifference, diffVis, 'Différence de température');
[Link](getHotSpots([Link]('LST')),
{palette: ['yellow', 'red']}, 'Points chauds');
// 11. Analyse statistique par grille
var gridStats = [Link]({
collection: grid,
reducer: [Link](),
scale: 30
});
// 12. Création de graphiques
var tempElevationChart = [Link]({
image: [Link](['LST', 'elevation']),
reducer: [Link](),
scale: 30
});
[Link]({
title: 'Température vs Élévation',
hAxis: {title: 'Élévation (m)'},
vAxis: {title: 'Température (°C)'},
pointSize: 3
});
print(tempElevationChart);
// 13. Export des résultats
[Link]({
collection: gridStats,
description: 'Temperature_Analysis_Grid',
fileFormat: 'CSV'
});
[Link]({
image: environmentalFactors,
description: 'Temperature_Analysis_Raster',
scale: 30,
region: studyArea,
maxPixels: 1e9
});