FME Form: 2024.2
Operating on List Attributes
List transformers allow you to work with list attributes.
See the Attributes category in the Transformer Gallery:
Convert List Elements into Regular Attributes
You can use the ListIndexer transformer to convert elements of a structured list into full attributes, and the index can be either a number you provide directly, or one that you extract from another attribute on the feature.
For example, if a feature has these attributes on it:
overlaps{0}.direction -1
overlaps{0}.line_id 50
overlaps{1}.direction 1
overlaps{1}.line_id 22
overlaps{2}.direction 1
overlaps{2}.line_id 40
overlaps{3}.direction -1
overlaps{3}.line_id 12
and it passes through a ListIndexer with an index of 2, then the feature emerges with these attributes:
direction 1
line_id 40
overlaps{0}.direction -1
overlaps{0}.line_id 50
overlaps{1}.direction 1
overlaps{1}.line_id 22
overlaps{2}.direction 1
overlaps{2}.line_id 40
overlaps{3}.direction -1
overlaps{3}.line_id 12
Note that the list itself was not changed, but the attributes at index 2 were converted from the list to become regular attributes.
Other List Operations
Examples of other list operations include:
- Searching a list (ListSearcher) for a particular value
- Counting the number of elements in a list (ListElementCounter)
- Concatenating all the elements of a list into a single attribute (ListConcatenator)
- Exploding a list by creating a new feature for each element in the list and adding its attributes (ListExploder).
The ListExploder is sometimes used to write new features to a relational database table. In this way, the 1 to many nature of the data model can be preserved by writing the original feature to one table, and the exploded list element features to another table. As long as there is a key field that can be used to rejoin them, the relationship is maintained. Furthermore, there is no requirement that the format used to store the list elements be the same as the format used to store the master feature– very often the exploded list element records are stored in a database table and the master feature is stored in a GIS or CAD system.
Another use of the ListExploder is to make copies of the feature for each list element, and then these copies may be sorted by some criteria (such as length or area), and lastly the elements run through a DuplicateRemover transformer to select only the largest or smallest feature that was originally an element of a list.
View an example problem solving exercise
Other Considerations
When operating on list attributes, keep in mind the following:
- List attributes can also be displayed in an Inspector transformer, or by attaching a Logger transformer.
- Remove lists, especially ones with many items, as soon as you are finished with them. This will save memory and processing time and will reduce the clutter of your workspace.
- Very few output formats offer support for lists. In most cases, if you want to output the data to such a format, you will need to manage the list first.