2014-03-25

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 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{})')):
feature.performFunction('@Dimension(2)')
# The line above can be replaced with:
# feature.setDimension(fmeobjects.FME_TWO_D)
feature.performFunction('@ZValue(_z{})')
feature.setAttribute('_result', 'success')
else:
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.