ee.FeatureCollection.map

将算法映射到集合。

返回映射的集合。

用法返回
FeatureCollection.map(algorithm, dropNulls)集合
参数类型详细信息
此:collection集合Collection 实例。
algorithm函数要对集合中的图片或特征进行映射的操作。一个 JavaScript 函数,用于接收图片或特征并返回一个。该函数仅被调用一次,结果会作为说明捕获,因此它无法执行命令式操作或依赖外部状态。
dropNulls布尔值,可选如果为 true,则允许映射的算法返回 null,并且将舍弃返回 null 的元素。

示例

代码编辑器 (JavaScript)

// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
            .filter('country_lg == "Belgium"');

// Function to convert power plant capacity from megawatts to gigawatts and
// add the value as a new feature property.
var mwToGw = function(feature) {
  var megawatt = feature.getNumber('capacitymw');
  var gigawatt = megawatt.divide(1000);
  return feature.set('capacitygw', gigawatt);
};

// Apply the function to each feature in the collection.
fc = fc.map(mwToGw);

print('Note the new "capacitygw" property in each feature', fc);

Python 设置

如需了解 Python API 和如何使用 geemap 进行交互式开发,请参阅 Python 环境页面。

import ee
import geemap.core as geemap

Colab (Python)

# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
    'country_lg == "Belgium"')

# Function to convert power plant capacity from megawatts to gigawatts and
# add the value as a new feature property.
def mw_to_gw(feature):
  megawatt = feature.getNumber('capacitymw')
  gigawatt = megawatt.divide(1000)
  return feature.set('capacitygw', gigawatt)

# Apply the function to each feature in the collection.
fc = fc.map(mw_to_gw)

print('Note the new "capacitygw" property in each feature:', fc.getInfo())