5

I have a FeatureCollection in Google Earth Engine, where each Feature is referenced by an id tag. How do I filter the FeatureCollection based on that id?

Following attempts to filter id=3 did not work:

 // Create a FC (from https://developers.google.com/earth-engine/guides/feature_collections)
var features = [
  ee.Feature(ee.Geometry.Rectangle(30.01, 59.80, 30.59, 60.15), {name: 'Voronoi'}),
  ee.Feature(ee.Geometry.Point(-73.96, 40.781), {name: 'Thiessen'}),
  ee.Feature(ee.Geometry.Point(6.4806, 50.8012), {name: 'Dirichlet'})
];
var FC = ee.FeatureCollection(features);
print(FC, "FC")

// extract basedon ID?
print(FC.filter(ee.Filter.eq("id", 2)))
print(FC.filter(ee.Filter.eq("system:id", 2)))

2 Answers 2

8

This is tricky, as there are actually two issues:

  • It's called system:index even though the UI shows it as id.

  • The id is a string, rather than an integer

So the correct way to do this is:

print(FC.filter(ee.Filter.eq("system:index", '3')))
1

As an alternative to your answer, you could use

print(g200.filterMetadata('system:index', 'equals', '3'))

Using either filter looks to do the same thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.