Performs a mathematical calculation on an expression that consists of FME Feature Functions, String Functions, Math Functions, and Math Operators. The operands and function arguments consist of attributes on the input feature, constant literals, published and private parameters, as well as functions and operators. You can use the GUI interface to set up an expression, but you can also edit an expression manually. The results of the expression are stored inside attributes specified by user.
There are two main uses for ExpressionEvaluator:
- Apply one expression to one attribute
- set Evaluation Mode to either Create New Attribute or Overwrite Existing Attributes, but only overwrite one attribute.
- expression might use @Value() function, but doesn’t use @CurrentAttribute() function.
- For example, if you want to add 1 to the values in a single attribute, use the expression @Value(attr) + 1, set Evaluation Mode to Overwrite Existing Attributes, and set Attributes to Overwrite to attr.
- Apply one expression to multiple attributes
- set Evaluation Mode to Overwrite Existing Attributes and only select the attributes that will be overwritten with new values. Unselected attributes will keep their original values.
- expression might use @CurrentAttribute() function, but typically won’t use @Value() function.
- For example, if you want to add 1 to the values in a few attributes, use the expression @CurrentAttribute() + 1, set Evaluation Mode to Overwrite Existing Attributes, and select the attributes to apply this to.
Note: If you want to apply different expressions to different attributes, you can either use multiple ExpressionEvaluators, or use a single AttributeCreator.
The supported operators are a subset of the operators permitted in C expressions. They have the same meaning and precedence as the corresponding C operators with one notable exception: they support numeric nulls.
Expressions are expected to yield numeric results. FME supports numeric nulls, which permit expressions to return null as result. For example, the expression 8.2 + 6 returns 14.2, whereas the expression @Value(nullAttr) * 1 returns null.
Note: It is easy to build an invalid expression, so you may want to double check your expression, especially if you are using an @Value(attr) within the expression, as some attributes may have unexpected values. If an expression is invalid, then the corresponding result attribute will be set to null. When the result is null, the following attributes will be set to indicate what went wrong, and where:
Inside the ExpressionEvaluator, null, missing, and empty string attributes are all considered to be null. Thus, @Value(attr) * 1 will result in null if attr is not present on the feature or is an empty string.
Choose Create New Attribute to evaluate the specified expression and have the calculated results put in the specified attribute.
Choose Overwrite Existing Attributes to evaluate the specified expression once per selected attribute. The result of the evaluation will be put back into the attribute.
This is the attribute that will contain the result. Use the default name, or type a new name.
This parameter allows the same expression to be evaluated, once per selected attribute. For each attribute specified, the result of the expression will be stored into that attribute.
If the expression needs the value of the current attribute, retrieve it using the function @CurrentAttribute(). For example, if the incoming feature has attributes X and Y, and we wish to increment each by one, select both attributes, and set the expression to @CurrentAttribute() + 1. This will set the attribute X to X+1 and Y to Y+1.
If using @Value(attr) and overwriting attr as well as other attributes, then the results will be iterative. After attr is overwritten with a new value from the expression, all subsequent applications of @Value(attr), when processing the remaining attributes, will use that new value of attr, and not its original value. The order of the attributes will affect the outcome.
For example, if you have the following attributes and values:
attr0 = 0
attr1 = 1
attr2 = 2
attr3 = 3
and the expression:
@Value(attr1) + 1
When all four attributes are selected to overwrite, the result will be:
attr0 = 2 (calculates 1+1 and overwrites attr0)
attr1 = 2 (calculates 1+1 and overwrites attr1)
attr2 = 3 (uses new value of attr1, so 2+1)
attr3 = 3 (uses new value of attr1, so 2+1)
For more information, see the Arithmetic Editor.
An expression consists of a combination of operators and operands, functions and arguments, and parentheses. White spaces may be used between the operands, operators, and parentheses, and are ignored by the expression processor.
Where possible, operands are interpreted as integer values. Integer values may be specified in decimal, such as 123, in octal if the first two characters of the operand are 0o (zero followed by the letter o), or in hexadecimal if the first two characters of the operand are 0x.
If an operand does not have one of the integer formats given above, then it will be treated as a floating point number, where possible. Floating point numbers may be specified in any of the ways accepted by an ANSI-compliant C compiler, except that "f", "F", "l", and "L" suffixes are not permitted in most installations. For example, all of the following are valid floating point numbers: 2.1, 3., 6e4, 7.91e+16. If no numeric interpretation is possible, then an operand is left as a string and should cause the expression to evaluate to null.
Operands and arguments may be specified in the following ways:
- As a constant numeric value, either integer or floating point.
- As the value of an FME feature attribute, using the @Value() or @CurrentAttribute() notation. The attribute's value is used as the operand or argument.
- As an FME feature function, such as @Area(). The function is evaluated and the result used as the operand or argument.
- As a mathematical function, such as @sin(1).
FME Feature Functions
For more information, see FME Feature Functions.
For more information, see String Functions.
For more information, see Math Functions.
For more information, see Math Operators.
FME Knowledge Center has a good example of the ExpressionEvaluator.
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
The mathematical operators in the ExpressionEvaluator are based on the Tool Command Language (Tcl) expr command.1Tcl and its documentation is copyrighted by the Regents of the University of California, Sun Microsystems, Inc. and other parties. However, the authors have granted permission to any party to reuse and modify the code and documentation, provided the original copyright holders are acknowledged.
Search FME Knowledge Center
Search for samples and information about this transformer on the FME Knowledge Center.