1

I have a FeatureCollection ('results'), with several cloud probability values as properties (from different dates).

These properties are called "CLD01", "CLD02",...

I want to filter my collection in a way that only features remain which have 0 cloud probability at any given time, which means each of the "CLD" has to be 0.

I know how to filter my Feature collection by ONE of them:

var results_clear = results.filter(ee.Filter.eq('CLD01', 0))

I found here that I can filter my collection by multiple properties using this approach:

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

but it does not work with ".and" (also not with ".or", I tried it)

This is what I did:

var results_clear = results.filter(ee.Filter.eq('CLD01', 0)).and(ee.Filter.eq('CLD02', 0))

and I get this error:

Line 256: results.filter(...).and is not a function

I feel like this should be an easy thing to do but somehow...it isn't.

1 Answer 1

2

You can make use of ee.Filter.and to filter using both properties.

var results_clear = results.filter(ee.Filter.and(ee.Filter.eq('CLD01', 0),
                                                 ee.Filter.eq('CLD02', 0)));
3
  • So I was right about one thing: it actaully IS easy. Thanks :)
    – pottsbill
    May 13, 2023 at 9:18
  • 1
    Actually, multiple filters are all anded anyway. So you could just do: results.filter(ee.Filter.eq('CLD01', 0)).filter(ee.Filter.eq('CLD02', 0)) or better: results.filter("CLD01 == 0 && CLD02 == 0") May 13, 2023 at 17:25
  • I also tried your method, Noel, and it worked fine for just those two properties but when I add the whole bunch of properties I want to filter on, I get an error. You might notice, I changed my operator to != (as I changed sth in the workflow) but when I try your proposed approach, it work for 2 properties (CLD01 and CLD02 but not for all of them: FeatureCollection (Error) Collection.filter: Expression parse error at character 118: 'CLD01 != 0 && CLD02 != 0 && CLD03 != 0 .......' I checked for spelling errors and the usual suspects but it is not working for my whole list of specifications.
    – pottsbill
    May 15, 2023 at 19:28

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.