Google Earth Engine(GEE)——在线面板实现NDVI值(点)的获取!

简介: Google Earth Engine(GEE)——在线面板实现NDVI值(点)的获取!

如果您在小部件中使用地球引擎结果(例如减少的数字输出),您将需要从服务器获取值。(有关地球引擎中客户端与服务器的详细信息,请参阅 此页面)。为了避免在计算该值时挂起整个 UI,您可以使用该evaluate()函数异步获取该值。该evaluate()函数开始请求一个值,当该值准备好时调用一个回调函数来处理结果。例如,考虑一个应用程序来获取 NDVI 时间序列在某个点的平均值:

函数:


evaluate(callback)

从服务器异步检索此对象的值并将其传递给提供的回调函数。

Asynchronously retrieves the value of this object from the server and passes it to the provided callback function.


Arguments:

参数:

这个:计算对象(ComputedObject): ComputedObject 实例。

回调(功能): 形式为 function(success, failure) 的函数,在服务器返回答案时调用。如果请求成功,则成功参数包含评估结果。如果请求失败,则失败参数将包含错误消息。

this:computedobject (ComputedObject):

The ComputedObject instance.

callback (Function):

A function of the form function(success, failure), called when the server returns an answer. If the request succeeded, the success argument contains the evaluated result. If the request failed, the failure argument will contains an error message.


widgets()

返回面板中当前的小部件列表。返回面板中的列表

Returns the list of widgets currently in the panel.


Arguments:

ui.panel(ui.Panel):
ui.Panel 实例。

this:ui.panel (ui.Panel):

The ui.Panel instance.


Returns: ui.data.ActiveList<ui.Widget>

代码:

// 加载 NDVI 影像
var ndvi = ee.ImageCollection('LANDSAT/LC8_L1T_8DAY_NDVI')
    .filterDate('2014-01-01', '2015-01-01');
var vis = {min: 0, max: 1, palette: ['99c199', '006400']};
Map.addLayer(ndvi.median(), vis, 'NDVI');
// 配置地图
Map.setCenter(-94.84497, 39.01918, 8);
Map.style().set('cursor', 'crosshair');
// 创建一个面板并将其添加到地图中
var inspector = ui.Panel([ui.Label('Click to get mean NDVI')]);
Map.add(inspector);
Map.onClick(function(coords) {
  // 显示加载标签。
  inspector.widgets().set(0, ui.Label({
    value: 'Loading...',
    style: {color: 'gray'}
  }));
  // 确定平均 NDVI,一个长期运行的服务器操作。
  var point = ee.Geometry.Point(coords.lon, coords.lat);
  var meanNdvi = ndvi.reduce('mean');
  var sample = meanNdvi.sample(point, 30);
  var computedValue = sample.first().get('NDVI_mean');
  // 从服务器请求值。
  computedValue.evaluate(function(result) {
    // 当服务器返回值时,显示它。
    inspector.widgets().set(0, ui.Label({
      value: 'Mean NDVI: ' + result.toFixed(2),
    }));
  });
});


代码中有一个需要说明的:result.toFixed(3),这里指的就是你的ndvi值显示的小数位数

最终结果:


相关文章
|
4月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
1942 1
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
4月前
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
193 0
|
4月前
|
存储 编解码 数据可视化
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
【2月更文挑战第14天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,按照给定的地表分类数据,对每一种不同的地物类型,分别加以全球范围内随机抽样点自动批量选取的方法~
424 1
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
|
4月前
|
API Go 网络架构
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
241 4
|
4月前
|
机器学习/深度学习 存储 人工智能
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
GEE Colab——初学者福音快速入门 Google Colab(Colaboratory)
202 3
|
4月前
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
71 0
|
4月前
|
编解码 人工智能 数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
100 0
|
4月前
|
编解码
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
59 0
|
4月前
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
174 0
|
4月前
|
传感器 编解码 数据处理
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
88 0

热门文章

最新文章