GEE平台下Sentinel-2遥感指数计算与分析指南

发布时间:2026/8/9 21:59:21
GEE平台下Sentinel-2遥感指数计算与分析指南 1. 项目概述GEE平台下的Sentinel-2遥感指数分析在遥感生态监测和农业应用中Sentinel-2卫星数据因其10-60米的空间分辨率和5天的重访周期成为地表观测的重要数据源。Google Earth EngineGEE平台为处理海量遥感数据提供了云端计算能力本教程将演示如何利用GEE计算Sentinel-2地表反射率SR数据的五大关键指数NDVI归一化差值植被指数、NDSI归一化差值雪指数、NDWI归一化差值水指数、NDMI归一化差值水分指数和NDGI归一化差值绿度指数并实现统计分析和数据下载的一站式解决方案。2. 数据准备与预处理2.1 Sentinel-2 SR数据特性Sentinel-2 Level-2A地表反射率产品已经过大气校正包含13个光谱波段。在GEE中对应的数据集为COPERNICUS/S2_SR主要波段包括B2, B3, B4, B8可见光与近红外B11, B12短波红外QA60云掩膜波段注意使用前需检查数据集的更新状态GEE会定期同步Copernicus Open Access Hub的最新数据2.2 研究区与时间范围设置// 示例定义河南省研究区和2022年时间范围 var roi ee.Geometry.Rectangle([110.5, 31.5, 116.5, 36.5]); var startDate 2022-01-01; var endDate 2022-12-31;2.3 数据过滤与云掩膜处理var s2 ee.ImageCollection(COPERNICUS/S2_SR) .filterBounds(roi) .filterDate(startDate, endDate) .filter(ee.Filter.lt(CLOUDY_PIXEL_PERCENTAGE, 20)) .map(function(image) { // 应用云掩膜 var qa image.select(QA60); var cloudBitMask 1 10; var cirrusBitMask 1 11; var mask qa.bitwiseAnd(cloudBitMask).eq(0) .and(qa.bitwiseAnd(cirrusBitMask).eq(0)); return image.updateMask(mask); });3. 遥感指数计算原理与实现3.1 各指数计算公式NDVI (B8 - B4) / (B8 B4)植被绿度指标范围[-1,1]健康植被通常0.6NDSI (B3 - B11) / (B3 B11)雪盖检测指标雪地通常0.4NDWI (B3 - B8) / (B3 B8)水体检测指标开阔水面0.2NDMI (B8 - B11) / (B8 B11)植被水分含量指标NDGI (B3 - B4) / (B3 B4)绿度敏感指标3.2 GEE实现代码// 定义指数计算函数 var calculateIndices function(image) { var ndvi image.normalizedDifference([B8, B4]).rename(NDVI); var ndsi image.normalizedDifference([B3, B11]).rename(NDSI); var ndwi image.normalizedDifference([B3, B8]).rename(NDWI); var ndmi image.normalizedDifference([B8, B11]).rename(NDMI); var ndgi image.normalizedDifference([B3, B4]).rename(NDGI); return image.addBands([ndvi, ndsi, ndwi, ndmi, ndgi]); }; // 应用到整个影像集合 var s2WithIndices s2.map(calculateIndices);4. 统计分析实现4.1 时间序列合成// 创建月度合成影像 var monthlyComposites ee.ImageCollection.fromImages( ee.List.sequence(1, 12).map(function(month) { return s2WithIndices.filter(ee.Filter.calendarRange(month, month, month)) .median() .set(month, month); }) );4.2 直方图与统计量计算// 定义统计区域可替换为特定地块 var statsRegion roi; // 计算年度统计 var annualStats monthlyComposites.reduce(ee.Reducer.mean()) .select([NDVI_mean,NDSI_mean,NDWI_mean,NDMI_mean,NDGI_mean]); // 获取统计值 var stats annualStats.reduceRegion({ reducer: ee.Reducer.minMax().combine({ reducer2: ee.Reducer.histogram(), sharedInputs: true }), geometry: statsRegion, scale: 100, maxPixels: 1e9 }); // 打印结果 print(Annual Statistics, stats);4.3 结果可视化// 直方图绘制 var histChart ui.Chart.feature.histogram({ features: ee.FeatureCollection([ee.Feature(null, stats)]), property: [NDVI_mean_histogram,NDSI_mean_histogram], minBucketWidth: 0.05 }).setOptions({ title: NDVI/NDSI Distribution, hAxis: {title: Index Value}, vAxis: {title: Pixel Count}, series: { 0: {color: green}, 1: {color: blue} } }); print(histChart); // 空间分布可视化 var visParams { bands: [NDVI], min: -0.2, max: 0.8, palette: [red, yellow, green] }; Map.addLayer(annualStats, visParams, NDVI Annual Mean);5. 数据导出与下载5.1 导出统计结果// 导出CSV表格 Export.table.toDrive({ collection: ee.FeatureCollection([ee.Feature(null, stats)]), description: AnnualIndicesStatistics, fileFormat: CSV }); // 导出直方图数据 var histData ee.FeatureCollection([ ee.Feature(null, { NDVI_hist: stats.get(NDVI_mean_histogram), NDSI_hist: stats.get(NDSI_mean_histogram) }) ]); Export.table.toDrive({ collection: histData, description: HistogramData, fileFormat: CSV });5.2 导出栅格数据// 导出年度合成影像 Export.image.toDrive({ image: annualStats, description: AnnualIndicesComposite, scale: 100, region: roi, maxPixels: 1e9, fileFormat: GeoTIFF, formatOptions: { cloudOptimized: true } }); // 导出月度时间序列 Export.image.toDrive({ image: monthlyComposites.toBands(), description: MonthlyIndicesSeries, scale: 100, region: roi, maxPixels: 1e9, fileFormat: GeoTIFF });6. 常见问题与优化技巧6.1 计算性能优化采样策略对大区域分析时先使用reduceResolution()降低计算分辨率var sampled image.reduceResolution({ reducer: ee.Reducer.mean(), maxPixels: 1024 }).reproject({crs: EPSG:4326, scale: 1000});分批处理年度数据可分季度处理后再合并var q1 s2.filterDate(2022-01-01, 2022-03-31).median(); var q2 s2.filterDate(2022-04-01, 2022-06-30).median(); // ...合并季度结果6.2 数据质量控制云覆盖结合SCL场景分类图进行更精确的云过滤var s2 ee.ImageCollection(COPERNICUS/S2_SR_HARMONIZED) .map(function(image) { var scl image.select(SCL); var cloudMask scl.neq(8).and(scl.neq(9)); // 8云中阴影,9云 return image.updateMask(cloudMask); });异常值处理添加指数值域约束var ndvi image.normalizedDifference([B8, B4]) .clamp(-1, 1) .rename(NDVI);6.3 高级分析扩展变化检测比较不同年份的指数差异var change ndvi2022.subtract(ndvi2021).rename(NDVI_change);阈值分类基于指数值进行土地覆盖分类var water ndwi.gt(0.2).selfMask().rename(water); var vegetation ndvi.gt(0.6).selfMask().rename(vegetation);时间序列分析使用ee.List.map()实现逐像元分析var trend ee.ImageCollection.fromImages( monthlyComposites.toList(12).map(function(img) { return ee.Image(img).select(NDVI); }) ).reduce(ee.Reducer.linearFit());实操经验在处理大区域数据时建议先在1000米尺度进行快速测试确认脚本无误后再全分辨率运行。GEE的scale参数对计算时间影响显著农业应用通常100米分辨率足够而森林监测可能需要20-30米分辨率