FME Version
Files
Introduction
Conditional Values are tests or conditions using one or more test clauses, which evaluate values or expressions based on a wide range of available operators and test types. The test clauses are connected with logic - combinations of AND, OR, and NOT, with parentheses to define evaluation order.
Conditional values take the form of If, Else If, Else, statements. The If statement is read first, if a feature passes the statement it will follow the action determined by that condition. If the feature fails the If condition, it will be tested against the Else If statement.
A feature that passes an Else If statement will take on that action. If the feature fails, it will move onto the next Else If statement or the final statement: Else.
A final Else statement determines the action for all features that have failed the previous tests or conditions. This includes missing, null, or empty values within the tested attribute.
Setting Conditional Actions
A variety of transformers have the capability to set conditional actions. These are located in the drop-down menu for setting a parameter value.
Selecting Conditional Value... in the AttributeManager transformer will expose an If, Else If, Else dialog (shown below). Double-clicking a row result in a Tester-style dialog for a user to create conditions to test the data against.
The Parameter Condition Definition dialog allows a user to create a test condition and an output for a feature that passes that condition.
Using Conditional Actions
Conditional values are commonly used for setting attribute values; for example when you need to map or set an attribute in relation to the value of one or more existing attributes. They are useful because they allow for conditions that are more complex than what can be handled in an AttributeValueMapper.
Conditional actions are applied within a single transformer and do not affect the number of output ports created. This allows a user to enter numerous possible values without cluttering or complicating the workspace. Tests can include multiple variables with multiple conditions by using AND/OR statements.
Examples of when to use Conditional Values
- Determining attribute values based on the value of one or more other attributes
- Using the TestFilter with multiple outputs
- Using the multiple Testers
- Using User Parameters to filter or calculate attribute values
Example Workspaces
To follow along, download the example workspace from the Files section of this article. There are two workflows in the example workspace, both use conditional values within the AttributeManager.
Example 1: Conditionals within a Tester
Enable the first bookmark (right-click the bookmark header and select Enable all Objects in Bookmark) and run the workspace.
The workflow in this bookmark uses conditional values to determine what size a park is: Tiny, Small, Medium, or Large. The park areas are calculated from park areas read from a Park MITAB file. Each feature has a park area calculated. The size constraints for the first workflow in squared meters are:
Example 2: Conditionals with a User Parameter
Disable the first bookmark from step 1 and enable the second bookmark. Set the workspace to Run With Prompt. Run the workspace and select yes or no for dog parks, the default value is yes.
This workflow uses a User Parameter with the conditional values to determine the size of a park using the user's input to select dog or non-dog parks. An area of 20,000 square meters is used to divide between Small and Large parks. Parks that do not pass the Dog Park yes-or-no test are given the attribute value of "Unwanted Park".
A composite test for each output value was used to determine if a park passes the requirements. Composite tests combine 3 or more tests within a single condition and consist of AND/OR to combine the statements. In the above dialog, the test condition evaluates if the park is a dog park (Y/N) and if the user wants a dog park (Y/N) and if the park is of a certain size (smaller or larger than 20,000).
To create a composite test such as the one above, enter all test clauses and add the logic as you go, including parentheses to control the logic order. Select from the drop-down menu, or type directly into the Logic column fields. Alternatively, after the tests have been written, open the Composite Expression disclosure and edit the Composite Test.
A wide range of conditional operators are available.
Comments
0 comments
Please sign in to leave a comment.