Skip to main content

I know how to use ListConcatenator in order to concatenate all list values into a single attribute. However, what can I do if my feature has multiple list attributes? I want to concatenate all values of all lists into respective single attributes. The resulting single attributes should have the names of the original list. I don' know the names of the lists in advance.

Examples:

colour{0} = 2

 

colour{1} = 3

 

colour{2} = 2

single attribute colour = 2,3,2

shape{0} = triangle

 

shape{1} = square

 

shape{2} = circle

single attribute shape = triangle,square,circle

Thanks for any help

I guess you can use Attribute Manager for this. Create new Output Attribute value as "single attribute sahpe" and add in "Attribute Value" like below.

@Value(shape{0}) @Value(shape{1}) @Value(shape{2})

I hope it will work.


In a dynamic scenario, where you don't know the names of the lists, I can't think of a way to do this other than via scripting.

Something along the lines of

import fme
import fmeobjects
import re

def processFeature(feature):
    # get all the unique list names
    rootNames =set()
    attrList= feature.getAllAttributeNames()
    for attr in attrList:
        list = re.search('(.*){o0-9]*}(.*)', attr)
        if list:
            listName = list.group(1)+"{}"+list.group(2)
            rootNames.add(listName)
   
    #get the values for each unique list and concatenate them
    for listAttr in rootNames:
        listVal = feature.getAttribute(listAttr)
        concatVal = ','.join(listVal)
        newAttr = listAttr.replace('{}','')
        
        #add the attribute to the feature
        feature.setAttribute(newAttr, concatVal)
 

There is an existing enhancement request for this behaviour. It's PR#15122 - the low number tells you how old that request is. Sadly I don't think there have been a lot of requests. But I will add a link to this thread and see if I can increase the priority.


@jdh

Great - your python script does the trick. Thanks a lot!!!!!

Thanks to the others as well-


There is an existing enhancement request for this behaviour. It's PR#15122 - the low number tells you how old that request is. Sadly I don't think there have been a lot of requests. But I will add a link to this thread and see if I can increase the priority.

Arrived here this morning after thinking there must be an alternative to many listconcatenators or a python script but seems not, I thought it was just lack of coffee and my brain not being awake!


Reply