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.

3 Answers 3

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)

0
var country = countries.filter(
  ee.Filter.or(
    ee.Filter.eq('ADM0_CODE', 240),
    ee.Filter.eq('ADM0_CODE', 264),
    ee.Filter.eq('ADM0_CODE', 139)
  )
);
1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 14 at 20:09

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.