for_each
- Details
- Last Updated on Thursday, 28 March 2013 09:10
syntax
- for_each_n[e|t][d[n]v[n]][l][d][a[t]][s][c][u]
definition
The for_each group represents a family of functions. The specific function name is dependent on the arguments used in the for_each function name. The possible names for the specific function are derived from the following notation: for_each_n[e|t][d[n]v[n]][l][d][a[t]][s][c][u]. In this notation the name characters within brackets are optional. The | character indicates one of the two namecharacters split by this | character need to be selected. The namecharacters specified need to match with the relevant arguments. They represent:
- n: name for each new item;
- e: expression for each new item;
- t: template instantiated for each new item;
- d[n]: domain unit for each new item, with optional a n for the name of the container where the domain units can be found, in case a set of different domain units are requested;
- v[n]: values unit for each new item, with optional a n for the name of the container where the values units can be found, in case a set of different values units are requested;
- l: label for each new item;
- d: description for each new item;
- a: storagename for each new item, with an optional t for the storage type;
- s: sqlstring for each new item.
- c: cdf for each new item
- u: url for each new item
description
A for_each function is used to derive a set of new tree items, based on the occuring values of data items in an origin domain. Different data items of this origin domain can be used to specify the name, label, description etc. for the new set of tree items. A template is used if the new items also request sub items. Often an expression is configured for the new items, in case for this expression elements from the origin domain are needed, the expression is usually indirect.
conditions
If a domain unit parameter is configured, a values unit is also obligatory and vice versa. If a template is ONLY used to configure the domain and values unit for the resulting tree items, it is advised to use the domain and values unit arguments in stead of a template (as in the example). The attribute used for naming the new items should not contain null values, if multiple null values occur, an error is generated.
since version
5.15
examples
1:
container regions: expr =
"for_each_nedvld("
" Relational/Region/RegionName" // name
",'lookup(' " // expression
"+ String(Relational/Region/RegionNr) "
"+ ', Relational/Region/NrInhabitants"
" )'"
",void1" // domain unit
",uint32" // values unit
",Relational/Region/RegionLabel" // label
",Relational/Region/RegionDescr" // description
")";
1) void is the domain unit for parameters
| RegionName | RegionNr | NrInhabitants | RegionLabel | RegionDescr |
| NoordHolland | 0 | 550 | ||
| ZuidHolland | 1 | 1025 | ||
| Utrecht | 2 | 300 | ||
| NoordBrabant | 3 | 300 | ||
| Gelderland | 4 | 0 |
Result: Container regions with a parameter for each province, with as value the NrInhabitants for this province. The name, expression, domain and values unit, label and description for these parameters are determined by the for_each_nedvld function.
2:
container FactorData: Expr =
"for_each_ndvndacu("
" MetaData/Factors/Name" // name
",Geography/Albers1kmGrid" // domain unit
",Units" // container with configuration of values units
",MetaData/Factors/ValuesUnit" // values units
",MetaData/Factors/Descr" // description
",'%sourceDataProjDir%.ASC/'+FileName+'.asc'" // storage name
",MetaData/Factors/Cdf2" // cdf
",MetaData/Factors/url2" // url
")";
container RegionGrids: Expr =Result: container RegionGrids with an attribute for each UniqueRegionRefs. The name, expression, domain and values unit for these attributes are determined by the for_each_nedvn function. The values units read from the data item: UniqueRegionRefs/Values(fifth argument) need to be direct subitems of the Geography/Regions(fourth argument) container.
"for_each_nedvn("
" UniqueRegionRefs/Values" // name
",'JrcFactorData/'+URR/Values+'[domain/grid_rel]'" // expression
",domain" // domain unit
",Geography/Regions" // container with configuration of values units
",UniqueRegionRefs/Values" // values units
")"