GEE(Google Earth Engine)——JavaScript 入门(3)

简介: GEE(Google Earth Engine)——JavaScript 入门(3)

波段计算

使用Image方法对图像进行数学运算。这可能包括波段重组(光谱指数)、图像差分或数学运算,例如乘以常数。例如,计算相隔 20 年的归一化差异植被指数 (NDVI) 图像之间的差异:


代码编辑器 (JavaScript)

// This function gets NDVI from Landsat 5 imagery.
var getNDVI = function(image) {
  return image.normalizedDifference(['B4', 'B3']);
};
// Load two Landsat 5 images, 20 years apart.
var image1 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_19900604');
var image2 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_044034_20100611');
// Compute NDVI from the scenes.
var ndvi1 = getNDVI(image1);
var ndvi2 = getNDVI(image2);
// Compute the difference in NDVI.
var ndviDifference = ndvi2.subtract(ndvi1);


请注意function本示例中定义的用户的使用。更多关于下一节的功能。


映射(做什么而不是 for 循环)


使用map()以遍历集合中的项目。(For 循环不是在 Earth Engine 中执行此操作的正确方法,应避免使用)。该map() 函数可以应用于 an ImageCollection、 a FeatureCollection或 aList并接受 afunction 作为其参数。函数的参数是它所映射的集合的一个元素。这对于以相同的方式修改集合的每个元素很有用,例如添加。例如,以下代码向 中的每个图像添加 NDVI 波段ImageCollection:


代码编辑器 (JavaScript)

// This function gets NDVI from Landsat 8 imagery.
var addNDVI = function(image) {
  return image.addBands(image.normalizedDifference(['B5', 'B4']));
};
// Load the Landsat 8 raw data, filter by location and date.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1')
  .filterBounds(ee.Geometry.Point(-122.262, 37.8719))
  .filterDate('2014-06-01', '2014-10-01');
// Map the function over the collection.
var ndviCollection = collection.map(addNDVI);


另一个常见任务是向 .csv 文件中的要素添加新属性(或“属性”或“字段”) FeatureCollection。在以下示例中,新属性是涉及两个现有属性的计算:


代码编辑器 (JavaScript)

// This function creates a new property that is the sum of two existing properties.
var addField = function(feature) {
  var sum = ee.Number(feature.get('property1')).add(feature.get('property2'));
  return feature.set({'sum': sum});
};
// Create a FeatureCollection from a list of Features.
var features = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(-122.4536, 37.7403),
    {property1: 100, property2: 100}),
    ee.Feature(ee.Geometry.Point(-118.2294, 34.039),
    {property1: 200, property2: 300}),
]);
// Map the function over the collection.
var featureCollection = features.map(addField);
// Print a selected property of one Feature.
print(featureCollection.first().get('sum'));
// Print the entire FeatureCollection.
print(featureCollection);


请注意将ee.Number属性值识别为数字以使用该add()方法所需的强制转换)。可以通过 更改集合的类型map()。例如:


代码编辑器 (JavaScript)

// This function creates a new property that is the sum of two existing properties.
var addField = function(feature) {
  var sum = ee.Number(feature.get('property1')).add(feature.get('property2'));
  return feature.set({'sum': sum});
};
// Create a FeatureCollection from a list of Features.
var features = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point(-122.4536, 37.7403),
    {property1: 100, property2: 100}),
    ee.Feature(ee.Geometry.Point(-118.2294, 34.039),
    {property1: 200, property2: 300}),
]);
// Map the function over the collection.
var featureCollection = features.map(addField);
// Print a selected property of one Feature.
print(featureCollection.first().get('sum'));
// Print the entire FeatureCollection.
print(featureCollection);


请注意foo为从图像质心创建的每个要素添加的属性 ( )。在最后一行中,演员表使生成的集合可识别为 FeatureCollection.


以上所有例子都可以在科学上网的情况下,完成直达,具体图像我就不展示了,希望对大家有帮助,更多资源可以点击资源查看。


相关文章
|
2月前
|
JavaScript 前端开发 C语言
javascript基础入门
javascript基础入门
24 1
|
3月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
551 0
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
3月前
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
106 0
|
1天前
|
存储 JavaScript 前端开发
【JavaScript技术专栏】JavaScript基础入门:变量、数据类型与运算符
【4月更文挑战第30天】本文介绍了JavaScript的基础知识,包括变量(var、let、const)、数据类型(Number、String、Boolean、Undefined、Null及Object、Array)和运算符(算术、赋值、比较、逻辑)。通过实例展示了如何声明变量、操作数据类型以及使用运算符执行数学和逻辑运算。了解这些基础知识对初学者至关重要,是进阶学习JavaScript的关键。
|
6天前
|
前端开发 JavaScript
前端 富文本编辑器原理——从javascript、html、css开始入门(二)
前端 富文本编辑器原理——从javascript、html、css开始入门
18 0
前端 富文本编辑器原理——从javascript、html、css开始入门(二)
|
6天前
|
前端开发 JavaScript 索引
前端 富文本编辑器原理——从javascript、html、css开始入门(一)
前端 富文本编辑器原理——从javascript、html、css开始入门
18 0
|
2月前
|
存储 编解码 数据可视化
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
【2月更文挑战第14天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,按照给定的地表分类数据,对每一种不同的地物类型,分别加以全球范围内随机抽样点自动批量选取的方法~
260 0
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
|
3月前
|
前端开发 JavaScript
从零开始学习前端开发:HTML、CSS、JavaScript入门指南
【2月更文挑战第1天】本文将带领读者从零开始学习前端开发,介绍HTML、CSS和JavaScript的基础知识与应用,帮助读者快速入门前端开发领域。
66 1
|
3月前
|
JavaScript 前端开发 Java
MooTools、Backbone、Sammy、Cappuccino、Knockout、JavaScript MVC、Google Web Toolkit、Google Closure、Ember、Batman 以及 Ext JS。
MooTools、Backbone、Sammy、Cappuccino、Knockout、JavaScript MVC、Google Web Toolkit、Google Closure、Ember、Batman 和 Ext JS 都是 JavaScript 框架,用于开发 Web 应用程序。它们分别提供了不同的功能和特性,以帮助开发者更高效地构建和维护 Web 应用程序。
19 2
|
3月前
|
API Go 网络架构
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
GEE Colab——如何从本地/Google云盘/Google Cloud Storage (GCS)上传和下载
90 4

热门文章

最新文章