Google Earth Engine(GEE)实例代码学习二十八——绘制波谱响应曲线(Image Spectral)

本文主要分享如何绘制某像元的光谱曲线,以两种形式表达,第一个为x轴表示各波段,第二个为x为波长,表示为光谱相应曲线

//选取Landsat8 大气顶层反射率影像
var landsat8Toa = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');

var COLOR = {
  PARK: 'ff0000',//红色
  FARM: '0000ff',//蓝色
  URBAN: '00ff00'//绿色
};

// 选择三个点要素
var park = ee.Feature(
    ee.Geometry.Point(-99.25260, 19.32235), {'label': 'park'});
var farm = ee.Feature(
    ee.Geometry.Point(-99.08992, 19.27868), {'label': 'farm'});
var urban = ee.Feature(
    ee.Geometry.Point(-99.21135, 19.31860), {'label': 'urban'});
//将三个点要素转为要素集
var mexicoPoints = ee.FeatureCollection([park, farm, urban]);
//用位筛选影像
landsat8Toa = landsat8Toa.filterBounds(mexicoPoints);
//选取检索出的第一幅影像
var mexicoImage = ee.Image(landsat8Toa.first());
// 选择影像1-7波段
mexicoImage = mexicoImage.select(['B[1-7]']);

//绘制反射率曲线,设置图表内容
var bandChart = ui.Chart.image.regions({
  image: mexicoImage,
  regions: mexicoPoints,
  scale: 30,                //表示像元分辨率                   
  seriesProperty: 'label'   //设置图例名称
});
//设置图标类型为折线图
bandChart.setChartType('LineChart');
//设置图标属性,标题名,坐标轴名,线宽点大小,线颜色
bandChart.setOptions({
  title: 'Landsat 8 TOA band values at three points near Mexico City',
  hAxis: {
    title: 'Band'
  },
  vAxis: {
    title: 'Reflectance'
  },
  lineWidth: 1,
  pointSize: 4,
  series: {
    0: {color: COLOR.PARK},
    1: {color: COLOR.FARM},
    2: {color: COLOR.URBAN}
  }
});

// 设置点x轴间隔
var wavelengths = [.44, .48, .56, .65, .86, 1.61, 2.2];
//设置图标内容
var spectraChart = ui.Chart.image.regions({
  image: mexicoImage,
  regions: mexicoPoints,
  scale: 30,
  seriesProperty: 'label',
  xLabels: wavelengths
});
spectraChart.setChartType('LineChart');
spectraChart.setOptions({
  title: 'Landsat 8 TOA spectra at three points near Mexico City',
  hAxis: {
    title: 'Wavelength (micrometers)'
  },
  vAxis: {
    title: 'Reflectance'
  },
  lineWidth: 1,
  pointSize: 4,
  series: {
    0: {color: COLOR.PARK},
    1: {color: COLOR.FARM},
    2: {color: COLOR.URBAN}
  }
});
//图表,影像显示
print(bandChart);
print(spectraChart);
Map.addLayer(park, {color: COLOR.PARK});
Map.addLayer(farm, {color: COLOR.FARM});
Map.addLayer(urban, {color: COLOR.URBAN});
Map.setCenter(-99.25260, 19.32235, 11);

代码运行结果
Google Earth Engine(GEE)实例代码学习二十八——绘制波谱响应曲线(Image Spectral)_第1张图片

你可能感兴趣的:(GEE实例代码学习)