ee.FeatureCollection.filter

  • The filter method is used to apply a filter to a collection.

  • The filter method returns the filtered collection.

  • The method takes a filter argument of type Filter.

  • Examples are provided in JavaScript and Python demonstrating how to use the filter method to select features based on an attribute value.

Apply a filter to this collection.

Returns the filtered collection.

UsageReturns
FeatureCollection.filter(filter)Collection
ArgumentTypeDetails
this: collectionCollectionThe Collection instance.
filterFilterA filter to apply to this collection.

Examples

Code Editor (JavaScript)

// Load a collection of counties.
var counties = ee.FeatureCollection('FAO/GAUL_SIMPLIFIED_500m/2015/level2');

// Filter the collection to get Denver county.
var denverCollection = counties.filter(ee.Filter.eq('ADM2_NAME', 'Denver'));

// Or you can use a string filter (equivalent to the above):
// var denverCollection = counties.filter("ADM2_NAME == 'Denver'");

Map.centerObject(denverCollection, 9);
Map.addLayer(denverCollection, null, 'Denver');

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

Colab (Python)

# Load a collection of counties.
counties = ee.FeatureCollection('FAO/GAUL_SIMPLIFIED_500m/2015/level2')

# Filter the collection to get Denver county.
denver_collection = counties.filter(ee.Filter.eq('ADM2_NAME', 'Denver'))

# Or you can use a string filter (equivalent to the above):
# denver_collection = counties.filter("ADM2_NAME == 'Denver'")

m = geemap.Map()
m.center_object(denver_collection, 9)
m.add_layer(denver_collection, None, 'Denver')
m