GEE 图表——sentinel-2和Landsat-8 影像各波段的图表展示和对比
简介
GEE 图表——sentinel-2和Landsat-8 影像各波段的图表展示和对比
函数
ui.Chart.image.regions(image, regions, reducer, scale, seriesProperty, xLabels)
Generates a Chart from an image. Extracts and plots the value of each band in one or more regions.
从图像中生成图表。提取并绘制一个或多个区域中每个波段的值。
-
X-axis = Band labeled by xProperty (default: band name).
-
Y-axis = Reducer output.
-
Series = Region labeled by seriesProperty (default: 'system:index').
Returns a chart.
Arguments:
image (Image):
Image to extract band values from.
regions (Feature|FeatureCollection|Geometry|List<Feature>|List<Geometry>, optional):
Regions to reduce. Defaults to the image's footprint.
reducer (Reducer, optional):
Reducer that generates the value(s) for the y-axis. Must return a single value per band.
scale (Number, optional):
The pixel scale in meters.
seriesProperty (String, optional):
Property to be used as the label for each region in the legend. Defaults to 'system:index'.
xLabels (List<Object>, optional):
A list of labels used for bands on the x-axis. Must have the same number of elements as the image bands. If omitted, bands will be labeled with their names. If the labels are numeric (e.g. wavelengths), x-axis will be continuous.
Returns: ui.Chart
setChartType(chartType)
Sets the chartType of this chart.
Returns this chart.
Arguments:
this:ui.chart (ui.Chart):
The ui.Chart instance.
chartType (String):
The chart type; e.g 'ScatterChart', 'LineChart', and 'ColumnChart'. For the complete list of charts, see: https://developers.google.com/chart/interactive/docs/gallery
Returns: ui.Chart
setOptions(options)
Sets options used to style this chart.
Returns this chart.
Arguments:
this:ui.chart (ui.Chart):
The ui.Chart instance.
options (Object):
An object defining chart style options such as:
title (string) The title of the chart. |
colors (Array) An array of colors used to draw the chart. |
Its format should follow the Google Visualization API's options: https://developers.google.com/chart/interactive/docs/customizing_charts
Returns: ui.Chart
代码
/*** 利用哨兵-2 展示光谱特征* 使用哨兵-2 QA 波段屏蔽云层的功能* 参数 {ee.Image} 图像 圣天诺-2 图像* 返回 {ee.Image} 云遮蔽的哨兵-2 图像*/var water = /* color: #0b0dd6 */ee.Geometry.Point([-105.14670897556627, 40.52974114741079]),vegetation = /* color: #5f9f00 */ee.Geometry.Point([-105.1499286288265, 40.56408842507554]),builtUp = /* color: #660404 */ee.Geometry.Point([-105.0799766177181, 40.571912420808935]);var dateStart = '2020-05-01'
var dateEnd = '2020-06-01'
Map.setCenter(-105.0381, 40.5538, 12); //centers on Fort Collins, COfunction maskS2clouds(image) {var qa = image.select('QA60');// Bits 10 and 11 are clouds and cirrus, respectively.var cloudBitMask = 1 << 10;var cirrusBitMask = 1 << 11;// Both flags should be set to zero, indicating clear conditions.var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(qa.bitwiseAnd(cirrusBitMask).eq(0));return image.updateMask(mask).divide(10000);
}var s2 = ee.ImageCollection('COPERNICUS/S2_SR').filterDate(dateStart, dateEnd)// Pre-filter to get less cloudy granules..filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20)).map(maskS2clouds);var visualization = {min: 0.0,max: 0.3,bands: ['B4', 'B3', 'B2'],
};var COLOR = {WATER: '0b0dd6',VEG: '5f9f00',BUILT: '660404'
};// 绘制光谱特征图
// 三个已知位置。
var fWater = ee.Feature(water, {'label': 'water'});
var fVegetation = ee.Feature(vegetation, {'label': 'veg.'});
var fBuiltUp = ee.Feature(builtUp, {'label': 'built-up'});var LCpoints = ee.FeatureCollection([fWater, fVegetation, fBuiltUp]);
var s2ic = s2.filterBounds(LCpoints)
var s2image = s2ic.mean()var s2image = s2image.select(['B2','B3','B4','B5','B6','B7','B8'])
var bandChart = ui.Chart.image.regions({image: s2image,regions: LCpoints,scale: 10,seriesProperty: 'label'
});
bandChart.setChartType('LineChart');
bandChart.setOptions({title: 'Sentinel-2 TOA band values near Fort Collins, CO',hAxis: {title: 'Band'},vAxis: {title: 'Reflectance'},lineWidth: 2,pointSize: 6,series: {0: {color: COLOR.WATER},1: {color: COLOR.VEG},2: {color: COLOR.BUILT}}
});var wavelengths = [.458, .543, .650, .698, .733, .773, .785];var spectraChart = ui.Chart.image.regions({image: s2image,regions: LCpoints,scale: 30,seriesProperty: 'label',xLabels: wavelengths
});
spectraChart.setChartType('LineChart');
spectraChart.setOptions({title: 'Landsat 8 TOA spectra near Fort Collins, CO',hAxis: {title: 'Wavelength (micrometers)'},vAxis: {title: 'Reflectance'},lineWidth: 2,pointSize: 6,series: {0: {color: COLOR.WATER},1: {color: COLOR.VEG},2: {color: COLOR.BUILT} }
});Map.addLayer(s2image)
print(bandChart);
print(spectraChart);