ee.FeatureCollection.map

Ánh xạ một thuật toán trên một tập hợp.

Trả về tập hợp được liên kết.

Cách sử dụngGiá trị trả về
FeatureCollection.map(algorithm, dropNulls)Bộ sưu tập
Đối sốLoạiThông tin chi tiết
this: collectionBộ sưu tậpPhiên bản Bộ sưu tập.
algorithmChức năngThao tác ánh xạ trên hình ảnh hoặc đối tượng của bộ sưu tập. Một hàm JavaScript nhận một hình ảnh hoặc các đối tượng và trả về một hình ảnh hoặc đối tượng. Hàm này chỉ được gọi một lần và kết quả được ghi lại dưới dạng nội dung mô tả, nên hàm này không thể thực hiện các thao tác bắt buộc hoặc dựa vào trạng thái bên ngoài.
dropNullsBoolean, không bắt buộcNếu đúng, thuật toán được liên kết sẽ được phép trả về giá trị rỗng và các phần tử mà thuật toán này trả về giá trị rỗng sẽ bị loại bỏ.

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

// Function to convert power plant capacity from megawatts to gigawatts and
// add the value as a new feature property.
var mwToGw = function(feature) {
  var megawatt = feature.getNumber('capacitymw');
  var gigawatt = megawatt.divide(1000);
  return feature.set('capacitygw', gigawatt);
};

// Apply the function to each feature in the collection.
fc = fc.map(mwToGw);

print('Note the new "capacitygw" property in each feature', fc);

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

# Function to convert power plant capacity from megawatts to gigawatts and
# add the value as a new feature property.
def mw_to_gw(feature):
  megawatt = feature.getNumber('capacitymw')
  gigawatt = megawatt.divide(1000)
  return feature.set('capacitygw', gigawatt)

# Apply the function to each feature in the collection.
fc = fc.map(mw_to_gw)

print('Note the new "capacitygw" property in each feature:', fc.getInfo())