Skip to main content

Hello,

 

I have a list called ''list'' of variable length depending on features.

 

I wanna assign as an attribute to each feature ''list(0) ; list(1) .... list(lenght(list))''

 

I tried writing a loop on the attribute manager but I didn't know how to use it well

 

Thanks for any possible help :)

Do you want to concatenate all element values in a list?

For example, if the list stores these values,

List ElementValue_list{0}._distance10_list{1}._distance20_list{2}._distance30
do you need to create this attribute?
Attribute NameValue_distances10;20;30

I'm not quite sure I understand what you want to do with the list, but have you looked at the ListExploder? It will create one feature for each list item, depending on the list length.

If you simply need a string with all the concatenated list values, have a look at the ListConcatenator.


Do you want to concatenate all element values in a list?

For example, if the list stores these values,

List ElementValue_list{0}._distance10_list{1}._distance20_list{2}._distance30
do you need to create this attribute?
Attribute NameValue_distances10;20;30
Thank you for your reply,

 

What I wanna do is : ''_list(0)._distance" + ''_list(0)._order" + ''_list(0)._DZ_Type" + ''_list(1)._distance" + ''_list(1)._order" + ''_list(1)._DZ_Type"

 

and so on until the end of the list.

 

The list have a different length depending on each feature

 


I'm not quite sure I understand what you want to do with the list, but have you looked at the ListExploder? It will create one feature for each list item, depending on the list length.

If you simply need a string with all the concatenated list values, have a look at the ListConcatenator.

Hello,

 

I have read its documentation but I think it's not the appropriate one what I wanna do is :

 

''_list(0)._distance" + ''_list(0)._order" +
''_list(0)._DZ_Type" + ''_list(1)._distance" + ''_list(1)._order" +
''_list(1)._DZ_Type"

 

and so on until the end of the list.

 

The list have a different length depending on each feature

 


Do you want to concatenate all element values in a list?

For example, if the list stores these values,

List ElementValue_list{0}._distance10_list{1}._distance20_list{2}._distance30
do you need to create this attribute?
Attribute NameValue_distances10;20;30
I'm still unclear what your requirement is. Could you please explain the conditions and requirement more specifically using source and destination tables, like the one I have posted.

 

 


Try something like this:

import fmeobjects

VALUE_DELIMITER = ','
ITEM_DELIMITER = ';'

def concat_list(feature):
    distances = feature.getAttribute('_list{}._distance')
    orders = feature.getAttribute('_list{}._order')
    types = feature.getAttribute('_list{}._DZ_Type')
    items = D]
    for values in zip(distances, orders, types):
        items.append(VALUE_DELIMITER.join(values))
    feature.setAttribute('result', ITEM_DELIMITER.join(items))

Play around with VALUE_DELIMITER and ITEM_DELIMITER until you get what you need.

Given the input lists:

0684Q00000ArKDTQA3.png

The result will be:

0684Q00000ArKJQQA3.png


Try something like this:

import fmeobjects

VALUE_DELIMITER = ','
ITEM_DELIMITER = ';'

def concat_list(feature):
    distances = feature.getAttribute('_list{}._distance')
    orders = feature.getAttribute('_list{}._order')
    types = feature.getAttribute('_list{}._DZ_Type')
    items = D]
    for values in zip(distances, orders, types):
        items.append(VALUE_DELIMITER.join(values))
    feature.setAttribute('result', ITEM_DELIMITER.join(items))

Play around with VALUE_DELIMITER and ITEM_DELIMITER until you get what you need.

Given the input lists:

0684Q00000ArKDTQA3.png

The result will be:

0684Q00000ArKJQQA3.png

Thank you very much

 

It worked

 

 


I'm still unclear what your requirement is. Could you please explain the conditions and requirement more specifically using source and destination tables, like the one I have posted.

 

 

I am sorry if my request was somehow unclear

 

I tried the python script above and it worked

 

I managed also meanwhile to complete the task using a combination of transformers

 

thank you very much

 

 


I'm still unclear what your requirement is. Could you please explain the conditions and requirement more specifically using source and destination tables, like the one I have posted.

 

 

Good to hear that you got a solution.

 

By the way, how the list attribute was created in your workflow? Depending on the condition, there could be a more simple solution without scripting.

 

For example, the list has been created with the Generate List option in a transformer, you can create a new attribute concatenating the three attribute values (_distance, _order, and _DZ_Zone) before creating the list, then just concatenate elements in the resulting list, with the ListConcatenator following to the transformer.

 

 


Reply