ee.FeatureCollection.map

將演算法對應至集合。

傳回對應的集合。

用量傳回
FeatureCollection.map(algorithm, dropNulls)集合
引數類型詳細資料
這個:collection集合Collection 執行個體。
algorithm函式要對集合的圖片或特徵進行對應的操作。JavaScript 函式,可接收圖片或特徵並傳回一個。函式只會呼叫一次,結果會擷取為說明,因此無法執行命令式作業或依附外部狀態。
dropNulls布林值 (選填)如果是 true,對應的演算法可以傳回空值,且系統會捨棄傳回空值的元素。

範例

程式碼編輯器 (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 環境頁面,瞭解 Python API 和如何使用 geemap 進行互動式開發。

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())