إشعار: يجب
إثبات أهلية جميع المشاريع غير التجارية المسجّلة لاستخدام Earth Engine قبل
15 أبريل 2025 من أجل الحفاظ على إمكانية الوصول إلى Earth Engine.
ee.FeatureCollection.reduceColumns
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تطبيق أداة تقليل على كل عنصر من عناصر المجموعة، باستخدام أدوات الاختيار المحدّدة لتحديد المدخلات
تعرض هذه الدالة قاموسًا للنتائج، ويتم تحديد مفاتيحها باستخدام أسماء الإخراج.
الاستخدام | المرتجعات |
---|
FeatureCollection.reduceColumns(reducer, selectors, weightSelectors) | القاموس |
الوسيطة | النوع | التفاصيل |
---|
هذا: collection | FeatureCollection | المجموعة المطلوب تجميعها. |
reducer | 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 واستخدام
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())
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003e\u003ccode\u003ereduceColumns\u003c/code\u003e applies a reducer function to properties (columns) of a FeatureCollection, effectively aggregating data across all features.\u003c/p\u003e\n"],["\u003cp\u003eIt takes a reducer, a list of selectors specifying the properties to use as input, and optionally, weight selectors for weighted reductions.\u003c/p\u003e\n"],["\u003cp\u003eThe output is a dictionary containing the results, keyed by the names defined within the reducer.\u003c/p\u003e\n"],["\u003cp\u003eThis function allows for calculating statistics such as mean, sum, or other custom aggregations across the features in a FeatureCollection, using specified properties and optional weights.\u003c/p\u003e\n"],["\u003cp\u003eExamples provided demonstrate calculating mean and weighted mean of properties within a FeatureCollection of power plants.\u003c/p\u003e\n"]]],["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"],null,["# ee.FeatureCollection.reduceColumns\n\nApply a reducer to each element of a collection, using the given selectors to determine the inputs.\n\n\u003cbr /\u003e\n\nReturns a dictionary of results, keyed with the output names.\n\n| Usage | Returns |\n|----------------------------------------------------------------------------|------------|\n| FeatureCollection.reduceColumns`(reducer, selectors, `*weightSelectors*`)` | Dictionary |\n\n| Argument | Type | Details |\n|--------------------|---------------------|----------------------------------------------------|\n| this: `collection` | FeatureCollection | The collection to aggregate over. |\n| `reducer` | Reducer | The reducer to apply. |\n| `selectors` | List | A selector for each input of the reducer. |\n| `weightSelectors` | List, default: null | A selector for each weighted input of the reducer. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// FeatureCollection of power plants in Belgium.\nvar fc = ee.FeatureCollection('WRI/GPPD/power_plants')\n .filter('country_lg == \"Belgium\"');\n\n// Calculate mean of a single FeatureCollection property.\nvar propMean = fc.reduceColumns({\n reducer: ee.Reducer.mean(),\n selectors: ['gwh_estimt']\n});\nprint('Mean of a single property', propMean);\n\n// Calculate mean of multiple FeatureCollection properties.\nvar propsMean = fc.reduceColumns({\n reducer: ee.Reducer.mean().repeat(2),\n selectors: ['gwh_estimt', 'capacitymw']\n});\nprint('Mean of multiple properties', propsMean);\n\n// Calculate weighted mean of a single FeatureCollection property. Add a fuel\n// source weight property to the FeatureCollection.\nvar fuelWeights = ee.Dictionary({\n Wind: 0.9,\n Gas: 0.2,\n Oil: 0.2,\n Coal: 0.1,\n Hydro: 0.7,\n Biomass: 0.5,\n Nuclear: 0.3\n});\nfc = fc.map(function(feature) {\n return feature.set('weight', fuelWeights.getNumber(feature.get('fuel1')));\n});\n\nvar weightedMean = fc.reduceColumns({\n reducer: ee.Reducer.mean(),\n selectors: ['gwh_estimt'],\n weightSelectors: ['weight']\n});\nprint('Weighted mean of a single property', weightedMean);\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# FeatureCollection of power plants in Belgium.\nfc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(\n 'country_lg == \"Belgium\"')\n\n# Calculate mean of a single FeatureCollection property.\nprop_mean = fc.reduceColumns(**{\n 'reducer': ee.Reducer.mean(),\n 'selectors': ['gwh_estimt']\n })\nprint('Mean of a single property:', prop_mean.getInfo())\n\n# Calculate mean of multiple FeatureCollection properties.\nprops_mean = fc.reduceColumns(**{\n 'reducer': ee.Reducer.mean().repeat(2),\n 'selectors': ['gwh_estimt', 'capacitymw']\n })\nprint('Mean of multiple properties:', props_mean.getInfo())\n\n\n# Calculate weighted mean of a single FeatureCollection property. Add a fuel\n# source weight property to the FeatureCollection.\ndef get_fuel(feature):\n return feature.set('weight', fuel_weights.getNumber(feature.get('fuel1')))\n\nfuel_weights = ee.Dictionary({\n 'Wind': 0.9,\n 'Gas': 0.2,\n 'Oil': 0.2,\n 'Coal': 0.1,\n 'Hydro': 0.7,\n 'Biomass': 0.5,\n 'Nuclear': 0.3\n })\n\nfc = fc.map(get_fuel)\n\nweighted_mean = fc.reduceColumns(**{\n 'reducer': ee.Reducer.mean(),\n 'selectors': ['gwh_estimt'],\n 'weightSelectors': ['weight']\n })\nprint('Weighted mean of a single property:', weighted_mean.getInfo())\n```"]]