公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.Dictionary.combine
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
合并两个字典。如果存在重复名称,除非 overwrite 为 false,否则输出将包含第二个字典的值。系统会忽略 / 移除两个字典中的 null 值。
用法 | 返回 |
---|
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 API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
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())
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):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```"]]