ee.FeatureCollection.randomColumn

Thêm một cột gồm các số ngẫu nhiên giả định có thể xác định vào một tập hợp. Kết quả là các số dấu phẩy động có độ chính xác kép. Khi sử dụng phương thức phân phối "đồng nhất" (mặc định), kết quả sẽ nằm trong khoảng [0, 1). Khi sử dụng phân phối "bình thường", đầu ra có μ=0, σ=1 nhưng không có giới hạn rõ ràng.

Cách sử dụngGiá trị trả về
FeatureCollection.randomColumn(columnName, seed, distribution, rowKeys)FeatureCollection
Đối sốLoạiThông tin chi tiết
this: collectionFeatureCollectionBộ sưu tập đầu vào để thêm một cột ngẫu nhiên.
columnNameChuỗi, mặc định: "random"Tên của cột cần thêm.
seedDài, mặc định: 0Giá trị khởi tạo được dùng khi tạo số ngẫu nhiên.
distributionChuỗi, mặc định: "đồng nhất"Loại phân phối số ngẫu nhiên cần tạo; một trong hai loại "đồng nhất" hoặc "bình thường".
rowKeysDanh sách, không bắt buộcDanh sách các thuộc tính phải xác định một phần tử của tập hợp một cách duy nhất và lặp lại, dùng để tạo số ngẫu nhiên. Giá trị mặc định là [system:index].

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"');
print('N features in collection', fc.size());

// Add a uniform distribution random value column to the FeatureCollection.
fc = fc.randomColumn();

// Randomly split the collection into two sets, 30% and 70% of the total.
var randomSample30 = fc.filter('random < 0.3');
print('N features in 30% sample', randomSample30.size());

var randomSample70 = fc.filter('random >= 0.3');
print('N features in 70% sample', randomSample70.size());

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 để 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"')
print('N features in collection:', fc.size().getInfo())

# Add a uniform distribution random value column to the FeatureCollection.
fc = fc.randomColumn()

# Randomly split the collection into two sets, 30% and 70% of the total.
random_sample_30 = fc.filter('random < 0.3')
print('N features in 30% sample:', random_sample_30.size().getInfo())

random_sample_70 = fc.filter('random >= 0.3')
print('N features in 70% sample:', random_sample_70.size().getInfo())