Script Modeling

Producer Field Guide

HGD_Product
Producer Field Guide
HGD_Portfolio_Suite
Producer

Spatial Modeler Language (SML) is a script language used internally by Model Maker to execute the operations specified in the graphical models that are created. SML can also be used to directly write to models you create. It includes all of the functions available in Model Maker, plus:

  • conditional branching and looping
  • ability to use complex data types

Graphical models created with Model Maker can be output to a script file (text only) in SML. These scripts can then be edited with a text editor using SML syntax and rerun or saved in a library. Script models can also be written from scratch in the text editor. They are stored in ASCII .mdl files.

SHARED Tip The Text Editor is available in the IMAGINE Workspace and from the Model Librarian (Spatial Modeler).

The figure below shows a graphical model for a tasseled cap transformation. Notice how even the annotation on the graphical model is included in the automatically generated script model. Generating script models from graphical models may aid in learning SML.

Graphical Model For Tasseled Cap Transformation

graphical_model_diagram_tasseled_cap

Tasseled Cap Script Model

# TM Tasseled Cap Transformation

# of Lake Lanier, Georgia

#

# declarations

#

INTEGER RASTER n1_tm_lanier FILE OLD NEAREST NEIGHBOR "/usr/imagine/exam\-ples/tm_lanier.img";

FLOAT MATRIX n2_Custom_Matrix;

FLOAT RASTER n4_lntassel FILE NEW ATHEMATIC FLOAT SINGLE "/usr/imagine/examples/lntas\-sel.img";

#

# set cell size for the model

#

SET CELLSIZE MIN;

#

# set window for the model

#

SET WINDOW UNION;

#

# load matrix n2_Custom_Matrix

#

n2_Custom_Matrix = MATRIX(3, 7:

0.331830, 0.331210, 0.551770, 0.425140, 0.480870, 0.000000, 0.252520,

-0.247170, -0.162630, -0.406390, 0.854680, 0.054930, 0.000000, -0.117490,

0.139290, 0.224900, 0.403590, 0.251780, -0.701330, 0.000000, -0.457320);

#

SHARED Tip Convert graphical models to scripts using Model Maker. Open existing script models from the Model Librarian (Spatial Modeler).

Statements

A script model consists primarily of one or more statements. Each statement falls into one of the following categories:

  • Declaration—defines objects to be manipulated within the model
  • Assignment—assigns a value to an object
  • Show and View—see and interpret results from the model
  • Set—defines the scope of the model or establishes default values used by the Modeler
  • Macro Definition—defines substitution text associated with a macro name
  • Quit—ends execution of the model

SML also includes flow control structures so that you can utilize conditional branching and looping in the models and statement block structures, which cause a set of statements to be executed as a group.

Declaration Example

In the Tasseled Cap script model, the following lines form the declaration portion of the model:

INTEGER RASTER n1_tm_lanier FILE OLD NEAREST NEIGHBOR "/usr/imagine/exam\-ples/tm_lanier.img";

FLOAT MATRIX n2_Custom_Matrix;

FLOAT RASTER n4_lntassel FILE NEW ATHEMATIC FLOAT SINGLE "/usr/imagine/examples/lntas\-sel.img";

Set Example

The following set statements are used:

SET CELLSIZE MIN;

SET WINDOW UNION;

Assignment Example

The following assignment statements are used:

n2_Custom_Matrix = MATRIX(3, 7:

0.331830, 0.331210, 0.551770, 0.425140, 0.480870, 0.000000, 0.252520,

-0.247170, -0.162630, -0.406390, 0.854680, 0.054930, 0.000000, -0.117490,

0.139290, 0.224900, 0.403590, 0.251780, -0.701330, 0.000000, -0.457320);

n4_lntassel = LINEARCOMB ( $n1_tm_lanier , $n2_Custom_Matrix ) ;

Data Types

In addition to the data types utilized by Graphical Modeling, script model objects can store data in the following data types:

  • Complex—complex data (double precision)
  • Color—three floating point numbers in the range of 0.0 to 1.0, representing intensity of red, green, and blue

Variables

Variables are objects in the Modeler that have been associated with names using Declaration Statements. The declaration statement defines the data type and object type of the variable. The declaration may also associate a raster variable with certain layers of an image file or a table variable with an attribute table. Assignment Statements are used to set or change the value of a variable.

For script model syntax rules, descriptions of all available functions and operators, and sample models, see Spatial Modeler Language Reference Guide (Legacy).