1

Is there a more elegant way than calling each filter in the list? It looks like ee.Filter.or wants separate arguments, not a list.

Using var NEfilter = ee.Filter.or(filterlist) gives the error:

Filter.or, argument 'filters': Invalid type. Expected: List< Filter >. Actual: List< List< Filter >>

https://code.earthengine.google.com/dffaf31424c0b5cbf2fd69187523eae0

var AllStates    = ee.FeatureCollection('ft:1fRY18cjsHzDgGiJiS2nnpUU3v9JPDc2HNaR7Xk8');   // U.S. States
print (AllStates);

var NameFcn = function(name) {
  return ee.Filter.eq('Name', name);
  };

var NE_list = ["Massachusetts", "Connecticut", "Rhode Island", "Maine", "Vermont", "New Hampshire"];
var filterlist = NE_list.map(NameFcn)

print(filterlist)

var NEfilter = ee.Filter.or(filterlist[0],filterlist[1],filterlist[2],filterlist[3],filterlist[4],filterlist[5]);

var NEStates = AllStates.filter(NEfilter);
print(NEStates)

1 Answer 1

2

Not 100% sure if this is what you are looking for:

var AllStates    = ee.FeatureCollection('ft:1fRY18cjsHzDgGiJiS2nnpUU3v9JPDc2HNaR7Xk8');   // U.S. States
print (AllStates);

var NameFcn = function(name) {
  return ee.Filter.eq('Name', name);
  };

var NE_list = ["Massachusetts", "Connecticut", "Rhode Island", "Maine", "Vermont", "New Hampshire"];
var filterlist = NE_list.map(NameFcn)

var filtered = AllStates.filter(ee.Filter.inList('Name', NE_list))
print(filtered)
1
  • Yes! I even saw that one and the word "metadata" in the docs confused me -- assumed it was for image collections.
    – J Kelly
    Commented Nov 18, 2019 at 17:07

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.