7

Is it possible to use an equality filter for a FeatureCollection in GEE based on multiple values? I understand how to filter by one value:

collectionName.filter(ee.Filter.eq('COLUMN','VALUE'));

But what if I wanted to filter by a list of values? Something like:

var lis = ee.List(['VALUE1', 'VALUE2', 'VALUE3']);

Is it possible to apply this to equality filter? I tried to do the following:

collectionName.filter(ee.Filter.eq('COLUMN',lis));

It ran, but didn't work.

2 Answers 2

8

The inList filter is what you want for looking for any value in a list:

collectionName.filter(ee.Filter.inList('COLUMN', lis))

If instead you want to use several filters (so that you can use other conditions than equality, or multiple properties), you can use ee.Filter.or:

collectionName.filter(
  ee.Filter.eq('COLUMN', 'VALUE1')
    .or(ee.Filter.eq('COLUMN', 'VALUE2'))
    .or(ee.Filter.eq('COLUMN', 'VALUE3')))

This is the same as the first filter but can be changed to look at different properties, for example. If you already have a simple list of values, inList is the right tool.

0

Follow these steps:

  1. Create variable containing the filter:

    var target_values = ee.Filter.inList('COLUMN', ['VALUE1', 'VALUE2', 'VALUE3']);

  2. Apply filter on the FeatureCollection:

    var features_select = ee.FeatureCollection("...").filter(target_values)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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