Earth Engine 即將推出
非商業用途的配額級別 ,以便保護共用運算資源,並確保所有使用者都能享有穩固效能。所有非商業用途的專案都必須在
2026 年 4 月 27 日 前選取配額級別,否則屆時會預設為「社群」級別。在
2026 年 4 月 27 日 ,所有專案 (無論選取級別的日期為何) 的級別配額都會生效。
瞭解詳情 。
Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
提供意見
ee.FeatureCollection.reduceColumns
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用指定選取器判斷輸入內容,然後將縮減器套用至集合中的每個元素。
傳回結果字典,並以輸出名稱做為鍵。
用量 傳回 FeatureCollection. reduceColumns (reducer, selectors, weightSelectors )字典
引數 類型 詳細資料 this: collection FeatureCollection 要匯總的集合。 reducer縮減函式 要套用的縮減函式。 selectors清單 每個縮減器輸入內容的選取器。 weightSelectors清單,預設值:null 每個縮減器加權輸入內容的選取器。
範例
程式碼編輯器 (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' ]
})
display ( 'Mean of a single property:' , prop_mean )
# Calculate mean of multiple FeatureCollection properties.
props_mean = fc . reduceColumns ( ** {
'reducer' : ee . Reducer . mean () . repeat ( 2 ),
'selectors' : [ 'gwh_estimt' , 'capacitymw' ]
})
display ( 'Mean of multiple properties:' , props_mean )
# 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' ]
})
display ( 'Weighted mean of a single property:' , weighted_mean )
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2026-04-20 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","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"]],["上次更新時間:2026-04-20 (世界標準時間)。"],[],["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"]]