Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.
ee.FeatureCollection.flatten Stay organized with collections Save and categorize content based on your preferences.
Page Summary
FeatureCollection.flatten() is used to flatten collections of collections.
The method takes a FeatureCollection as input and returns a flattened FeatureCollection.
| Usage | Returns |
|---|---|
FeatureCollection.flatten() | FeatureCollection |
| Argument | Type | Details |
|---|---|---|
this:collection | FeatureCollection | The input collection of collections. |
Examples
Code Editor (JavaScript)
// Counties in New Mexico, USA.varcounties=ee.FeatureCollection('TIGER/2018/Counties').filter('STATEFP == "35"');// Monthly climate and climatic water balance surfaces for January 2020.varclimate=ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE').filterDate('2020-01','2020-02');// Calculate mean climate variables for each county per climate surface// time step. The result is a FeatureCollection of FeatureCollections.varcountiesClimate=climate.map(function(image){returnimage.reduceRegions({collection:counties,reducer:ee.Reducer.mean(),scale:5000,crs:'EPSG:4326'});});// Note that a printed FeatureCollection of FeatureCollections is not// recursively expanded, you cannot view metadata of the features within the// nested collections until you isolate a single collection or flatten the// collections.print('FeatureCollection of FeatureCollections',countiesClimate);print('Flattened FeatureCollection of FeatureCollections',countiesClimate.flatten());
Python setup
See the Python Environment page for information on the Python API and usinggeemap for interactive development.
importeeimportgeemap.coreasgeemap
Colab (Python)
# Counties in New Mexico, USA.counties=ee.FeatureCollection('TIGER/2018/Counties').filter('STATEFP == "35"')# Monthly climate and climatic water balance surfaces for January 2020.climate=ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE').filterDate('2020-01','2020-02')# Calculate mean climate variables for each county per climate surface# time step. The result is a FeatureCollection of FeatureCollections.defreduce_mean(image):returnimage.reduceRegions(**{'collection':counties,'reducer':ee.Reducer.mean(),'scale':5000,'crs':'EPSG:4326'})counties_climate=climate.map(reduce_mean)# Note that a printed FeatureCollection of FeatureCollections is not# recursively expanded, you cannot view metadata of the features within the# nested collections until you isolate a single collection or flatten the# collections.display('FeatureCollection of FeatureCollections:',counties_climate)display('Flattened FeatureCollection of FeatureCollections:',counties_climate.flatten())
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.