Skip to main content

Hi,

I would like to write a python function to extract the value a list attribute knowing its e.g. Working with a dgn file for instance, I would like to extract the value igds_linkage{ind_entity}.key where ind_entity is a know index.

I already wrote a script to do that but it requires 3 transformers and I want to optimize my workspace.

Thanks

Hi @arthy, a list element can be considered as an attribute whose name contains index number surrounded by curly brackets, so the point is how to construct the name using the index number. For example,  assuming that the attribute called "ind_entity" stores the index indicating the element to be extracted from the list, the PythonCaller with this script extracts the value of the element and save it to a new attribute called "key".

def processFeature(feature):
    index = feature.getAttribute('ind_entity')
    key = feature.getAttribute('igds_linkage{%s}.key' % index)
    feature.setAttribute('key', key)

Once you have understood the mechanism, you can also use the AttributeCreator.

0684Q00000ArJkpQAF.png

@Value(igds_linkage{@Value(ind_entity)}.key)

Hi @arthy, a list element can be considered as an attribute whose name contains index number surrounded by curly brackets, so the point is how to construct the name using the index number. For example,  assuming that the attribute called "ind_entity" stores the index indicating the element to be extracted from the list, the PythonCaller with this script extracts the value of the element and save it to a new attribute called "key".

def processFeature(feature):
    index = feature.getAttribute('ind_entity')
    key = feature.getAttribute('igds_linkage{%s}.key' % index)
    feature.setAttribute('key', key)

Once you have understood the mechanism, you can also use the AttributeCreator.

0684Q00000ArJkpQAF.png

@Value(igds_linkage{@Value(ind_entity)}.key)
@Takashi,

 

 

Thank you very much.

 

Before posting my question, I wrote exactly this syntax using the attribute creator but at the end, I was getting it a constant equals to <@Value(igds_linkage{@Value(ind_entity)}.key)>

 

Could you tell me what I was doing wrong when defing the transformer?

 

 


@Takashi,

 

 

Thank you very much.

 

Before posting my question, I wrote exactly this syntax using the attribute creator but at the end, I was getting it a constant equals to <@Value(igds_linkage{@Value(ind_entity)}.key)>

 

Could you tell me what I was doing wrong when defing the transformer?

 

 

@arthy, cannot specify the exact reason unless seeing the actual parameters setting, but a possible reason I can think of is that there could be a typo in the expression. Note that FME function names ('@Value' in this case) should be written in case-sensitive, and the expression will be treated as a constant string value if there was a typo including wrong case.

Reply