ee.FeatureCollection.set

替换元素的 1 个或多个元数据属性。

返回具有指定属性覆盖的元素。

用法返回
FeatureCollection.set(var_args)元素
参数类型详细信息
此:element元素Element 实例。
var_argsVarArgs<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())