ee.FeatureCollection.remap

Ánh xạ lại giá trị của một thuộc tính cụ thể trong một tập hợp. Lấy 2 danh sách song song và ánh xạ các giá trị tìm thấy trong danh sách này sang các giá trị trong danh sách kia. Mọi phần tử có giá trị không được chỉ định trong danh sách đầu tiên đều bị loại bỏ khỏi tập hợp đầu ra.

Cách sử dụngGiá trị trả về
FeatureCollection.remap(lookupIn, lookupOut, columnName)FeatureCollection
Đối sốLoạiThông tin chi tiết
this: collectionFeatureCollectionBộ sưu tập cần sửa đổi.
lookupInDanh sáchCác giá trị ánh xạ đầu vào. Chỉ giới hạn ở chuỗi và số nguyên.
lookupOutDanh sáchCác giá trị liên kết đầu ra. Phải có cùng kích thước với lookupIn.
columnNameChuỗiTên của thuộc tính cần liên kết lại.

Ví dụ

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

// Classify features based on a string property.
// The 'nonsense' category gets dropped.
var fc = ee.FeatureCollection([
  ee.Feature(ee.Geometry.Point([1, 2]), {isTree: 'Tree'}),
  ee.Feature(ee.Geometry.Point([3, 4]), {isTree: 'NotTree'}),
  ee.Feature(ee.Geometry.Point([5, 6]), {isTree: 'nonsense'}),
]);

var trees = fc.remap(['NotTree', 'Tree'], [0, 1], 'isTree');
print('remapped trees', trees);

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)

# Classify features based on a string property.
# The 'nonsense' category gets dropped.
fc = ee.FeatureCollection([
    ee.Feature(ee.Geometry.Point([1, 2]), {'isTree': 'Tree'}),
    ee.Feature(ee.Geometry.Point([3, 4]), {'isTree': 'NotTree'}),
    ee.Feature(ee.Geometry.Point([5, 6]), {'isTree': 'nonsense'}),
    ])

trees = fc.remap(['NotTree', 'Tree'], [0, 1], 'isTree')
print('Remapped trees:', trees.getInfo())