特色:GEE绘制图例、提取像元值、反演模型与GEE的融合。
该结果为洱海地区叶绿素水质反演结果,利用GEE ui绘制了图例,屏蔽了影像图层即增加了白色底图,提取监测点位像元值并输出CSV,代码部分注释掉了输出像元值,取消注释即可。可供参考
var p280 = ee.Geometry.Point([100.16,25.86])
var p281 = ee.Geometry.Point([100.19,25.83])
var p283 = ee.Geometry.Point([100.21,25.70])
var p284 = ee.Geometry.Point([100.21,25.71])
var p285 = ee.Geometry.Point([100.25,25.71])
var p287 = ee.Geometry.Point([100.24,25.61])
var p288 = ee.Geometry.Point([100.27,25.65])
var p631 = ee.Geometry.Point([100.13,25.91])
var p632 = ee.Geometry.Point([100.14,25.92])
var p633 = ee.Geometry.Point([100.19,25.91])
var pts = ee.FeatureCollection(ee.List([
ee.Feature(p280).set('name','p280'),
ee.Feature(p281).set('name','p281'),
ee.Feature(p283).set('name','p283'),
ee.Feature(p284).set('name','p284'),
ee.Feature(p285).set('name','p285'),
ee.Feature(p287).set('name','p287'),
ee.Feature(p288).set('name','p288'),
ee.Feature(p631).set('name','p631'),
ee.Feature(p632).set('name','p632'),
ee.Feature(p633).set('name','p633'),]))
/**
* Function to mask clouds based on the pixel_qa band of Landsat 8 SR data.
* @param {ee.Image} image input Landsat 8 SR image
* @return {ee.Image} cloudmasked Landsat 8 image
*/
function maskL8sr(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = (1 << 3);
var cloudsBitMask = (1 << 5);
// Get the pixel QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return image.updateMask(mask);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
//根据反演模型提取chl_a
var addVariables = function(image){
var chl_a = image.expression(
'(0.06*RED+0.00638)/10000',{
RED:image.select('B4'),
}).float().rename('CHL_A')
return image.addBands(chl_a);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2020-01-01', '2020-01-31')
.filterBounds(table)
.map(maskL8sr)
.map(addVariables)
.mosaic()
.clip(table);
var visParams = {bands: ['B4', 'B3', 'B2'],min: 0,max: 3000,gamma: 1.4,};
print(dataset);
Map.centerObject(geometry, 24);
var china = table3;
var image_reduced = china.reduceToImage(['value'], 'mean');
//显示图像
var dataset1 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2020-01-01', '2020-01-25')
Map.addLayer(dataset1.select('B1'), {min: 0,max: 1,palette: ['FFFFFF']},'底色');
Map.addLayer(dataset.clip(table), visParams);
var visParams_chl = {min: -0.8, max: 0.8, palette: ['00FF00', '99FF99', '0000CC', '66FF66', '0099FF', 'FF6600', '3366FF']};
Map.addLayer(dataset.select('CHL_A'),visParams_chl,'CHL_A');
var Etiquetas = [
'0.000 - 0.001 mg/L',
'0.001 - 0.002 mg/L',
'0.002 - 0.004 mg/L',
'0.004 - 0.006 mg/L',
'0.006 - 0.008 mg/L',
'0.008 - 0.009 mg/L',
'0.009 - 0.010 mg/L',];
var Titulo = ui.Label({
value: 'chl_a浓度分级图', // 图例标签
style: {fontWeight: 'bold', fontSize: '18px', margin: '0px 0px 13px 0px',}}); // Estilo y dimensiones
var Leyenda = ui.Panel({
style: {position: 'bottom-left', padding: '10px 20px'}}); // Posicion, altura y anchura
Leyenda.add(Titulo);
var Simbologia = ['00FF00', '99FF99', '0000CC', '66FF66', '0099FF', 'FF6600', '3366FF'];
var Simbolos = function(simbolo, texto) {
var TextoLeyenda = ui.Label({
value: texto,
style: {margin: '5px 0px 8px 12px'}}); // Posicion en la separacion de los textos
var CajaLeyenda = ui.Label({
style: {backgroundColor: '#' + simbolo,
padding: '15px', // Tama帽o del simbolo
margin: '0px 0px 5px 0px'}}); // Posicion en la separacion de los simbolos
return ui.Panel({
widgets: [CajaLeyenda, TextoLeyenda],
layout: ui.Panel.Layout.Flow('horizontal')});};
for (var i = 0; i < 7; i++) {Leyenda.add(Simbolos(Simbologia[i], Etiquetas[i]));}
//Map.centerObject (SRTM90, 2);
Map.add(Leyenda);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
//提取监测点像元值
/*
var ft = ee.FeatureCollection(ee.List([]))
var fill = function(img, ini) {
// type cast
var inift = ee.FeatureCollection(ini)
// gets the values for the points in the current img
var ft2 = img.reduceRegions(pts, ee.Reducer.first(),30)
// gets the date of the img
var date = img.date().format()
// var name = img.name().format()
// writes the date in each feature
var ft3 = ft2.map(function(f){return f.set("date", date)})
// var ft3 = ft2.map(function(f){return f.set("name", name)})
// merges the FeatureCollections
return inift.merge(ft3)
}
// Iterates over the ImageCollection
var newft = ee.FeatureCollection(dataset.iterate(fill, ft))
Export.table.toDrive({
collection: newft,
description: 'sample_get',
fileFormat: 'CSV'
});
*/
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//