Skip to content

Custom transformer for FME® that enables a user to extract key-value pairs in lists as new attributes

License

Notifications You must be signed in to change notification settings

GeoSander/fme-listkeyvaluepairextractor

Repository files navigation

FME® ListKeyValuePairExtractor

About

The ListKeyValuePairExtractor creates new attributes based on a list of keys (attribute names) and a list of values.
For example, a feature might contain the following list elements:

list{0}.name = 'StringData'
list{0}.data = 'Test Value'
list{1}.name = 'IntData'
list{1}.data = 32536
list{2}.name = 'FloatData'
list{2}.data = 23.67

If the user sets the Attribute Name List to list{n}.name and the Attribute Value List to list{n}.data, the transformer will add the following attributes to the output feature:

StringData = 'Test Value'
IntData = 32536
FloatData = 23.67

IMPORTANT

In the example above, you can fill in any integer for list element n. Due to the fact that FME does not support nested lists as an input parameter for custom transformers, you will actually have to specify it as a list attribute, using FME's List Element Selection dialog.
This means you can select regular attributes for the Attribute Name List and Attribute Value List parameters, but that will result in an error. It also means that if you have a basic unnested list, the index you specify does not matter. The ListKeyValuePairExtractor will simply fetch the complete list.

For example, if you want to use all the values in list{}.name as your Attribute Name List, you could set the input parameter to list{0}.name. If there are 3 elements in this list, the transformer will fetch list{0}.name, list{1}.name and list{2}.name. But this will also be the case if you set it to list{2}.name, for example.

However, if you want to use all the values of list{}.nestedlist{}, the index of the parent list{} matters and should exist! For example, if you set the Attribute Name List parameter to list{3}.nestedlist{0}, only the nestedlist{} elements within list{3} will be used.

Please note that the created attributes will not be exposed. You can use an AttributeExposer afterwards to achieve that.

Notes

  • Also available on FME Hub for convenient installation.
  • This transformer has been tested on Python 2.7 and 3.4.
  • Released under GNU General Public License v3.0.
  • If you notice a bug or desire a new feature, please contact me. Or make a pull request!
  • The test workspace is used for testing and provides some examples.

Usage

Attribute Name List
Specify the list attribute that should be used to extract the attribute names (keys). The list can have missing elements (in which case no attribute will be written), but the list should be in the same order as the Attribute Value List. Please read the overview section of this documentation for more information.

Attribute Value List
Specify the list attribute that should be used to extract the attribute values. If a value is missing or null, a warning will be shown in the log. The value list does not need to be of the same size as the Attribute Name List, but if the created pairs should match, the list has to be in the same order. Please read the overview section of this documentation for more information.

Conflict Resolution
If one or more of the Attribute Name List elements already exist as a feature attribute, setting this value to "Keep Original Attributes" will prevent the attribute values from being overwritten by the Attribute Value List elements.

About

Custom transformer for FME® that enables a user to extract key-value pairs in lists as new attributes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published