การกรอง FeatureCollection

การกรอง FeatureCollection นั้นคล้ายกับการกรอง ImageCollection (ดูการกรองส่วน ImageCollection) มีวิธีการแบบสะดวก featureCollection.filterDate() และ featureCollection.filterBounds() รวมถึงวิธี featureCollection.filter() สำหรับใช้กับ ee.Filter ที่เกี่ยวข้อง เช่น

// Load watersheds from a data table.
var sheds = ee.FeatureCollection('USGS/WBD/2017/HUC06')
  // Convert 'areasqkm' property from string to number.
  .map(function(feature){
    var num = ee.Number.parse(feature.get('areasqkm'));
    return feature.set('areasqkm', num);
  });

// Define a region roughly covering the continental US.
var continentalUS = ee.Geometry.Rectangle(-127.18, 19.39, -62.75, 51.29);

// Filter the table geographically: only watersheds in the continental US.
var filtered = sheds.filterBounds(continentalUS);

// Check the number of watersheds after filtering for location.
print('Count after filter:', filtered.size());

// Filter to get only larger continental US watersheds.
var largeSheds = filtered.filter(ee.Filter.gt('areasqkm', 25000));

// Check the number of watersheds after filtering for size and location.
print('Count after filtering by size:', largeSheds.size());

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap สําหรับการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

import ee
import geemap.core as geemap
# Load watersheds from a data table.
sheds = (
    ee.FeatureCollection('USGS/WBD/2017/HUC06')
    # Convert 'areasqkm' property from string to number.
    .map(
        lambda feature: feature.set(
            'areasqkm', ee.Number.parse(feature.get('areasqkm'))
        )
    )
)

# Define a region roughly covering the continental US.
continental_us = ee.Geometry.Rectangle(-127.18, 19.39, -62.75, 51.29)

# Filter the table geographically: only watersheds in the continental US.
filtered = sheds.filterBounds(continental_us)

# Check the number of watersheds after filtering for location.
display('Count after filter:', filtered.size())

# Filter to get only larger continental US watersheds.
large_sheds = filtered.filter(ee.Filter.gt('areasqkm', 25000))

# Check the number of watersheds after filtering for size and location.
display('Count after filtering by size:', large_sheds.size())