Solved

How to Testfilter attributes if they contain a word or not?

  • 28 January 2022
  • 2 replies
  • 124 views

Badge

I have a user parameter getting a string of comma separated words. I would like to use that as items/arguments to filter whether or not a feature attribute contain one of those words.

It would be to be used on about 10,000 features eventually with maybe up to 5 different words

 

I can get the user parameter to a list, and then to an attribute, but I can't find a way to use those to filter my dataset, either using Like, In, or Contains

 

Any idea how this can be done?

It's basically to filter whether a path does or not contain some words

filter_attributes

icon

Best answer by takashi 28 January 2022, 03:41

View original

2 replies

Userlevel 2
Badge +17

Hi @ts_84​ , I think the "Contain Regex" operator would help you.

StringReplacer: Replace every , (comma) within the parameter value with | (pipe). The resulting string can be interpreted as a regex "word1|word2|word3", which matches one of the words.

FeatureMerger: Merge the regex attribute to every feature read from CSV unconditionally.

Tester or TestFilter: Test if "_full_path" string contains a part that matches the regex, with the "Contain Regex" operator.

The attached screenshot illustrates an example of implementation.

contains-regex-operator-example

Badge

Hi @ts_84​ , I think the "Contain Regex" operator would help you.

StringReplacer: Replace every , (comma) within the parameter value with | (pipe). The resulting string can be interpreted as a regex "word1|word2|word3", which matches one of the words.

FeatureMerger: Merge the regex attribute to every feature read from CSV unconditionally.

Tester or TestFilter: Test if "_full_path" string contains a part that matches the regex, with the "Contain Regex" operator.

The attached screenshot illustrates an example of implementation.

contains-regex-operator-example

Thank you @Takashi Iijima​ , this works perfectly.

It's quite interesting to see Regex can work so simply like that too. And I didn't know a simple '1' would merge feature so easily either. Thanks for your valuable input

Reply