Parameters in a script can replace (parts of) object names, operations, etc. Parameters in scripts work as DOS replaceable parameters in DOS batch files, and must be written on the Script tab of the Script editor as %1, %2, %3, up to %9.
Example: calculating slope maps in degrees and in percentages
Suppose you have a segment map 'Contour' and an existing georeference 'MyGeoref' with a certain pixel size, and you create a script called 'slopes' to calculate slope maps in degrees and in percentages.
To obtain a slope map in degrees and a slope map in percentages, create the following script:
%3 = MapInterpolContour(%1, %2)
DX = MapFilter(%3, dfdx)
DY = MapFilter(%3, dfdy)
%4 = 100 * HYP(DX, DY) / PIXSIZE(%3)
%5 = RADDEG(ATAN(%4 / 100))
calc %3.mpr
calc %4.mpr
calc %5.mpr
This script is more elaborately explained in MapCalc & TabCalc : creating and running scripts.
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 (in percentages) | Filename |
%5 | Output slope map (in degrees) | Filename |
For instance:
The Run Script dialog box will appear:
In the Run Script dialog box, all parameter names are listed as specified on the Parameters tab of the script editor.
In this case, you can select your own segment map with contour lines for the 'Input contour segment map', and you can select your own georeference for 'Georef for all output maps'.
In this case, the output map names DEM, SlopePct and SlopeDeg were already filled out on the Default Values tab.
Click OK to execute the script.
Tips:
Example 1: calculating slope maps in degrees and in percentages
%3 = MapInterpolContour(%1, %2)
DX = MapFilter(%3, dfdx)
DY = MapFilter(%3, dfdy)
%4 = 100 * HYP(DX, DY) / PIXSIZE(%3)
%5 = RADDEG(ATAN(%4 / 100))
calc %3.mpr
calc %4.mpr
calc %5.mpr
run Slopes Contour.mps MyGeoref.grf DEM SlopePct SlopeDeg
The first string found after the script name Slope will replace %1 in the script, the second one %2, etc. In this example it means that:
Contour.mps | replaces %1 |
MyGeoref.grf | replaces %2 |
DEM | replaces %3 |
SlopePct | replaces %4 |
SlopeDeg | replaces %5 |
Mind:
When you use long filenames as parameters, you must enclose the object name within single quotes; the .ext extension of ILWIS objects should be left outside the quotes.
A valid example of using long names is for instance:
run Slopes 'My Contours'.mps 'My Georef'.grf 'my DEM' 'Slope Map in Percentages' 'Slope Map in Degrees'
For more information, refer to How to use long object names.
Of course, you could also specify the object names directly in the script itself, thus creating a script without parameters.
Example 2: calculating yield maps of different years
Suppose you have three landuse maps (LU70, LU80, and LU90) of different years (1970, 1980, 1990). Each map has an attribute table linked to it (LUTBL70, LUTBL80, LUTBL90), and each table contains a column YieldMainCrop.
To obtain attribute maps (yield maps) of all landuse maps, you can create the following script:
Yield%1=MapAttribute(LU%1, YieldMainCrop)
Yield%2=MapAttribute(LU%2, YieldMainCrop)
Yield%3=MapAttribute(LU%3, YieldMainCrop)
run Yields 70 80 90
In script Yields, '70' replaces %1, '80' replaces %2 and '90' replaces %3. You thus obtain three attribute maps (Yield70, Yield80, Yield90) from the three input maps (LU70, LU80, LU90).
Tips:
See also:
Appendices : ILWIS script language (syntax)