基于landsat8的NDVI时空演变规律
# 以武汉市为例,借助PIE-Engine平台基于landsat8遥感数据分析区域NDVI时空演变规律
# 一、背景介绍
植被归一化指数(NDVI)是反映植被生长状态和营养信息的重要参数之一,同时也可以根据NDVI进行诸多衍生计算,包括农作物类型的识别和面积计算,生态健康指数计算等。随着高精度遥感数据日益庞大,无论是存储还是算力,个人的硬件和软件条件都很难满足反演计算的需求,应用遥感云计算的手段对海量高精度遥感数据进行反演计算显得尤为重要。本应用基于武汉市2013-2020年的landsat8遥感影像数据产品,通过设置循环计算操作,一次性输出不同年份的NDVI反演的栅格图像,并利用反演结果分别提取NDVI的最小值、最大值、平均值和中位值,最后利用折线图以年份为横轴,以NDVI值为纵轴,结合NDVI空间地理分布栅格图直观反映武汉市NDVI的时空演变规律。
# 二、实现功能模块
# 三、PIE-Engine运行代码解析
PIE-Engine平台地址:遥感计算服务 (piesat.cn) (opens new window)
//武汉市矢量边界加载(用户可以根据个人需要限定自己所要进行NDVI反演的区域)
var roi = pie.FeatureCollection('NGCC/CHINA_CITY_BOUNDARY')
.filter(pie.Filter.eq("name", "武汉市"))
.first() //转化为对象
.geometry(); //转化为几何形状
//加载显示中国边界图
Map.addLayer(roi, {color:"ffff00ff", fillColor:"00000000"}, "调查区域");
//加载landsat8影像产品
var l8Col1 = pie.ImageCollection("LC08/01/T1");
for(var year = 2013; year<2021; year++ ){
var startDay = pie.Date.fromYMD(year,1,1);
var endDay = pie.Date.fromYMD(year,12,31);
l8Col = l8Col1.filterDate(startDay, endDay)
.select(["B4","B5"])
.filterBounds(roi)
.map(function(image){
var b4 = image.select("B4");
var b5 = image.select("B5");
var ndvi = (b5.subtract(b4)).divide(b5.add(b4));
return ndvi;
});
//对NDVI栅格文件按照限定范围进行裁剪
var ndvi_clip = l8Col.mosaic().clip(roi);
//NDVI地图展示,根据常规的NDVI展示效果设定NDVI相关展示参数
var visParamNDVI = {
min: -0.2,
max: 0.8,
palette: 'CA7A41, CE7E45, DF923D, F1B555, FCD163, 99B718, '+
'74A901, 66A000, 529400,3E8601, 207401, 056201, 004C00,'+
'023B01, 012E01, 011D01, 011301'
};
//NDVI地图展示
Map.addLayer(ndvi_clip, visParamNDVI,year+"NDVI");
Map.centerObject(roi, 5);
//导出NDVI栅格数据,根据时间序列分别命名区分
//NDVI栅格文件的批量导出并保存
Export.image({
image:ndvi_clip,
description:year+"_"+'ndvi',
region:roi,
crs:'WGS84',
scale:30,
});
};
//////////上面代码执行完毕并导出保存NDVI栅格文件成功后运行下面代码;计算NDVI的最小值、最大值、平均值和中位数值并通过折线图进行时间序列变化分析///////////
//加载上一模块中生成的不同年份NDVI栅格文件,并选择B1波段
var ndvi2013 = pie.Image('user/Allen666666/Landsat8_NDVI/2013_ndvi').select("B1");
var ndvi2014 = pie.Image('user/Allen666666/Landsat8_NDVI/2014_ndvi').select("B1");
var ndvi2015 = pie.Image('user/Allen666666/Landsat8_NDVI/2015_ndvi').select("B1");
var ndvi2016 = pie.Image('user/Allen666666/Landsat8_NDVI/2016_ndvi').select("B1");
var ndvi2017 = pie.Image('user/Allen666666/Landsat8_NDVI/2017_ndvi').select("B1");
var ndvi2018 = pie.Image('user/Allen666666/Landsat8_NDVI/2018_ndvi').select("B1");
var ndvi2019 = pie.Image('user/Allen666666/Landsat8_NDVI/2019_ndvi').select("B1");
var ndvi2020 = pie.Image('user/Allen666666/Landsat8_NDVI/2020_ndvi').select("B1");
//计算不同年份的NDVI区域最小值
var Min1 = ndvi2013.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
var Min2 = ndvi2014.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
var Min3 = ndvi2015.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
var Min4 = ndvi2016.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
var Min5 = ndvi2017.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
var Min6 = ndvi2018.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
var Min7 = ndvi2019.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
var Min8 = ndvi2020.reduceRegion(pie.Reducer.min(), roi,1e7).getNumber("B1");
//逐个输出不同年份最小值
print("Min1:");
print(Min1);
print("Min2:");
print(Min2);
print("Min3:");
print(Min3);
print("Min4:")
print(Min4);
print("Min5:")
print(Min5);
print("Min6:")
print(Min6);
print("Min7:")
print(Min7);
print("Min8:")
print(Min8);
//计算不同年份的NDVI区域最大值
var Max1 = ndvi2013.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
var Max2 = ndvi2014.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
var Max3 = ndvi2015.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
var Max4 = ndvi2016.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
var Max5 = ndvi2017.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
var Max6 = ndvi2018.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
var Max7 = ndvi2019.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
var Max8 = ndvi2020.reduceRegion(pie.Reducer.max(), roi,1e7).getNumber("B1");
//逐个输出不同年份最大值
print("Max1:");
print(Max1);
print("Max2:");
print(Max2);
print("Max3:");
print(Max3);
print("Max4:");
print(Max4);
print("Max5:");
print(Max5);
print("Max6:");
print(Max6);
print("Max7:");
print(Max7);
print("Max8:");
print(Max8);
//计算不同年份的NDVI区域平均值
var Mean1 = ndvi2013.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
var Mean2 = ndvi2014.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
var Mean3 = ndvi2015.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
var Mean4 = ndvi2016.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
var Mean5 = ndvi2017.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
var Mean6 = ndvi2018.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
var Mean7 = ndvi2019.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
var Mean8 = ndvi2020.reduceRegion(pie.Reducer.mean(), roi,1e7).getNumber("B1");
//逐个输出不同年份平均值
print("Mean1:");
print(Mean1);
print("Mean2:");
print(Mean2);
print("Mean3:");
print(Mean3);
print("Mean4:");
print(Mean4);
print("Mean5:");
print(Mean5);
print("Mean6:");
print(Mean6);
print("Mean7:");
print(Mean7);
print("Mean8:");
print(Mean8);
//计算不同年份的NDVI区域中位数
var Median1 = ndvi2013.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
var Median2 = ndvi2014.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
var Median3 = ndvi2015.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
var Median4 = ndvi2016.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
var Median5 = ndvi2017.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
var Median6 = ndvi2018.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
var Median7 = ndvi2019.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
var Median8 = ndvi2020.reduceRegion(pie.Reducer.median(), roi, 1e7).getNumber("B1");
//逐个输出不同年份平均值
print("Median1:");
print(Median1);
print("Median2:");
print(Median2);
print("Median3:");
print(Median3);
print("Median4:");
print(Median4);
print("Median5:");
print(Median5);
print("Median6:");
print(Median6);
print("Median7:");
print(Median7);
print("Median8:");
print(Median8);
//折线图的绘制
var line_options = {
title: 'NDVI年际变化规律',
legend:["NDVI_min","NDVI_max","NDVI_mean","NDVI_median"],
xAxis: ["2013", "2014", "2015", "2016", "2017", "2018","2019","2020"],
yAxisName: "NDVI value",
xAxisName: "年份",
series: [
[-0.16681776971894832,-0.2776735459662289,-0.32717190388170053,-0.12576312576312576,-0.23300970873786409,-0.13113651647612642,-0.18349135527049637,0.1084587441619097], [-0.01904761904761905,-0.06439393939393939,-0.2804232804232804,0.04090801607945141,-0.14733178654292342,0.11764705882352941,-0.07515657620041753,0.1084587441619097], [-0.09293269438328369,-0.17103374268008414,-0.30379759215249047,-0.042427554841837176,-0.19017074764039377,-0.006744728826298507,-0.12932396573545696,-0.0301703841652365], [-0.16681776971894832,-0.2776735459662289,-0.32717190388170053,-0.12576312576312576,-0.23300970873786409,-0.13113651647612642,-0.18349135527049637,-0.1687995124923827],
],
chartType: "line"
};
ChartArray(line_options);
结果:
外部链接共享代码:https://engine.piesat.cn/engine-share/shareCode.html?id=f698a97ed7e24472ae43d934ebb18fe8
有问题,我来改改 (opens new window)
上次更新: 2022/10/17, 19:07:36