ee.FeatureCollection.select

Chọn các thuộc tính trong mỗi Đối tượng trên một tập hợp. Bạn cũng có thể gọi hàm này chỉ bằng các đối số chuỗi; tất cả các đối số này sẽ được diễn giải dưới dạng propertySelectors (varargs).

Trả về tập hợp đối tượng có các thuộc tính đã chọn.

Cách sử dụngGiá trị trả về
FeatureCollection.select(propertySelectors, newProperties, retainGeometry)FeatureCollection
Đối sốLoạiThông tin chi tiết
this: featurecollectionFeatureCollectionĐối tượng FeatureCollection.
propertySelectorsList<String>Một danh sách tên hoặc biểu thức chính quy chỉ định các thuộc tính cần chọn.
newPropertiesList<String>, không bắt buộcDanh sách tên mới cho các thuộc tính đầu ra. Phải khớp với số lượng cơ sở lưu trú đã chọn.
retainGeometryBoolean, không bắt buộcKhi sai, kết quả sẽ có một hình học NULL. Giá trị mặc định là đúng.

Ví dụ

Trình soạn thảo mã (JavaScript)

// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
            .filter('country_lg == "Belgium"');

// Select a single property.
var singleProp = fc.select('fuel1');
print('Single property selected',
      singleProp.first());

// Select multiple properties.
var multiProp = fc.select(['fuel1', 'capacitymw']);
print('Multiple properties selected',
      multiProp.first());

// Select multiple properties and rename them.
var multiPropRename = fc.select({
  propertySelectors: ['fuel1', 'capacitymw'],
  newProperties: ['Fuel_1', 'Capacity_MW']
});
print('Multiple properties selected, renamed',
      multiPropRename.first());

// Select multiple properties, remove geometry.
var multiPropNoGeom = fc.select({
  propertySelectors: ['fuel1', 'capacitymw'],
  retainGeometry: false
});
print('Multiple properties selected, geometry removed',
      multiPropNoGeom.first());

Thiết lập Python

Hãy xem trang Môi trường Python để biết thông tin về API Python và cách sử dụng geemap cho quá trình phát triển tương tác.

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"')

# Select a single property.
single_prop = fc.select('fuel1')
print('Single property selected:', single_prop.first().getInfo())

# Select multiple properties.
multi_prop = fc.select(['fuel1', 'capacitymw'])
print('Multiple properties selected:', multi_prop.first().getInfo())

# Select multiple properties and rename them.
multi_prop_rename = fc.select(**{
    'propertySelectors': ['fuel1', 'capacitymw'],
    'newProperties': ['Fuel_1', 'Capacity_MW']
    })
print('Multiple properties selected, renamed:',
      multi_prop_rename.first().getInfo())

# Select multiple properties, remove geometry.
multi_prop_no_geom = fc.select(**{
    'propertySelectors': ['fuel1', 'capacitymw'],
    'retainGeometry': False
    })
print('Multiple properties selected, geometry removed:',
      multi_prop_no_geom.first().getInfo())