公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.Dictionary.combine
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
合併兩個字典。如果名稱重複,除非覆寫為 false,否則輸出內容會包含第二個字典的值。系統會忽略 / 移除兩個字典中的空值。
用量 | 傳回 |
---|
Dictionary.combine(second, overwrite) | 字典 |
引數 | 類型 | 詳細資料 |
---|
這個:first | 字典 | |
second | 字典 | |
overwrite | 布林值,預設值為 true | |
範例
程式碼編輯器 (JavaScript)
// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
var dict1 = ee.Dictionary({
B1: 182,
B2: 219,
B3: 443
});
// A second dictionary.
var dict2 = ee.Dictionary({
Region: 'The Forest of Nisene Marks State Park',
Image: 'Sentinel-2 surface reflectance (scaled by 1e4)',
B1: -9999 // Note that the B1 key is present in both dictionaries.
});
print('Combined dictionaries (overwrite false)',
dict1.combine(dict2, false));
print('Combined dictionaries (overwrite true)',
dict1.combine(dict2, true));
Python 設定
請參閱
Python 環境頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
import ee
import geemap.core as geemap
Colab (Python)
import pprint
# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).
dic_1 = ee.Dictionary({
'B1': 182,
'B2': 219,
'B3': 443
})
# A second dictionary.
dic_2 = ee.Dictionary({
'Region': 'The Forest of Nisene Marks State Park',
'Image': 'Sentinel-2 surface reflectance (scaled by 1e4)',
'B1': -9999 # Note that the B1 key is present in both dictionaries.
})
print('Combined dictionaries (overwrite false)')
pprint.pprint(dic_1.combine(dic_2, False).getInfo())
print('\nCombined dictionaries (overwrite true)')
pprint.pprint(dic_1.combine(dic_2, True).getInfo())
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eDictionary.combine()\u003c/code\u003e merges two dictionaries into a single dictionary.\u003c/p\u003e\n"],["\u003cp\u003eIf the same key exists in both dictionaries, the value from the second dictionary is used by default, unless \u003ccode\u003eoverwrite\u003c/code\u003e is set to \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eNull values present in either of the input dictionaries are automatically excluded from the final combined dictionary.\u003c/p\u003e\n"],["\u003cp\u003eIt's accessible in both JavaScript and Python environments within the Earth Engine platform.\u003c/p\u003e\n"]]],[],null,["# ee.Dictionary.combine\n\nCombines two dictionaries. In the case of duplicate names, the output will contain the value of the second dictionary unless overwrite is false. Null values in both dictionaries are ignored / removed.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|---------------------------------------------|------------|\n| Dictionary.combine`(second, `*overwrite*`)` | Dictionary |\n\n| Argument | Type | Details |\n|---------------|------------------------|---------|\n| this: `first` | Dictionary | |\n| `second` | Dictionary | |\n| `overwrite` | Boolean, default: true | |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).\nvar dict1 = ee.Dictionary({\n B1: 182,\n B2: 219,\n B3: 443\n});\n\n// A second dictionary.\nvar dict2 = ee.Dictionary({\n Region: 'The Forest of Nisene Marks State Park',\n Image: 'Sentinel-2 surface reflectance (scaled by 1e4)',\n B1: -9999 // Note that the B1 key is present in both dictionaries.\n});\n\nprint('Combined dictionaries (overwrite false)',\n dict1.combine(dict2, false));\n\nprint('Combined dictionaries (overwrite true)',\n dict1.combine(dict2, true));\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\nimport pprint\n\n# A dictionary (e.g. results of ee.Image.reduceRegion of an S2 image).\ndic_1 = ee.Dictionary({\n 'B1': 182,\n 'B2': 219,\n 'B3': 443\n})\n\n# A second dictionary.\ndic_2 = ee.Dictionary({\n 'Region': 'The Forest of Nisene Marks State Park',\n 'Image': 'Sentinel-2 surface reflectance (scaled by 1e4)',\n 'B1': -9999 # Note that the B1 key is present in both dictionaries.\n})\n\nprint('Combined dictionaries (overwrite false)')\npprint.pprint(dic_1.combine(dic_2, False).getInfo())\n\nprint('\\nCombined dictionaries (overwrite true)')\npprint.pprint(dic_1.combine(dic_2, True).getInfo())\n```"]]