ee.FeatureCollection.aggregate_count_distinct
Aggregates over a given property of the objects in a collection, calculating the number of distinct values for the selected property.
Usage | Returns |
---|
FeatureCollection.aggregate_count_distinct(property) | Number |
Argument | Type | Details |
---|
this: collection | FeatureCollection | The collection to aggregate over. |
property | String | The property to use from each element of the collection. |
Examples
// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
.filter('country_lg == "Belgium"');
print('Number of distinct power plant fuel sources',
fc.aggregate_count_distinct('fuel1')); // 7
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
'country_lg == "Belgium"')
print('Number of distinct power plant fuel sources:',
fc.aggregate_count_distinct('fuel1').getInfo()) # 7
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["Counts the number of distinct values for a specified property within a FeatureCollection."],["Accepts a FeatureCollection and the property name as input."],["Returns the total count of distinct values as a number."],["Useful for understanding the variety of values within a dataset's property."]]],["The `aggregate_count_distinct` method calculates the number of unique values for a specified property within a FeatureCollection. It takes a FeatureCollection as input and a property name (string) to evaluate. The method returns a numerical value representing the count of distinct values. For example, in a FeatureCollection of power plants, using `aggregate_count_distinct('fuel1')` returns the number of distinct fuel sources. In the provided example in Belgium it returned 7.\n"]]