Question

Calculation in a list

  • 9 February 2014
  • 3 replies
  • 12 views

Hello,

 

 

I have a many objetcs with a list (LIST_A) with N elements and a list attribute ATTR_1, i would like to know a smart way to do a expression evaluation on ATTR_1 on all elements of the list (without doing list explode doing the calculation with expression evaluator and doing a list builder).

 

 

Thanks in advance.

3 replies

Userlevel 4
Badge +13
Depending on the expression needed the list based transformers can be used. Although the possibilities are not great  certain statistics and simple expressions can be done .
For example a simple one, like multiply by 2 the ATTR_1 on all elements of the list.

 

 

Userlevel 2
Badge +17
I would use PythonCaller when it's desirable to avoid list explosion.

 

-----

 

# Python Example

 

# Assume every list element can be interpreted as numeric value.

 

import fmeobjects

 

def multiplyBy2(feature):

 

    for i, value in enumerate(feature.getAttribute('MyList{}')):

 

        feature.setAttribute('MyList{%d}' % i, float(value) * 2)

 

-----

Reply