Show:
Module: iLand

A TreeExpr object is a helper object for efficient access to values of individual trees (>4m) in iLand.

The TreeExpr encapsulates an iLand expression (iland.boku.ac.at/Expression) which allows access to many properties of single trees in the model. The basic use is demonstrated in the following example:

// set up a TreeExpr
var expr = new TreeExpr("dbh*dbh");

// now use to evaluate the expression for individual trees, assume 'trees' is a TreeList
var sum = 0;
for (var i=0;i<trees.count;++i) {
    sum += expr.value(trees.tree(i));
}

Similar functionality is provided by the expr-method of Tree - the difference is mainly performance: while the expr-method constructs for each call an internal "expression" (and has to parse the content of the expression each time), the TreeExpr object only parses the expression once.

Performance comparison

The test case extracts the dbh of a tree 1,000,000 times in Javascript and measures the time (the overhead time of the Javascript loop (0.3s) is substracted)

  • dbh-property (tree.dbh) (no Expression): 0.5s
  • TreeExpr object (expr.value(tree)) (create Expression once): 1.1s
  • tree.expr("dbh") (create Expression every time): 2.5s

Item Index

Methods

Properties

Methods

TreeExpr

(
  • string
)

Constructs a TreeExpr. Use with the new JavaScript keyword.

Parameters:

  • string Object

    expression The expression as a string

value

(
  • tree
)

Calculates the value of the expression for the given tree. If the tree is invalid, a warning is written to the log and -1 is returned.

Parameters:

  • tree Tree

    The Tree-object for which to calculate the expression.

Properties

expression

String

A string representing the current expression. The property is read/write and can be used to modify the expression.

Example:

var expr = new TreeExpr("dbh");
                    // assume 't' is a Tree:
                    console.log(expr.value(t)); // e.g. 9.799 cm
                    expr.expression = "age";
                    console.log(expr.value(t)); // e.g. 21 yrs