RasterExpressionEvaluator
Evaluates expressions on each cell in a raster, such as algebraic operations or conditional statements.
Input Ports
Features are input through ports A and B. The cardinality of the input is required to be one of the following cases:
- one or more As, no Bs
- one A, one or more Bs
Note that the B port is only visible if Two Rasters is specified in the Mode parameter.
When both A and B features are provided, the single A input will be paired with each B input.
Note the following restrictions on input features:
- Input features must have raster geometry.
- All paired rasters must have the same number of rows and columns.
- Either all bands used in the same expression must have the same nodata value, or all bands used in the same expression must have no nodata value.
- No band may have a palette.
Output Ports
The output of the transformer will be a single raster feature per input pair. The output rasters will have n bands, where n is the number of interpretation/expression pairs, specified through the Band Expression(s) parameter.
Parameters
This parameter specifies how many types of input features are allowed. If One Raster is selected, then only A input features are permitted. If Two Rasters is selected, then A and B input features are permitted.
If any Group By attributes are given, then each group will be treated independently. This allows a single transformer to operate on multiple pairs of As and Bs. Note that this parameter is not applicable when the Mode is One Raster; in that case, each raster is considered individually and there are no groupings.
This table is used to specify how to calculate and interpret one or more bands in the output raster. Each row of the table represents a different band in the output raster.
The first column of the table indicates how each band is to be interpreted. Valid interpretations are Preserve, Auto, Gray8, Gray16, Red8, Red16, Green8, Green16, Blue8, Blue16, Alpha8, Alpha16, UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, Real32, Real64. A value of Preserve means that if all input bands share the same interpretation, the output band will preserve that interpretation. If the input bands do not share the same interpretation, Preserve is the same as Auto. A value of Auto means the output interpretation will be automatically determined based on the data types used to perform the calculations.
The second column of the table indicates the expression used to calculate each output band. A simple expression might be something like "(A[0] + B[0])/2", which calculates the average of the first band of input A and input B. Note that this parameter is case-sensitive.
When pairs of inputs are being operated on (i.e., the expression references both input A and B), the output feature will have all the attributes from both feature A and B. If the same attribute exists on both input features, then the attribute value from feature B will be preferred. Similarly, the output raster will have the properties of raster B. When only a single input is being operated on (i.e., the expression only references input A), the feature attributes and raster properties will remain unchanged.
Usage Notes
Note that when converting between different data types, a Bounded Cast is used. As a result, when a calculated value does not fit in the specified destination interpretation, the corresponding destination value will either be set to the minimum or maximum value possible in the destination data type.
Constructing Expressions
The Arithmetic Editor - Raster Expression is available via the Expression ellipsis (...) button to assist in the construction of expressions.
Expression Syntax
|
Means... |
---|---|
|| | Or |
&& | And |
== | Equal |
!= | Not equal |
< | Less than |
> | Greater than |
A[x] | Band x of raster feature A |
B[x] | Band x of raster feature B |
Bands start counting at zero (so a three-band raster is A[0], A[1], and A[2]).
A statement can be as simple as these:
255 | Set the value of the current cell to be 255. |
A[0]+1 | Set the value of the current cell to be Raster A, band zero, plus 1. |
"if" statements allow a value to be set depending on conditions, in the form if (conditions, pass value, fail value):
if (A[0] < 255, 200, 255) | If Raster A, band zero is less than 255, then set the current cell to 200, else leave it as 255. |
if (A[0]<50 || A[1]<50 || A[2]<50, 0, 255) | If Raster A, band zero is less than 50 OR band one is less than 50 OR band two is less than 50, then set the current cell to 0, else set it to 255. |
Bands in two raster features can be referenced in the statement:
if (A[0]!=B[0] && A[0]<255, 0, A[0]) | If Raster A band zero is not equal to Raster B band zero, AND Raster A band zero is less than 255, then set the current cell to 0, else set it to the value of Raster A band zero. |
Standard maths operators are permitted:
if (A[0] - B[0] == 255, 0, A[0]/5) | If Raster A band zero minus Raster B band zero equals 255, then set the current cell to 0, else set it to the value of Raster A band zero divided by five. |
Attributes can be referenced using @Value and either A: or B: to refer to the attribute name:
A[0]*@Value(A:myattr) | Multiply Raster A band zero by the attribute myattr on raster A. |
Examples
Expression |
Result |
---|---|
255-A[0] | Inverts an 8-bit band. For a 24-bit RGB image, repeat for A[1] and A[2] to invert the full image, repeat for A[3] too if it is a 32-bit RGBA image |
if ((A[0]+A[1]+A[2])==0, 255, A[0]) | Convert black values into white in a 24-bit RGB image. Repeat for A[1] and A[2] to invert the full image |
A[0]*1.5 | Increases the brightness of the red band in an RGB image. Repeat for A[1] and A[2] to brighten the full image |
@sqrt((A[0]*A[0]) + (B[0]*B[0])) | Combines two raster cells together. An alternative would be to average the values: (A[0]+B[0])/2) |
if(A[0]==0,0,A[0]/@Value(A:_height+1)) | Classify raster DEM cells into groups where group size is defined by the _height attribute |
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.
Transformer Categories
FME Licensing Level
FME Professional edition and above
Search FME Knowledge Center
Search for samples and information about this transformer on the FME Knowledge Center.