Question

Summarising a list

  • 8 March 2017
  • 9 replies
  • 29 views

Badge +1

Hi folks,

I've been scratching my head with this one a little.

I've got features each with an appended list of values (features that are within X distance). I would like to cycle through the the features and get the average value of matches stored (I have 7) within the list.

The list for each feature is not a fixed size, 0-50.

Any suggestions about what the best approach would be?


9 replies

Badge

Hi,

1. Make sure every feature does have a unique id

2. Use ListExploder to create features for every list element

(you might want to take a look at 'Conflict Resolution')

3. Use StatisticsCalculator to calculate average value grouped by id

Userlevel 4

You can get the list average using a ListSummer and a ListElementCounter, followed by an ExpressionEvaluator with something like

@Value(_sum)/@double(@Value(_element_count))

This avoids using the ListExploder, which has a tendency to consume a lot of memory and slow down your translation considerably if you have many features and/or list elements. It also leaves you with the same number of output features and doesn't require a unique ID.

Badge

You can get the list average using a ListSummer and a ListElementCounter, followed by an ExpressionEvaluator with something like

@Value(_sum)/@double(@Value(_element_count))

This avoids using the ListExploder, which has a tendency to consume a lot of memory and slow down your translation considerably if you have many features and/or list elements. It also leaves you with the same number of output features and doesn't require a unique ID.

Nice suggestion! I will use this one myself in the future :)

 

 

Userlevel 4
Badge +25

Alternatively I think you can avoid exploding (an rebuilding) the list like this:

  1. Use a ListElementCounter to count the number of list elements, store that in an attribute (e.g. _elements)
  2. Use a ListSummer to sum the value of one list attribute, store that in a new attribute (e.g. _sum)
  3. Your average will be _sum divided _elements
Userlevel 4
Badge +25

You can get the list average using a ListSummer and a ListElementCounter, followed by an ExpressionEvaluator with something like

@Value(_sum)/@double(@Value(_element_count))

This avoids using the ListExploder, which has a tendency to consume a lot of memory and slow down your translation considerably if you have many features and/or list elements. It also leaves you with the same number of output features and doesn't require a unique ID.

Aaah, you beat me once again... :)

 

 

Userlevel 4
Aaah, you beat me once again... :)

 

 

On the other hand, I think your suggestion is a brilliant one ;-)
Userlevel 4
Badge +25
On the other hand, I think your suggestion is a brilliant one ;-)
Almost as brilliant as yours ;)

 

 

Badge +16

And yet another option is.....the ListStatisticsCalculator from the FME Hub.

Badge +1

You can get the list average using a ListSummer and a ListElementCounter, followed by an ExpressionEvaluator with something like

@Value(_sum)/@double(@Value(_element_count))

This avoids using the ListExploder, which has a tendency to consume a lot of memory and slow down your translation considerably if you have many features and/or list elements. It also leaves you with the same number of output features and doesn't require a unique ID.

Thanks @jeroenstiers and @david_r , both great suggestions, I went with the latter option as I need this thing to scale up to handle lots of data. 

 

 

I got to say, FME Knowledge Center is a great resource. I always get multiple good answers, really quickly too! 

 

 

Thanks for all the help folks!

Reply