Question

Is there a generic way to reference attribute name (not the value held by the attribute) of a selected attribute in an AttributeManager condition?


I want to use the same condition for each attribute, with the only variation being the attribute/field name of the attribute to which the condition applies.


8 replies

Badge +10

Yes, you can use @CurrentAttribute() so you can then use the same conditional statement multiple times without having to edit

image

Userlevel 3
Badge +26

Yes, you can use @CurrentAttribute() so you can then use the same conditional statement multiple times without having to edit

image

Brilliant, thank you for that!

Yes, you can use @CurrentAttribute() so you can then use the same conditional statement multiple times without having to edit

image

Thanks ebygomm, however my understanding is that "@CurrentAttribute()" refers to the value held by the attribute and not the attribute name. In your example you're testing whether "Attribute1" or "Attribute2" holds a value of "10". For my scenario, I'm hoping there's a similar method in relation to the current attribute name (i.e. "Attribute1", "Attribute2" - without specifying "Attribute1" or "Attribute2" in the condition statement).

Badge +10

I'm struggling to understand what you are trying to do. At the point you are writing the condition you know the attribute name, it's not variable.

 

If you want to do something to all attributes where the name matches certain criteria, you could look at the NullAttributeMapper, which despite the name will let you apply the same condition to multiple attributes depending on them matching a regex condition for example

The attached screen print shows an example of the condition that I would like to use against different attributes. The text highlighted in yellow is where the attribute name is specified. Rather than changing this text each time the condition is used, I was wondering if there's a was to generically reference the current attribute name. I need to use the condition many times for many different attributes (around 1,000). If I could generically reference the name of the current attribute, it'd make my job much easier. The alternative is to modify this part of the condition for each different attribute.

Userlevel 3
Badge +26

I think you will need to incorporate the AttributeExploder somehow. You will likely need to use the List option, and Keep Attributes. This transformer will allow you to test for the string in the attribute names, not just the attribute values. It's hard to say exactly what the workbench needs to look like, but this should point you in the right direction.image

Badge +10

The attached screen print shows an example of the condition that I would like to use against different attributes. The text highlighted in yellow is where the attribute name is specified. Rather than changing this text each time the condition is used, I was wondering if there's a was to generically reference the current attribute name. I need to use the condition many times for many different attributes (around 1,000). If I could generically reference the name of the current attribute, it'd make my job much easier. The alternative is to modify this part of the condition for each different attribute.

Ah, now I understand. I'd probably resort to python for  this

import fme
import fmeobjects
 
def processFeature(feature):
    attrs = feature.getAllAttributeNames()
    #get all attribute names as a list
    label = feature.getAttribute('GISLabel')
    #get value of attribute GISLabel and store as label
    for a in attrs:
        #for each attribute name in the list, if the attributename equals value of label
        if a == label:
            #set the value of the attribute to the value of the attribute AttributeDesc
            feature.setAttribute(a,feature.getAttribute("AttributeDesc"))
        else:
            pass

 

Thanks ebygomm and ddbrocatto. I decided to give up trying to use the attribute name. Instead I modified my workflows such that the attributes first held their respective names as values and then used @CurrentAttribute() in the subsequent AttributeManager condition to replace the value with the value I needed. It allows me to use the same condition multiple times, so ultimately achieves the goal.

Reply