GEE专栏之水质反演 基于线下训练模型的在线叶绿素反演(叶绿素反演结果可视化、图例、白板底图、提取点位像元值并输出CSV)

GEE专栏之水质反演 基于线下训练模型的在线预测

效果图

特色: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'
});
*/
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//

  • 4
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吕波涛.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值