Skip to main content
Question

Feature contains elements from two lists


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor

I have a set of lists

 

 

_option1{0}=A

 

_option1{1}=B

 

_option1{1}=C

 

 

_option2{0} = X

 

_option2{0} = Y

 

_option2{0} = Z

 

 

and values

feature 1

 

_list{0} = A3

 

_list{1} = 7B2

 

 

feature 2

 

_list{0} = 4X

 

 

feature 3

 

_list{0} = C2

 

_list{1} = 3Z

 

 

 

I need to identify only those features that whose list elements contain items from both _option1{} and _option2{} .

 

 

In the above example, that would be feature 3.

 

 

The data list values are not an exact match to the values in the option lists, just contain them.

 

There can be any number of elements in the data list.

 

The options are the same for every feature.

 

 

4 replies

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • June 10, 2019

Hi @jdh,

You can use a combination of ListConcatenator and AttributeCreator to concatenate the _option lists into regex expressions (ie. [XYZ]). Then use two StringSearchers to search _list by those expressions. I am attaching a workspace to illustrate.

searchlist.fmw


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • June 10, 2019

Create two attributes in python that are populated depending on whether there is a match between each list, then you can test for where match_list1 or match_list2 are both true.

import fme
import fmeobjects

def processFeature(feature):
    match1 = ['A','B','C']
    match2 = ['X','Y','Z']
    list = feature.getAttribute('_list{}')

    for x in list:
        if any(y in x for y in match1):
            feature.setAttribute('match_list1','true')
        if any (y in x for y in match2):
            feature.setAttribute('match_list2','true')
        

 


jdh
Contributor
Forum|alt.badge.img+28
  • Author
  • Contributor
  • June 10, 2019
daveatsafe wrote:

Hi @jdh,

You can use a combination of ListConcatenator and AttributeCreator to concatenate the _option lists into regex expressions (ie. [XYZ]). Then use two StringSearchers to search _list by those expressions. I am attaching a workspace to illustrate.

searchlist.fmw

Unfortunately the actual codes are not single characters, so I end up with many false positives.


jdh
Contributor
Forum|alt.badge.img+28
  • Author
  • Contributor
  • June 10, 2019
ebygomm wrote:

Create two attributes in python that are populated depending on whether there is a match between each list, then you can test for where match_list1 or match_list2 are both true.

import fme
import fmeobjects

def processFeature(feature):
    match1 = ['A','B','C']
    match2 = ['X','Y','Z']
    list = feature.getAttribute('_list{}')

    for x in list:
        if any(y in x for y in match1):
            feature.setAttribute('match_list1','true')
        if any (y in x for y in match2):
            feature.setAttribute('match_list2','true')
        

 

I had tried the 'any'  but got lost in triple for loops,  running two separate searches and testing for True and True  is the piece I was missing.


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