Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
ego_script [2012/09/24 02:10] hermann [Complex Example] |
ego_script [2013/01/07 16:50] admin |
||
---|---|---|---|
Line 11: | Line 11: | ||
A simple EGO script model can be seen below: | A simple EGO script model can be seen below: | ||
- | <file cpp ego1.ego> | + | <file java ego1.ego> |
Script {{ | Script {{ | ||
// Loads a GeoTiff map. | // Loads a GeoTiff map. | ||
Line 32: | Line 32: | ||
Here is a slightly more complex example: | Here is a slightly more complex example: | ||
- | <file cpp ego2.ego> | + | <file java ego2.ego> |
Script {{ | Script {{ | ||
landscape := LoadCategoricalMap "c:/landscape.tif"; | landscape := LoadCategoricalMap "c:/landscape.tif"; | ||
Line 44: | Line 44: | ||
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: | 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: | ||
- | <file cpp ego3.ego> | + | <file java ego3.ego> |
Script {{ | Script {{ | ||
landscape := LoadCategoricalMap "c:/landscape.tif"; | landscape := LoadCategoricalMap "c:/landscape.tif"; | ||
Line 64: | Line 64: | ||
It is also possible to use the input and output names to bind variables and parameters. The previous example can be rewritten as | It is also possible to use the input and output names to bind variables and parameters. The previous example can be rewritten as | ||
- | <file cpp ego4.ego> | + | <file java ego4.ego> |
Script {{ | Script {{ | ||
{ landscape=map } := LoadCategoricalMap { filename="c:/landscape.tif" }; | { landscape=map } := LoadCategoricalMap { filename="c:/landscape.tif" }; | ||
Line 78: | Line 78: | ||
It is possible to freely mix both styles. So you can write the previous input as | It is possible to freely mix both styles. So you can write the previous input as | ||
- | <file cpp ego4.ego> | + | <file java ego4.ego> |
Script {{ | Script {{ | ||
landscape := LoadCategoricalMap { filename="c:/landscape.tif" }; | landscape := LoadCategoricalMap { filename="c:/landscape.tif" }; | ||
Line 88: | Line 88: | ||
It is also possible to inline a definition of functor pretty much like nesting function calls in other programming languages: | It is also possible to inline a definition of functor pretty much like nesting function calls in other programming languages: | ||
- | <file cpp ego5.ego> | + | <file java ego5.ego> |
Script {{ | Script {{ | ||
{ hects=cellAreaInHectares } := CalcAreas (LoadCategoricalMap { filename="c:/landscape.tif" }); | { hects=cellAreaInHectares } := CalcAreas (LoadCategoricalMap { filename="c:/landscape.tif" }); | ||
Line 103: | Line 103: | ||
You can define a single line comment preceding the text with a '%%//%%'. | You can define a single line comment preceding the text with a '%%//%%'. | ||
- | <code cpp> | + | <code java> |
// This is a single line comment. | // This is a single line comment. | ||
</code> | </code> | ||
Line 109: | Line 109: | ||
Multi-line comments can be defined surrounding the text with '%%/*%%' and '%%*/%%'. | Multi-line comments can be defined surrounding the text with '%%/*%%' and '%%*/%%'. | ||
- | <code cpp> | + | <code java> |
/* This is a multi-line | /* This is a multi-line | ||
comment */ | comment */ | ||
Line 116: | Line 116: | ||
It is worth noting that there is a very important difference between both comment styles: multi-line comment style are not preserved if the model is opened using the graphical interface. Usually this is not a problem since multi-line comment can be defined using the '%%//%%' style. Ex: | It is worth noting that there is a very important difference between both comment styles: multi-line comment style are not preserved if the model is opened using the graphical interface. Usually this is not a problem since multi-line comment can be defined using the '%%//%%' style. Ex: | ||
- | <code cpp> | + | <code java> |
// This is a multi-line | // This is a multi-line | ||
// comment | // comment | ||
Line 125: | Line 125: | ||
The sequence ''==='' is used to separate the brief and extended comments of a functor. | The sequence ''==='' is used to separate the brief and extended comments of a functor. | ||
- | <code cpp> | + | <code java> |
// Generate the initial 'seed' | // Generate the initial 'seed' | ||
// | // | ||
Line 165: | Line 165: | ||
The first syntax represents properties using comments. | The first syntax represents properties using comments. | ||
- | <code cpp> | + | <code java> |
/** name = value */ | /** name = value */ | ||
</code> | </code> | ||
Line 171: | Line 171: | ||
The other syntax uses the special symbol @. | The other syntax uses the special symbol @. | ||
- | <code cpp> | + | <code java> |
@name = value | @name = value | ||
</code> | </code> | ||
Line 179: | Line 179: | ||
Examples of properties can be seen below: | Examples of properties can be seen below: | ||
- | <code cpp> | + | <code java> |
/** | /** | ||
dff.date = Wed Oct 21 18:19:21 2009 | dff.date = Wed Oct 21 18:19:21 2009 | ||
Line 195: | Line 195: | ||
</code> | </code> | ||
- | <code cpp> | + | <code java> |
@alias = Largest Patch Area | @alias = Largest Patch Area | ||
@collapsed = yes | @collapsed = yes | ||
Line 232: | Line 232: | ||
The syntax | The syntax | ||
- | <code cpp> | + | <code java> |
// The input map. | // The input map. | ||
// | // | ||
Line 240: | Line 240: | ||
and | and | ||
- | <code cpp> | + | <code java> |
@comment = "The input map. | @comment = "The input map. | ||
Line 255: | Line 255: | ||
Since Dinamica EGO version 2.0, expressions in EGO Script can be represented using an additional special syntax. The example below illustrates: | Since Dinamica EGO version 2.0, expressions in EGO Script can be represented using an additional special syntax. The example below illustrates: | ||
- | <code cpp> | + | <code java> |
if #random <= ($mean - $min) / ($max - $min) then | if #random <= ($mean - $min) / ($max - $min) then | ||
$min + sqrt(#random * ($max - $min) * ($mean - $min)) | $min + sqrt(#random * ($max - $min) * ($mean - $min)) | ||
Line 272: | Line 272: | ||
The example below represents a fragment of a real model using the original syntax: | The example below represents a fragment of a real model using the original syntax: | ||
- | <code cpp> | + | <code java> |
patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | ||
// ... | // ... | ||
Line 291: | Line 291: | ||
The model modified to use the special expression calculation syntax can be seen below: | The model modified to use the special expression calculation syntax can be seen below: | ||
- | <code cpp> | + | <code java> |
patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | patches := LoadCategoricalMap "../originals/landscape.ers" .no .no 0 0 .none; | ||
// ... | // ... | ||
Line 298: | Line 298: | ||
// Isolate the patches of a single category. | // Isolate the patches of a single category. | ||
@collapsed = yes | @collapsed = yes | ||
- | singleCategoryPatches := #[ if #patches = $currenteCategoryId then 1 else null ]; | + | singleCategoryPatches := #[ if #patches = $currenteCategoryId then 1 else null ] .uint8 0 .no; |
</code> | </code> | ||
===== Complex Example ===== | ===== Complex Example ===== | ||
- | <code cpp> | + | <code java> |
@title = Calc Patch Sizes, Mean Patch Sizes and Patch Size Standard Deviations | @title = Calc Patch Sizes, Mean Patch Sizes and Patch Size Standard Deviations | ||
@author = Dinamica Team | @author = Dinamica Team | ||
Line 410: | Line 410: | ||
// Calculate the standard deviation using the SUM(Xi - MEAN)^2. | // Calculate the standard deviation using the SUM(Xi - MEAN)^2. | ||
@collapsed = yes | @collapsed = yes | ||
- | standardDeviation := CalculateValue [ | + | standardDeviation := $ [ |
sqrt($accumulatedValue / %attributes["uniqueCells"]) ? 0 | sqrt($accumulatedValue / %attributes["uniqueCells"]) ? 0 | ||
] .no 0; | ] .no 0; |