Have you ever needed to do arithmetic on every element of a list? Perform complicated list analysis not available in the existing list transformers? Come take a technical look at 3 methods for manipulating lists in FME, their ease of setup and relative efficiency.
3. UNMATCHED ON A GLOBAL SCALE
COUNTRIES
35+
TRAINING CENTRES
65+
LOCATIONS
160
EMPLOYEES
8,000+
4. Lists
Lists are everywhere in FME:
• 15 transformers are
dedicated to list manipulation
• Over 80 transformers can
produce lists
But there’s no such thing as a
list data type in FME
Working with
Wait…
What?
5. With a specific naming convention
Lists are simply attributes
As long as the attribute name
contains {#} FME will treat it as a list.
You can use regular attribute
manipulators to create a list.
6. Vocabulary
A Little
Basic listSimple
Complex
Nested
List with
sub-elements
_animals{0} Cat
_animals{1} Dog
_pets{0}.Name Felix
_pets{0}.Type Cat
_pets{1}.Name Fido
_pets{1}.Type Dog
Multi-level list _relationships{0}.pass{0} Contains
_relationships{0}.pass{1} Intersects
_relationships{1}.pass{0} Intersects
_relationships{2}.pass{0} Intersects
7. Processing Every
List Element
There are lots of situations
where you might want to
process every list element
individually.
We’re going to examine
three different methods of
doing so.
The Classic
The Loop
The Python
8. The Classic
Pros
• Easy to setup
• Access to all transformers
Cons
• Loss of geometry (ListBuilder) or
duplication of geometry (Aggregator)
• Special handling required for non-list
attributes
• Does not scale well
9. The Classic
Methodology
1. Create unique ID
2. Explode the list: ListExploder
3. Perform the manipulation(s) on each feature
4. Recombine the list: ListBuilder or Aggregator
Grouping by unique ID
5. Restore geometry/non-list attributes
10. The Loop
Pros
• No issues with
geometry or non list
attributes
• More efficient than
classic method for
shorter lists
Cons
• Requires a linked
custom transformer if
element manipulation
involves blocking
transformers
• Inefficient with large
lists
11. The Loop
Methodology
1. Create a Custom Transformer
2. Create an attribute to hold the current index
3. Check the index is less than the length of the list
4. Perform the manipulation(s) using the current index
5. Increment the index
6. Loop to Step 3
12. Place your screenshot here
The Python
Pros
• Extremely efficient
• No attribute or
geometry issues
Cons
• Requires coding
skills
• Not all
transformers have
an equivalent
python method
13. Place your screenshot here
The Python
Methodology
1. Get the list
attribute
2. Perform the
manipulations
3. Set the list
attribute
4. Expose the
list attribute if
creating a
new list
Is it really that
simple?
14. Place your screenshot here
Gotchas: Types
feature.getAttribute()
will often return
numbers as strings.
You may have to
explicitly cast
variables back and
forth between types.
15. Place your screenshot here
Gotchas: Types
feature.setAttribute()
will not work directly
on numeric lists.
You can either cast
the list to string or
use a for loop.
16. Place your screenshot here
Gotchas: Nested List
Nested lists cannot be
accessed directly.
You can retrieve the
sublist for a specific
element of the main
list, or a specific
element of the sublist
for all elements of the
main list.
To use all elements of
both lists,you need to
loop through the main
list.
But the length of the
list cannot be accessed
directly.
17. Place your screenshot here
Gotchas: Nested List
Hybrid
Solution
• Use a
ListElementCounter
prior to the
PythonCaller
• Use a “for i in
range” loop to
retrieve the subList