The Binary math raster operation can be used to perform arithmetic on raster maps. The operation includes: addition, subtraction, multiplication, division, modulus and exponential.
- Addition (Add); adds one raster coverage to another one or a certain value, given by user, to a raster coverage.
- Subtraction (Subtract); subtracts one raster coverage from another one or subtracts a certain value, given by user, from the raster coverage.
- Division (divide); divides a raster coverage to a certain value or to another raster coverage.
- Multiplication (times); multiplies two raster coverage or a certain value to a raster coverage.
- Modulus (Mod); finds the remainder after division of a raster coverage by another one or by a certain user defined value.
- Exponential (power); applied to two raster coverage's or a raster coverage and a number.The exponent of a number refers to how many times to use the number in a multiplication.
As indicated above, these operators can be used to perform operation using two raster maps, a raster map and a number or two numbers. For example, users can add two raster maps (
outmap = raster A + raser B ) or add certain value to a raster map (
outmap = raster a + 21) generating a new raster map. In addition, the operation can also be used to add two values which generates a new number as an output but not a raster coverage. Note, for all the operators, when one or both operands are undefined, the output will also be undefined. As for the exponential operator, when the base value is negative, the exponent has to be integer value (otherwise the output will be undefined). Using the operator in the form of
returns the nth root of a in power of m (
). In case, using modulus (mod) operator, e.g.,
a mod b ;the output will be undefined if b is 0.
The Binary math raster operation can be applied via ILWIS-Python editor or via ILWIS main window, Toolbar and the Operatins tab. The required Python syntax is:
name of the output raster coverage = ilwis.Engine.do(name of the operation, name of an input raster coverage or a number, name of an input raster coverage or a number, operator)
In example bellow, we subtract value 21 from a raster coverage; where the input raster coverage is tmb2, the value to be subtracted is 21, the operator is - (mines) and the name of the output raster coverage is tmb2c.
tmb2c=ilwis.Engine.do('binarymathraster',“file:///C:/my director/tmb2.mpr", 21, "subtract")
In general, the URL used in the Python syntax can be replaced with variable name created via using Python. For example: you can open a raster coverage or a georeference as variables and give them a name as the following:
rc = ilwis.RasterCoverage("file:///C:/my director/tmb2.mpr")
Once the variable is created via ILWIS-Python editor, then it can be used directly in Python syntax without quotation mark and the path as the following:
tmb2c=ilwis.Engine.do('binarymathraster', rc, 21, "subtract")
Or by using the Python operators directly: tmb2c = (rc - 21)