公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
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())
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003emap()\u003c/code\u003e iterates over a FeatureCollection, applying a user-defined function to each feature.\u003c/p\u003e\n"],["\u003cp\u003eThe provided function transforms features and returns modified versions, creating a new FeatureCollection.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003emap()\u003c/code\u003e allows adding/modifying properties of features within a FeatureCollection or performing calculations based on existing properties.\u003c/p\u003e\n"],["\u003cp\u003eAn optional \u003ccode\u003edropNulls\u003c/code\u003e parameter controls whether features resulting in null from the mapping function are retained in the output.\u003c/p\u003e\n"]]],["The `map` algorithm applies a user-defined function to each element within a collection (e.g., features or images). This function, which accepts an element as input and returns a modified one, is applied to each item of the collection. The `dropNulls` argument allows filtering null return values. The result is a new collection containing the modified elements. For example, converting power plant capacity units and adding them as a new property to the features.\n"],null,["# ee.FeatureCollection.map\n\n\u003cbr /\u003e\n\nMaps an algorithm over a collection.\n\n\u003cbr /\u003e\n\nReturns the mapped collection.\n\n| Usage | Returns |\n|---------------------------------------------------|------------|\n| FeatureCollection.map`(algorithm, `*dropNulls*`)` | Collection |\n\n| Argument | Type | Details |\n|--------------------|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| this: `collection` | Collection | The Collection instance. |\n| `algorithm` | Function | The operation to map over the images or features of the collection. A JavaScript function that receives an image or features and returns one. The function is called only once and the result is captured as a description, so it cannot perform imperative operations or rely on external state. |\n| `dropNulls` | Boolean, optional | If true, the mapped algorithm is allowed to return nulls, and the elements for which it returns nulls will be dropped. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// FeatureCollection of power plants in Belgium.\nvar fc = ee.FeatureCollection('WRI/GPPD/power_plants')\n .filter('country_lg == \"Belgium\"');\n\n// Function to convert power plant capacity from megawatts to gigawatts and\n// add the value as a new feature property.\nvar mwToGw = function(feature) {\n var megawatt = feature.getNumber('capacitymw');\n var gigawatt = megawatt.divide(1000);\n return feature.set('capacitygw', gigawatt);\n};\n\n// Apply the function to each feature in the collection.\nfc = fc.map(mwToGw);\n\nprint('Note the new \"capacitygw\" property in each feature', fc);\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# FeatureCollection of power plants in Belgium.\nfc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(\n 'country_lg == \"Belgium\"')\n\n# Function to convert power plant capacity from megawatts to gigawatts and\n# add the value as a new feature property.\ndef mw_to_gw(feature):\n megawatt = feature.getNumber('capacitymw')\n gigawatt = megawatt.divide(1000)\n return feature.set('capacitygw', gigawatt)\n\n# Apply the function to each feature in the collection.\nfc = fc.map(mw_to_gw)\n\nprint('Note the new \"capacitygw\" property in each feature:', fc.getInfo())\n```"]]