ee.FeatureCollection.map

將演算法對應至集合。

傳回對應的集合。

用量傳回
FeatureCollection.map(algorithm, dropNulls)集合
引數類型詳細資料
this: 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 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)

display('Note the new "capacitygw" property in each feature:', fc)