Tree Class
iLand\tree_doc.js:1
A Tree
object allows accessing individual trees (>4m height) in iLand via Javascript.
Note that using Javascript with individual trees can be slow.
Accessing a tree
Trees can be accessed via the Management object or TreeList list within ABE. The Management object provides tree and treeObject functions. Similarly, the TreeList includes tree and treeObject.
Reference vs object
iLand provides two distinct ways to access trees, namely as reference (to an internal object) or as a Javascript object. Access via reference is faster, but tree references can not be used for later access. See the example:
// load all trees of resource unit 0:
management.loadResourceUnit(0);
// access via reference: every call to the tree() functions modifies the reference:
var t1=management.tree(0); // the first tree (dbh=10)
var t2=management.tree(1); // the second tree (dbh=20)
console.log("Tree1: " + t1.dbh + ", Tree2: " + t2.dbh); // -> yields "Tree1: 20, Tree2: 20"!!!!
// access via object:
var t1=management.treeObject(0); // the first tree (dbh=10)
var t2=management.treeObject(1); // the second tree (dbh=20)
console.log("Tree1: " + t1.dbh + ", Tree2: " + t2.dbh); // -> yields "Tree1: 10, Tree2: 20"
// References are, however, useful for iterating over a list of trees:
var sum_dbh=0;
for (var i=0;i<management.count;++i)
sum_dbh += management.tree(i).dbh;
console.log("Mean dbh: " + sum_dbh / management.count);
Methods
expr
-
expression
expr()
can be used to retrieve the value of an iLand expression iland-model.org/Expression. All tree variables can be accessed via the expression. Note that
the expression
is a string and can contain mathematical operations and a set of pre-defined functions.
See also: TreeExpr
Parameters:
-
expression
StringiLand tree expression
Returns:
value of the expression
for the tree.
Example:
var tree = trees.tree(0); // trees is a TreeList
console.log( tree.expr("dbh*dbh") ); // print the squared dbh
info
()
String
A string with memory address, Id, dbh, height, and coordinates of the tree.
Returns:
A human-readable string with key characteristics of the tree.
Properties
dbh
Double
The dbh (diamter at breast height), in cm.
flags
Int
flags
is a binary encoded set of tree flags (see https://iland-model.org/outputs#Tree_Removed_Output for a list of all flags).
species
String
The species (4-character species ID), e.g. 'piab'.
valid
Bool
false
if the tree object is not valid, true
otherwise.
x
Double
The x-coordinate of the tree, in m.
y
Double
The y-coordinate of the tree, in m.