Iif
Logical functions iif ( ? : )
syntax
- iif(condition, then, else)
- condition ? then : else
definition
iif(condition, then, else) or condition ? then : else results in a Data item with the result of the Subexpression then if the condition is true and of else if the condition is false.
description
The iif function results in a data item with the same Domain unit and Values unit as the subexpressions then and else.
Since GeoDMS 20.19.3 the result also keeps the composition type of then and else when both have the same one, so choosing between two polygon attributes results in a polygon attribute:
attribute<crs> geometry (poly) := use_override ? overrides/geometry[overrides_rel] : geometry;
Before 20.19.3 the result of such a choice was always an arc. The declared poly was then reported as deprecated (the declared ValueComposition ‘poly’ differs from the ‘arc’ of the calculation result) and replaced by that arc, which propagated to every item reading the attribute, so the choice had to be written as a Lookup in a Union_unit of both geometries instead.
When then and else have a different composition type, there is no composition type that describes the result, since it would be part ring and part polyline. The GeoDMS reports this as deprecated and results in poly, the rule it has always used for such a mixture; from GeoDMS 21 it is an error. Make the two branches agree instead, with Points2sequence, points2polygon or points2multi_point.
iif statements can be nested, but it is advised to use the Switchcase function for nested statements.
In the evaluation of an iif function, both then and else subexpressions are calculated. Use an Indirect expression if the calculation of one of both subexpressions is time consuming or illogical.
applies to
- condition data item with bool Value type
- subexpressions then and else
conditions
- The domain unit of condition, subexpressions then and else and the resulting data item must match or be Void (literals or parameters can be combined with data items of any domain).
- The values unit of subexpressions then and else and the resulting data item must match.
example
1. attribute<float32> iifAgteB (ADomain) := iif(A >= B, 1f, 0f);
2. attribute<float32> iifAgteB (ADomain) := A >= B ? 1f : 0f;
| A(float32) | B(float32) | iifAgteB |
|---|---|---|
| 0 | 2 | 0 |
| 1 | 2 | 0 |
| 2 | 2 | 1 |
| 3 | 2 | 1 |
| null | 2 | 0 |
ADomain, nr of rows = 5