ee.FeatureCollection.randomColumn
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
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ụng | Giá trị trả về |
---|
FeatureCollection.randomColumn(columnName, seed, distribution, rowKeys) | FeatureCollection |
Đối số | Loại | Thông tin chi tiết |
---|
this: collection | FeatureCollection | Bộ sưu tập đầu vào để thêm một cột ngẫu nhiên. |
columnName | Chuỗi, mặc định: "random" | Tên của cột cần thêm. |
seed | Dài, mặc định: 0 | Giá trị khởi tạo được dùng khi tạo số ngẫu nhiên. |
distribution | Chuỗ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". |
rowKeys | Danh sách, không bắt buộc | Danh 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())
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-25 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[],["This tool adds a column of pseudorandom numbers to a FeatureCollection. Users can specify the `columnName`, `seed`, and `distribution`. The default distribution, 'uniform', generates numbers between 0 and 1; 'normal' produces numbers with a mean of 0 and a standard deviation of 1. The `randomColumn` method returns the modified FeatureCollection. This is exemplified by creating random splits into subsets. The outputs are double-precision floating point numbers.\n"],null,[]]