Skip to main content
Solved

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

  • January 28, 2022
  • 2 replies
  • 428 views

Forum|alt.badge.img

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

Best answer by takashi

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

View original
Did this help you find an answer to your question?

2 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • January 28, 2022

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


Forum|alt.badge.img
  • Author
  • January 28, 2022
takashi wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings