Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
Filtering a FeatureCollection is analogous to filtering an
ImageCollection. (See the Filtering an
ImageCollection section). There are the featureCollection.filterDate(),
and featureCollection.filterBounds() convenience methods and the
featureCollection.filter() method for use with any applicable
ee.Filter. For example:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-03 UTC."],[[["\u003cp\u003eFiltering \u003ccode\u003eFeatureCollection\u003c/code\u003e objects is similar to filtering \u003ccode\u003eImageCollection\u003c/code\u003e objects and can be done using methods like \u003ccode\u003efilterDate()\u003c/code\u003e, \u003ccode\u003efilterBounds()\u003c/code\u003e, and \u003ccode\u003efilter()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003efilter()\u003c/code\u003e method accepts an \u003ccode\u003eee.Filter\u003c/code\u003e object, allowing for flexible filtering based on various criteria.\u003c/p\u003e\n"],["\u003cp\u003eThe provided examples demonstrate how to filter a dataset of watersheds based on location and size using the \u003ccode\u003efilterBounds()\u003c/code\u003e and \u003ccode\u003efilter()\u003c/code\u003e methods respectively.\u003c/p\u003e\n"],["\u003cp\u003eCode snippets in JavaScript and Python (using \u003ccode\u003egeemap\u003c/code\u003e and Colab) illustrate the implementation of the filtering process.\u003c/p\u003e\n"]]],[],null,["# Filtering a FeatureCollection\n\nFiltering a `FeatureCollection` is analogous to filtering an\n`ImageCollection`. (See the [Filtering an\nImageCollection section](/earth-engine/guides/ic_filtering)). There are the `featureCollection.filterDate()`,\nand `featureCollection.filterBounds()` convenience methods and the\n`featureCollection.filter()` method for use with any applicable\n`ee.Filter`. For example:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load watersheds from a data table.\nvar sheds = ee.FeatureCollection('USGS/WBD/2017/HUC06')\n // Convert 'areasqkm' property from string to number.\n .map(function(feature){\n var num = ee.Number.parse(feature.get('areasqkm'));\n return feature.set('areasqkm', num);\n });\n\n// Define a region roughly covering the continental US.\nvar continentalUS = ee.Geometry.Rectangle(-127.18, 19.39, -62.75, 51.29);\n\n// Filter the table geographically: only watersheds in the continental US.\nvar filtered = sheds.filterBounds(continentalUS);\n\n// Check the number of watersheds after filtering for location.\nprint('Count after filter:', filtered.size());\n\n// Filter to get only larger continental US watersheds.\nvar largeSheds = filtered.filter(ee.Filter.gt('areasqkm', 25000));\n\n// Check the number of watersheds after filtering for size and location.\nprint('Count after filtering by size:', largeSheds.size());\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# Load watersheds from a data table.\nsheds = (\n ee.FeatureCollection('USGS/WBD/2017/HUC06')\n # Convert 'areasqkm' property from string to number.\n .map(\n lambda feature: feature.set(\n 'areasqkm', ee.Number.parse(feature.get('areasqkm'))\n )\n )\n)\n\n# Define a region roughly covering the continental US.\ncontinental_us = ee.Geometry.Rectangle(-127.18, 19.39, -62.75, 51.29)\n\n# Filter the table geographically: only watersheds in the continental US.\nfiltered = sheds.filterBounds(continental_us)\n\n# Check the number of watersheds after filtering for location.\ndisplay('Count after filter:', filtered.size())\n\n# Filter to get only larger continental US watersheds.\nlarge_sheds = filtered.filter(ee.Filter.gt('areasqkm', 25000))\n\n# Check the number of watersheds after filtering for size and location.\ndisplay('Count after filtering by size:', large_sheds.size())\n```"]]