Skip to main content
Solved

getting the value of a list attribute with python

  • December 29, 2016
  • 3 replies
  • 153 views

arthy
Contributor
Forum|alt.badge.img+8

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

Best answer by takashi

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)
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.

3 replies

takashi
Celebrity
  • Best Answer
  • December 29, 2016

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)

arthy
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • December 29, 2016

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
Celebrity
  • December 30, 2016
@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.