Logical functions

if_null

Arguments: [test: Nullable[Anything], else: Nullable[Anything]]

Returns: Anything

Returns the test value if it is non-null, otherwise returns the else value. This is useful for supplying a non-null default if a nullable expression yields null. For example, if_null(sum(value), 0) would return 0 if the sum function returns null.

if

Arguments: [condition: Nullable[Bool], then: Nullable[Anything], else: Nullable[Anything]]

Returns: Anything

A function that fills a similar role to an if statement in other programming languages, e.g. if(depth > 1, then: 'damaged', else: 'safe'). The then case is returned if true, else if false or null. Note that the then and else values must have similar types, or the function’s return type will be the anything type.

The else argument is optional. For example if(false, 'foo') will return null and the return type will be a nullable version of the then argument’s type.

RiskScape functions evaluate their arguments before the function is called, which can be wasteful when an expression takes a while to run, e.g. a spatial lookup. To avoid this behaviour, the then and else arguments can be supplied as lambda expressions. These are only evaluated when the particular case applies. In the example of if(exposure.high_lsl_risk, () -> sample(exposure, landslide_susceptibility), else: 0) the sample function will only be called if the high_lsl_risk attribute is true, avoiding unnecessary computation.

if_then_else

Arguments: [condition: Nullable[Bool], then: Nullable[Anything], else: Nullable[Anything]]

Returns: Anything

Deprecated, if_then_else is the same as if. See if for function help.

is_null

Arguments: [Nullable[Anything]]

Returns: Bool

Returns true if the given argument is null, as per https://docs.geoserver.org/latest/en/user/filter/function_reference.html#comparison-functions

is_not_null

Arguments: [Nullable[Anything]]

Returns: Bool

Returns true if the given argument is not null, i.e. it contains a value

not

Arguments: [Bool]

Returns: Bool

Returns the negation of the given input