Iif - ObjectVision/GeoDMS GitHub Wiki
Logical functions iif ( ? : )
- iif(condition, then, else)
- condition ? then : else
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.
The iif function results in a data item with the same domain unit and values unit as the subexpressions then and else.
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;
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. Such a choice is deprecated: it works with a warning and results in poly, and GeoDMS 21 refuses it. 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.
- condition data item with bool value type
- subexpressions then and else
- 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.
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
The composition type of then and else is kept in the result since 20.19.3.