EGO Script is a simple language used to create and edit Dinamica EGO models. The file describing the model using the EGO Script format uses the extension ”.ego”.
They behave just like XML models, so it is possible to edit, load them on the graphical interface and save them again. However, beware that the Dinamica EGO graphical interface can change the model layout and input/output format based on the currently defined options. More tips on saving EGO scripts on the GUI at the end of this language tutorial.
A simple EGO script model can be seen below:
Script {{ // Loads a GeoTiff map. x := LoadMap "c:/map.tif"; // Saves an ERMapper map. SaveMap x "c:/map-copy.ers"; }};
The Script {{ }}
is used to delimit the script text. It allows several script elements to be passed on the same file. To retain backward compatibility with previous versions, this declaration can be omitted, but this practice is not encouraged.
The second line indicates the use of a Load Map to load the Geotiff file “map.tif”. The resulting map is bound to the variable x
. Note that the functor name is written without breaks. Variables are always defined and bound using the operator :=
.
The third line uses a Save Map to save the map bound by variable x
in a ERMapper file named “c:/map-copy.ers”.
The variables and parameters after the functor name are bound to the functor input ports. Those variables before the operator :=
are bound to the functor output ports.
The sequence //
mark the beginning of a comment. The comment continue until the end of line.
Here is a slightly more complex example:
Script {{ landscape := LoadCategoricalMap "c:/landscape.tif"; cells hects m2s := CalcAreas landscape; SaveLookupTable hects "c:/area_in_hectares.csv"; }};
Note that functor Calc Areas produces three lookup tables, representing the calculated area in cells, hectares and square meters.
It is possible to omit variables representing outputs or ignore them using the variable _
(underline). So the previous example can be re-written as shown below:
Script {{ landscape := LoadCategoricalMap "c:/landscape.tif"; _ hects := CalcAreas landscape; SaveLookupTable hects "c:/area_in_hectares.csv"; }};
You can also write
_ hects := CalcAreas landscape;
as
_ hects _ := CalcAreas landscape;
Note the trailing _
after hects
.
It is also possible to use the input and output names to bind variables and parameters. The previous example can be rewritten as
Script {{ { landscape=map } := LoadCategoricalMap { filename="c:/landscape.tif" }; { hects=cellAreaInHectares } := CalcAreas { categoricalMap=landscape }; SaveLookupTable { table=hects, filename="c:/area_in_hectares.csv" }; }};
So the first line is binding the filename “c:/landscape.tif” to the input named filename
.
…
It is possible to freely mix both styles. So you can write the previous input as
Script {{ landscape := LoadCategoricalMap { filename="c:/landscape.tif" }; { hects=cellAreaInHectares } := CalcAreas landscape; SaveLookupTable { table=hects, filename="c:/area_in_hectares.csv" }; }};
You can define a comment preceding the comment text with the '//'.
It is possible to define value to input ports using two different syntaxes:
Using this syntax you can pass values and variables based on the position of the input port. Optional input ports always came last and can be omited. However, it is not possible to omit an input and give the next one. This limitation is a huge drawback when working with function with several optional input ports.