公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.FeatureCollection.set
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
替换元素的 1 个或多个元数据属性。
返回具有指定属性覆盖的元素。
用法 | 返回 |
---|
FeatureCollection.set(var_args) | 元素 |
参数 | 类型 | 详细信息 |
---|
此:element | 元素 | Element 实例。 |
var_args | VarArgs<Object> | 属性字典或属性的 vararg 序列,例如 key1、value1、key2、value2 等。 |
示例
代码编辑器 (JavaScript)
// An empty FeatureCollection for simple demonstration.
var fc = ee.FeatureCollection([]);
// Set a single new property using a key-value pair.
fc = fc.set('key_1', 'value 1');
// Set multiple new properties using a series of key-value pairs.
fc = fc.set('key_2', 'value 2',
'key_3', 3);
// Set new properties using a dictionary of key-value pairs.
fc = fc.set({
key_5: ee.Array([1, 2, 3]),
key_6: ee.Image(0),
key_7: ee.Feature(null)
});
print('New FeatureCollection properties added', fc);
// Overwrite an existing property.
fc = fc.set('key_1', 'overwritten');
print('FeatureCollection property overwritten', fc);
Python 设置
如需了解 Python API 和如何使用 geemap
进行交互式开发,请参阅
Python 环境页面。
import ee
import geemap.core as geemap
Colab (Python)
from pprint import pprint
# An empty FeatureCollection for simple demonstration.
fc = ee.FeatureCollection([])
# Set a single new property using a key-value pair.
fc = fc.set('key_1', 'value 1')
# Set multiple new properties using a series of key-value pairs.
fc = fc.set('key_2', 'value 2', 'key_3', 3)
# Set new properties using a dictionary of key-value pairs.
fc = fc.set({
'key_5': ee.Array([1, 2, 3]),
'key_6': ee.Image(0),
'key_7': ee.Feature(None)
})
print('New FeatureCollection properties added:')
pprint(fc.getInfo())
# Overwrite an existing property.
fc = fc.set('key_1', 'overwritten')
print('FeatureCollection property overwritten:')
pprint(fc.getInfo())
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThe \u003ccode\u003eset()\u003c/code\u003e method overrides or adds metadata properties to an Element, such as a FeatureCollection.\u003c/p\u003e\n"],["\u003cp\u003eIt accepts either a dictionary of key-value pairs or a sequence of key-value pairs as arguments.\u003c/p\u003e\n"],["\u003cp\u003eExisting properties can be overwritten by calling \u003ccode\u003eset()\u003c/code\u003e with the same key and a new value.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eset()\u003c/code\u003e method returns a new Element with the modified properties, leaving the original Element unchanged.\u003c/p\u003e\n"]]],[],null,["# ee.FeatureCollection.set\n\n\u003cbr /\u003e\n\nOverrides one or more metadata properties of an Element.\n\n\u003cbr /\u003e\n\nReturns the element with the specified properties overridden.\n\n| Usage | Returns |\n|-----------------------------------|---------|\n| FeatureCollection.set`(var_args)` | Element |\n\n| Argument | Type | Details |\n|-----------------|-------------------|-------------------------------------------------------------------------------------------------------------|\n| this: `element` | Element | The Element instance. |\n| `var_args` | VarArgs\\\u003cObject\\\u003e | Either a dictionary of properties, or a vararg sequence of properties, e.g. key1, value1, key2, value2, ... |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// An empty FeatureCollection for simple demonstration.\nvar fc = ee.FeatureCollection([]);\n\n// Set a single new property using a key-value pair.\nfc = fc.set('key_1', 'value 1');\n\n// Set multiple new properties using a series of key-value pairs.\nfc = fc.set('key_2', 'value 2',\n 'key_3', 3);\n\n// Set new properties using a dictionary of key-value pairs.\nfc = fc.set({\n key_5: ee.Array([1, 2, 3]),\n key_6: ee.Image(0),\n key_7: ee.Feature(null)\n});\nprint('New FeatureCollection properties added', fc);\n\n// Overwrite an existing property.\nfc = fc.set('key_1', 'overwritten');\nprint('FeatureCollection property overwritten', 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\nfrom pprint import pprint\n\n# An empty FeatureCollection for simple demonstration.\nfc = ee.FeatureCollection([])\n\n# Set a single new property using a key-value pair.\nfc = fc.set('key_1', 'value 1')\n\n# Set multiple new properties using a series of key-value pairs.\nfc = fc.set('key_2', 'value 2', 'key_3', 3)\n\n# Set new properties using a dictionary of key-value pairs.\nfc = fc.set({\n 'key_5': ee.Array([1, 2, 3]),\n 'key_6': ee.Image(0),\n 'key_7': ee.Feature(None)\n})\nprint('New FeatureCollection properties added:')\npprint(fc.getInfo())\n\n# Overwrite an existing property.\nfc = fc.set('key_1', 'overwritten')\nprint('FeatureCollection property overwritten:')\npprint(fc.getInfo())\n```"]]