Skip to main content
Solved

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

  • January 28, 2022
  • 2 replies
  • 579 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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Celebrity
  • 7843 replies
  • 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
  • 21 replies
  • 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

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