Map and Table calculation

Creating and running scripts

By creating and running a script, you can perform a series of ILWIS operations. The usage of scripts may save time but is something for more experienced users.

With a script, MapCalc and TabCalc expressions can be performed as well as any ILWIS operation. Furthermore, some extra commands are possible to show objects, or to perform some file management. For more information on script syntax, see Appendices : ILWIS expressions, Appendices : ILWIS commands and Appendices : ILWIS script language (syntax).

To create a script:

The Script editor appears in which you can type your script expressions.

Example of a script with parameters:

To calculate slope maps in percentages and in degrees:

  1. Create a script (e.g. 'Slopes')
  2. On the Script tab of the script editor where the script can be defined: type, to insert a comment line:
  3. //script to calculate slope maps in percentages and in degrees

    or type

    Rem script to calculate slope maps in percentages and in degrees

  4. To use the Contour Interpolation operation to create an interpolated height map from segment contour lines, type:
  5. %3 = MapInterpolContour(%1, %2)

    Perform a contour interpolation on segment map %1, use existing georeference %2, and write the output to map %3.
    Advanced users may wish to define a georeference corners beforehand with a script command; see Appendices : ILWIS script language (syntax).

  6. To use the dfdx filter on the interpolated contour map to calculate height differences in X-direction, type:
  7. DX = MapFilter(%3, dfdx)

    Filter map %3 with the dfdx filter and write the output to map DX.

  8. To use the dfdy filter on the interpolated contour map to calculate height differences in Y-direction, type:
  9. DY = MapFilter(%3, dfdy)

    Filter map %3 with the dfdy filter and write the output to map DY.

  10. To calculate a slope map in percentages from the output of step 4 and 5, type:
  11. %4 = 100 * HYP(DX,DY) / PIXSIZE(%3)

    HYP is an internal MapCalc/TabCalc function;
    DX and DY are the output maps from the filtering operation;
    function PIXSIZE returns the pixel size of raster map %3;
    %4 is the output map name of the map containing slope values in percentages.

  12. To convert the percentage values into degrees, type:
  13. %5 = RADDEG(ATAN(%4/100))

    Function ATAN and RADDEG are internal MapCalc/TabCalc functions,
    %5 is the output map name of the map containing slope values in degrees.

  14. After running the script (see step 11), the output maps will be available as dependent maps. The expression by which a map is created is stored in the map's object definition file. The data file for an output map will be calculated when you double-click an output map in the Catalog.
  15. To let the script calculate the data files for the output maps, you may add the following lines to your script:

    calc %3.mpr
    calc %4.mpr
    calc %5.mpr

    In fact, by adding only calc %5.mpr, all maps which are part of the process to calculate map %5 will be calculated as well.

  16. On the Parameters tab of the script editor, select the number of parameters (in this case 5), type a name for every parameter and select for each input parameter the object type. For example:
  17.  

    Parameter Name Type
    %1 Input contour segment map Segment Map
    %2 Georef for all output maps Georeference
    %3 Output DEM Filename
    %4 Output slope map (perc.) Filename
    %5 Output slope map (degrees) Filename

     

  18. On the Default Values tab, you may assign default objects to your parameters as you would like to use them in the script and/or as you would like to see them in the Run Script dialog box.
  19. For instance:

     

  20. To run the script:

    The Run Script dialog box will appear:

     

    Run Script dialog box

    In the Run Script dialog box, all parameter names are listed as specified on the Parameters tab of the script editor.

    Choose the objects etc. you wish to use, and click OK to execute the script.

Tips:

The result of running this script are maps SlopePct and SlopeDeg which are slope maps in percentages and in degrees. Also other maps are calculated during the whole procedure, such as the DEM, DX (height differences in X-direction) and DY (height differences in Y-direction). The following maps show the input map Contour and very small parts of the other maps calculated by the script.

 

Contour    DEM
  
DX    DY
  

Negative values in map DX mean that the slope is downwards when you go from west to east. A positive value indicates an upwards slope. In map DY positive values indicate that when you go from the south to north the slope is upwards and negative values mean that the slope is downwards.

 

SlopePct    SlopeDeg
  

The slope maps show the steepness of the slopes irrespective of the direction of the slope.

Mind:

the following slope values are the same: 30�= 58%, 45�= 100%, 60�= 173%, 80�= 567%. As you see, slope values in the Slopepct map can be greater than 100%.

Additionally, you can prepare representations for both maps with the Representation Value/Gradual editor.

You can also create two domain Groups to classify both output maps, e.g.:
classes 0-10%, 10-25%, 25-50%, 50-100%, >100% for the slope map in percentages and
classes 0-6�, 6-12.5�, 12.5-22.5�, 22.5-45�, >45� for the slope map in degrees.

Use these domain groups in the Slicing operation.

You can create your own Help for a script so that you can explain the meaning of parameters to other users of the script. For more information, see the Run Script dialog box.

See also: