【问题标题】:Include variable in plot title - Google Earth Engine在绘图标题中包含变量 - Google Earth Engine
【发布时间】:2018-08-01 20:24:53
【问题描述】:

有没有办法将变量包含在情节标题中?我希望我的标题取决于某个整数的值(此处取决于 iC_FC_size)。

var text = ee.String('Landsat Mission 4-8 - GEE image availability: ').cat(iC_FC_size)
var options1 = {
  title: 'Landsat Mission 4-8 - GEE image availability Suriname',
  hAxis: {title: 'Year'},
  vAxis: {title: 'Image count'},
  colors: ['red']
}; // options for plotting histogram
var histogram = ui.Chart.feature.histogram({
  features: iC_FC,
  property: 'year',
  minBucketWidth: 1
}).setOptions(options1);
var panel = ui.Panel({
      layout: ui.Panel.Layout.flow('vertical'),
      style: {position: 'bottom-right', height: '500px', width:'350px'}
    }); // create panel for plotting
    ui.root.add(panel);
    panel.widgets().set(0, histogram); // plot the histogram

想知道这是否可能?

问候!

【问题讨论】:

    标签: javascript google-earth-engine


    【解决方案1】:

    此脚本在图表上方的标题中包含一个变量:

    var ic = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR');
    
    var size= ic.size().getInfo();
    
    var some_title = 'How many LS5 scenes are there? Exactly ' + size+ ' scenes!';
    
    var some_chart = ui.Chart.array.values(ee.Array([1,5,6,8,6]), 0).setOptions({title: some_title});
    print(some_chart);
    

    “.getInfo()”方法将值从服务器端拉到客户端(即您的浏览器)。然后,您可以使用任何 Javascript 命令(例如,使用“+”)构建您想要的字符串作为标题。

    另一种方法是构建字符串服务器端,然后像这样拉它:

    var string_size = ee.String(ic.size());
    
    var some_title = ee.String('How many LS5 scenes are there? Exactly ').cat(string_size).cat(' scenes!').getInfo();
    

    【讨论】:

      【解决方案2】:

      要添加来自Bert Coerver 的答案: 如果您希望绘图标题中的变量是在 ImageCollection 中用作 ROI 的 FeatureCollection 中的多边形名称,您可以这样做:

      var fc = ee.FeatureCollection('ft:some fusion table containing multiple polygons')
          .filter(ee.Filter.eq('name', 'Suriname')); // Here I have already chosen my ROI
      
      // When you are ready to plot:
      var area_name = fc.aggregate_array('name').getInfo();
      var some_title = 'Name of area: ' + area_name;
      
      var some_chart = ui.Chart.array.values(ee.Array([1,5,6,8,6]), 0).setOptions({title: some_title});
      print(some_chart);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-09
        • 2023-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-20
        • 2020-05-20
        相关资源
        最近更新 更多