Class: Formula

Formula(formula)

This converts a mathematical formula into a openEO process for you.

Operators: - (subtract), + (add), / (divide), * (multiply), ^ (power)

It supports all mathematical functions (i.e. expects a number and returns a number) the back-end implements, e.g. sqrt(x). For namespaced processes, use for example process@namespace(x) - EXPERIMENTAL!

Only available if a builder is specified in the constructor: You can refer to output from processes with a leading #, e.g. #loadco1 if the node to refer to has the key loadco1.

Only available if a parent node is set via setNode(): Parameters can be accessed simply by name. If the first parameter is a (labeled) array, the value for a specific index or label can be accessed by typing the numeric index or textual label with a $ in front, for example $B1 for the label B1 or $0 for the first element in the array. Numeric labels are not supported. You can access subsequent parameters by adding additional $ at the beginning, e.g. $$0 to access the first element of an array in the second parameter, $$$0 for the same in the third parameter etc.

An example that computes an EVI (assuming the labels for the bands are NIR, RED and BLUE): 2.5 * ($NIR - $RED) / (1 + $NIR + 6 * $RED + (-7.5 * $BLUE))

Constructor

new Formula(formula)

Creates a math formula object.

Parameters:
Name Type Description
formula string

A mathematical formula to parse.y

Source:

Members

(static) operatorMapping :object.<string, string>

List of supported operators.

All operators must have the parameters be name x and y.

The key is the mathematical operator, the value is the process identifier.

Type:
  • object.<string, string>
Source:

(nullable) builder :Builder

Type:
Source:

tree :object.<string, *>

Type:
  • object.<string, *>
Source:

Methods

addOperatorProcess(operator, left, right) → {BuilderNode}

Adds a process node for an operator like +, -, *, / etc.

Parameters:
Name Type Description
operator string

The operator.

left number | object.<string, *>

The left part for the operator.

right number | object.<string, *>

The right part for the operator.

Source:
Throws:
Error
Returns:
Type
BuilderNode

generate(setResultNode) → {BuilderNode}

Generates the processes for the formula specified in the constructor.

Returns the last node that computes the result.

Parameters:
Name Type Default Description
setResultNode boolean true

Set the result flag to true.

Source:
Throws:
Error
Returns:
Type
BuilderNode

(protected) getRef(value) → {*}

Gets the reference for a value, e.g. from_node or from_parameter.

Parameters:
Name Type Description
value *
Source:
Returns:
Type
*

(protected) parseTree(tree) → {object.<string, *>}

Walks through the tree generated by the TapDigit parser and generates process nodes.

Parameters:
Name Type Description
tree object.<string, *>
Source:
Throws:
Error
Returns:
Type
object.<string, *>

setBuilder(builder)

The builder instance to use.

Parameters:
Name Type Description
builder Builder

The builder instance to add the formula to.

Source: