本文主要是介绍GEE24:合肥市1986-2024年年均NDVI变化分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码如下:
var roi = ee.FeatureCollection("users/yipeizhao736/HefeiProvince");
Map.centerObject(roi);
Map.addLayer(roi,{'color':'grey'},'roi');
// Applies scaling factors.
function applyScaleFactors(image) {var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);return image.addBands(opticalBands, null, true).addBands(thermalBands, null, true);
}
function rmCloudNew(image) {var cloudShadowBitMask = (1 << 4); var cloudsBitMask = (1 << 3); var qa = image.select('QA_PIXEL'); var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0) .and(qa.bitwiseAnd(cloudsBitMask).eq(0)); return image.updateMask(mask).copyProperties(image).copyProperties(image, ["system:time_start"]);
}
var get_NDVI = function(image) {var NDVI=image.normalizedDifference(['nir','red']).rename(['NDVI']);image=image.addBands(NDVI)return image.select("NDVI")
};
var L8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2').filterBounds(roi).filter(ee.Filter.calendarRange(2014,2023,'year')).filter(ee.Filter.calendarRange(1,12,'month')).map(applyScaleFactors).select(['SR_B4','SR_B5','QA_PIXEL'],['red','nir','QA_PIXEL']).map(rmCloudNew).map(get_NDVI);
var L7 = ee.ImageCollection('LANDSAT/LE07/C02/T1_L2').filterBounds(roi).filter(ee.Filter.calendarRange(2012,2013,'year')).filter(ee.Filter.calendarRange(1,12,'month')).map(applyScaleFactors).select(['SR_B3','SR_B4','QA_PIXEL'],['red','nir','QA_PIXEL']).map(rmCloudNew).map(get_NDVI);
var L5 = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2').filterBounds(roi).filter(ee.Filter.calendarRange(1986,2011,'year')).filter(ee.Filter.calendarRange(1,12,'month')).map(applyScaleFactors).select(['SR_B3','SR_B4','QA_PIXEL'],['red','nir','QA_PIXEL']).map(rmCloudNew).map(get_NDVI);
var Landsat = ee.ImageCollection(L8.merge(L7).merge(L5)).sort("system:time_start")
//print("Landsat_data",Landsat);
var precipitationVis = {min: -1,max: 1,palette: ["FFFFFF", "CE7E45", "DF923D", "F1B555", "FCD163", "99B718", "74A901", "66A000", "529400", "3E8601", "207401", "056201", "004C00", "023B01", "012E01", "011D01", "011301"],
};
for(var i = 1986;i<=2023;i++){var ndvi_year = Landsat.filterDate(i+'-01-01', i+'-12-31').select('NDVI')var ndvi_mean = ndvi_year.mean().clip(roi)//print(i,ndvi_mean)//Map.addLayer(ndvi_mean, precipitationVis, i+'_ndvi_mean',false);Export.image.toDrive({image: ndvi_mean,description: i+'year_mean',region: roi,scale: 30,maxPixels: 1e13,folder: 'NDVI_year'})
}
var years = ee.List.sequence(1986, 2023);
var collectYear = ee.ImageCollection(years.map(function(y) {var start = ee.Date.fromYMD(y, 1, 1);var end = start.advance(12,'month');return Landsat.filterDate(start, end).reduce(ee.Reducer.mean()).float().set('system:time_start',y).set('year',y);
}));
print(collectYear,"ndvi_year")
var result_land = collectYear.mean().clip(roi);
print(result_land,'ndvi_mean');
Map.addLayer(result_land, precipitationVis, 'ndvi_mean');
Export.image.toDrive({image: result_land,description: 'ndvi_mean',region: roi,scale: 30,maxPixels: 1e13,folder: 'NDVI_year'})
var Yearly_chart = ui.Chart.image.series({imageCollection: collectYear.select('NDVI_mean'),region: roi,reducer: ee.Reducer.mean(),scale: 500,xProperty: 'year',}).setOptions({interpolateNulls: true,lineWidth: 2,title: 'NDVI Yearly Seires',vAxis: {title: 'NDVI'},hAxis: {title: 'Date'},trendlines: { 0: {title: 'NDVI_trend',type:'linear', showR2: true, color:'red', visibleInLegend: true}}});
print(Yearly_chart);
研究区:
年均NDVI变化趋势:
GEE代码
这篇关于GEE24:合肥市1986-2024年年均NDVI变化分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!