13.2. Conditional Expressions

Cartographica supports conditional expressions to provide for complex calculations, such as discontinuous functions. These functions may be nested, so that decision trees can be implemented with great flexibility.

The format for conditional expressions is true_expression if condition else false_expression. In this case, the expressions can be any other expression, including a nested conditional expression, so it is possible to create a conditional expression of arbitrary complexity by chaining them together.

[Note]

Parenthesis around the condition are optional but are useful for clarification.

Example 13.4. Conditional Function Example

For example, if you were to need a function that takes a number and rounds to the nearest 500 in the case that the number is positive, but clamps to zero in the case the number is negative, you could write it like this:

trunc(VALUE/500)*500 if (VALUE>0) else 0

This would result in a value of 0 for all values <500, 500 for all values between 500 and 1000, 1000 for all values between 1000 and 1500, etc.