Removing List Element Example

From fmepedia


Some time ago we had a question in FMETalk about removing a list element - http://groups.google.com/group/fmetalk/browse_thread/thread/ae5aab16356587c9#.

We know that FME needs better list handling capabilities and we hope that the changes will come soon, but for now we can use Python for some list manipulations.

Here is a simple Python code that takes a list consisting of three elements (MyList()) and makes a new list (NewList()) that has one element less than the original list. The idea is to read only those elements from the source list that will be needed in the new one:

import pyfme 

class ListElRemover(object):
    def __init__(self):
        self.count_features = 0
        self.logger = pyfme.FMELogfile()

    def input(self,feature):
        mylist1 = feature.getListAttribute('MyList{}.attr1')
        mylist3 = feature.getListAttribute('MyList{}.attr3')
        feature.setListAttribute('NewList{}.attr1', mylist1)
        feature.setListAttribute('NewList{}.attr3', mylist3)
        self.pyoutput(feature)	

Here is the workspace where this code is used. Note that you have to make changes in the Python code to adjust the workspace for your data.

Attached Files
filesizedate
index.php------
listelremover.fmw50.5 kB12/18/08
User Comments Add a new comment