公告 :凡是在
2025 年 4 月 15 日前 註冊使用 Earth Engine 的非商業專案,都必須
驗證非商業用途資格 ,才能繼續存取。如未在 2025 年 9 月 26 日前完成驗證,存取權可能會暫停。
提供意見
ee.FeatureCollection.reduceColumns
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用指定選取器判斷輸入內容,並將縮減器套用至集合中的每個元素。
傳回結果字典,並以輸出名稱做為鍵。
用量 傳回 FeatureCollection. reduceColumns (reducer, selectors, weightSelectors )
字典
引數 類型 詳細資料 這個:collection
FeatureCollection 要匯總的集合。 reducer
縮減函式 要套用的縮減函式。 selectors
清單 每個縮減器輸入內容的選取器。 weightSelectors
清單,預設值為空值 每個加權縮減輸入內容的選取器。
範例
程式碼編輯器 (JavaScript)
// FeatureCollection of power plants in Belgium.
var fc = ee . FeatureCollection ( 'WRI/GPPD/power_plants' )
. filter ( 'country_lg == "Belgium"' );
// Calculate mean of a single FeatureCollection property.
var propMean = fc . reduceColumns ({
reducer : ee . Reducer . mean (),
selectors : [ 'gwh_estimt' ]
});
print ( 'Mean of a single property' , propMean );
// Calculate mean of multiple FeatureCollection properties.
var propsMean = fc . reduceColumns ({
reducer : ee . Reducer . mean (). repeat ( 2 ),
selectors : [ 'gwh_estimt' , 'capacitymw' ]
});
print ( 'Mean of multiple properties' , propsMean );
// Calculate weighted mean of a single FeatureCollection property. Add a fuel
// source weight property to the FeatureCollection.
var fuelWeights = ee . Dictionary ({
Wind : 0.9 ,
Gas : 0.2 ,
Oil : 0.2 ,
Coal : 0.1 ,
Hydro : 0.7 ,
Biomass : 0.5 ,
Nuclear : 0.3
});
fc = fc . map ( function ( feature ) {
return feature . set ( 'weight' , fuelWeights . getNumber ( feature . get ( 'fuel1' )));
});
var weightedMean = fc . reduceColumns ({
reducer : ee . Reducer . mean (),
selectors : [ 'gwh_estimt' ],
weightSelectors : [ 'weight' ]
});
print ( 'Weighted mean of a single property' , weightedMean );
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"' )
# Calculate mean of a single FeatureCollection property.
prop_mean = fc . reduceColumns ( ** {
'reducer' : ee . Reducer . mean (),
'selectors' : [ 'gwh_estimt' ]
})
print ( 'Mean of a single property:' , prop_mean . getInfo ())
# Calculate mean of multiple FeatureCollection properties.
props_mean = fc . reduceColumns ( ** {
'reducer' : ee . Reducer . mean () . repeat ( 2 ),
'selectors' : [ 'gwh_estimt' , 'capacitymw' ]
})
print ( 'Mean of multiple properties:' , props_mean . getInfo ())
# Calculate weighted mean of a single FeatureCollection property. Add a fuel
# source weight property to the FeatureCollection.
def get_fuel ( feature ):
return feature . set ( 'weight' , fuel_weights . getNumber ( feature . get ( 'fuel1' )))
fuel_weights = ee . Dictionary ({
'Wind' : 0.9 ,
'Gas' : 0.2 ,
'Oil' : 0.2 ,
'Coal' : 0.1 ,
'Hydro' : 0.7 ,
'Biomass' : 0.5 ,
'Nuclear' : 0.3
})
fc = fc . map ( get_fuel )
weighted_mean = fc . reduceColumns ( ** {
'reducer' : ee . Reducer . mean (),
'selectors' : [ 'gwh_estimt' ],
'weightSelectors' : [ 'weight' ]
})
print ( 'Weighted mean of a single property:' , weighted_mean . getInfo ())
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],["The `reduceColumns` function applies a reducer to a FeatureCollection, generating a dictionary of results. It uses `selectors` to specify input properties and can use `weightSelectors` for weighted inputs. The function takes a `reducer`, and a list of `selectors` and `weightSelectors`. This method can calculate means of single or multiple properties and weighted means by using a reducer and specifying properties to calculate on. The results are returned as a dictionary.\n"]]