公告:凡是在
2025 年 4 月 15 日前註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格,才能繼續存取 Earth Engine。
ee.FeatureCollection.randomColumn
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
將一列決定性的偽隨機數新增至集合。輸出內容為雙精度浮點數。使用「均勻」分佈 (預設) 時,輸出值會落在 [0, 1] 的範圍內。使用「正常」分佈函式時,輸出值的 μ 和 σ 分別為 0 和 1,但沒有明確的限制。
用量 | 傳回 |
---|
FeatureCollection.randomColumn(columnName, seed, distribution, rowKeys) | FeatureCollection |
引數 | 類型 | 詳細資料 |
---|
this:collection | FeatureCollection | 要新增隨機資料欄的輸入集合。 |
columnName | 字串,預設值為「random」 | 要新增的資料欄名稱。 |
seed | Long,預設值:0 | 產生隨機號碼時使用的種子。 |
distribution | 字串,預設值為「uniform」 | 要產生的隨機數分布類型,可選值為「uniform」或「normal」。 |
rowKeys | 清單,選用 | 屬性清單,應可用於唯一且可重複識別集合元素,用於產生隨機號碼。預設值為 [system:index]。 |
範例
程式碼編輯器 (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());
Python 設定
請參閱「
Python 環境」頁面,瞭解 Python API 和如何使用 geemap
進行互動式開發。
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())
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[],["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,[]]