FME Function and PythonCaller

(FME 2014 build 14235)

I tested some FME Functions using the TclCaller in the previous article, but any FME Function can be called also in a Python script embedded in a PythonCaller.
FMEFeature.performFunction() method can be used to call any FME Function on the feature.
Here I give examples of Python edition.

Example 1: Merge Multiple List Attributes
Assume input feature has two list attributes named "_list1{}", "_list2{}". This script creates a new list attribute named "_merged{}" by merging them and removes the original lists.
import fmeobjects
def mergeLists(feature):

Example 2: Remove Duplicate Vertices from Polygon
This script identifies geometry type of input feature and removes duplicate vertices when the type is fme_polygon.
import fmeobjects
def removeDuplicateVertices(feature):
    if feature.performFunction('@GeometryType()') == 'fme_polygon':

Example 3: Set Z Values to Coordinates
Assume input feature has a list attribute named "_z{}" storing numeric values. This script set Z values stored in the list to coordinates of the feature when number of the list elements is equal to number of the coordinates.
import fmeobjects
def setZValues(feature):
    n = int(feature.performFunction('@NumCoords()'))
    # The line above can be replaced with:
    # n = feature.numCoords()
    if 0 < n and n == int(feature.performFunction('@NumElements(_z{})')):
        # The line above can be replaced with:
        # feature.setDimension(fmeobjects.FME_TWO_D)
        feature.setAttribute('_result', 'success')
        feature.setAttribute('_result', 'failure')

I've never used the FMEFunctionCaller transformer, performFunction method (Python) and FME_Execute procedure (Tcl) in any practical workspace, since the documentation about FME Functions had not been accessable.
But now, the documentation has become available. FME Functions could be used effectively in some cases.

No comments:

Post a Comment