|
@@ -7,41 +7,41 @@
|
|
|
</head>
|
|
|
<body bgcolor="white">
|
|
|
<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
|
|
|
-<H2>NAME</H2>
|
|
|
-<EM><B>r.mapcalc</B></EM>
|
|
|
-<H2>DESCRIPTION</H2>
|
|
|
-<EM>r.mapcalc</EM> performs arithmetic on raster map layers.
|
|
|
+<h2>NAME</h2>
|
|
|
+<em><b>r.mapcalc</b></em>
|
|
|
+<h2>DESCRIPTION</h2>
|
|
|
+<em>r.mapcalc</em> performs arithmetic on raster map layers.
|
|
|
New raster map layers can be created which are arithmetic expressions
|
|
|
involving existing raster map layers, integer or floating point constants,
|
|
|
and functions.
|
|
|
-<H2>PROGRAM USE</H2>
|
|
|
-If used without command line arguments, <EM>r.mapcalc</EM> will read its
|
|
|
+<h2>PROGRAM USE</h2>
|
|
|
+If used without command line arguments, <em>r.mapcalc</em> will read its
|
|
|
input, one line at a time, from standard input
|
|
|
(which is the keyboard, unless redirected from a file or across a pipe).
|
|
|
Otherwise, the expression on the command line is evaluated.
|
|
|
-<EM>r.mapcalc</EM> expects its input to have the form:
|
|
|
-<P>
|
|
|
-<B>result=</B><EM>expression</EM>
|
|
|
-<P>
|
|
|
-where <EM>result</EM> is the name of a raster map layer
|
|
|
+<em>r.mapcalc</em> expects its input to have the form:
|
|
|
+<p>
|
|
|
+<b>result=</b><em>expression</em>
|
|
|
+<p>
|
|
|
+where <em>result</em> is the name of a raster map layer
|
|
|
to contain the result of the calculation and
|
|
|
-<EM>expression</EM> is any legal arithmetic expression involving existing
|
|
|
+<em>expression</em> is any legal arithmetic expression involving existing
|
|
|
raster map layers, integer or floating point constants,
|
|
|
and functions known to the calculator.
|
|
|
Parentheses are allowed in the expression and may be nested to any depth.
|
|
|
-<EM>result</EM> will be created in the user's current mapset.
|
|
|
-<P>
|
|
|
-The formula entered to <EM>r.mapcalc</EM> by the user is recorded both in the
|
|
|
-<EM>result</EM> map title (which appears in the category file for <EM>result</EM>)
|
|
|
-and in the history file for <EM>result</EM>.
|
|
|
-<P>
|
|
|
+<em>result</em> will be created in the user's current mapset.
|
|
|
+<p>
|
|
|
+The formula entered to <em>r.mapcalc</em> by the user is recorded both in the
|
|
|
+<em>result</em> map title (which appears in the category file for <em>result</em>)
|
|
|
+and in the history file for <em>result</em>.
|
|
|
+<p>
|
|
|
Some characters have special meaning to the command shell. If the user
|
|
|
-is entering input to <EM>r.mapcalc</EM> on the command line, expressions
|
|
|
+is entering input to <em>r.mapcalc</em> on the command line, expressions
|
|
|
should be enclosed within single quotes. See NOTES, below.
|
|
|
-<P>
|
|
|
-<H2>OPERATORS AND ORDER OF PRECEDENCE</H2>
|
|
|
+<p>
|
|
|
+<h2>OPERATORS AND ORDER OF PRECEDENCE</h2>
|
|
|
The following operators are supported:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
Operator Meaning Type Precedence
|
|
|
--------------------------------------------------------------
|
|
|
- negation Arithmetic 12
|
|
@@ -69,111 +69,111 @@ The following operators are supported:
|
|
|
|| logical or Logical 2
|
|
|
||| logical or[1] Logical 2
|
|
|
?: conditional Logical 1
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
(modulus is the remainder upon division)
|
|
|
-<P>
|
|
|
+<p>
|
|
|
[1] The &&& and ||| operators handle null values differently to other
|
|
|
operators. See the section entitled <b>NULL support</b> below for more
|
|
|
details.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
The operators are applied from left to right, with those of higher precedence
|
|
|
applied before those with lower precedence.
|
|
|
Division by 0 and modulus by 0 are acceptable and give a NULL result.
|
|
|
The logical operators give a 1 result if the comparison is true, 0 otherwise.
|
|
|
-<P>
|
|
|
-<P>
|
|
|
-<H2>RASTER MAP LAYER NAMES</H2>
|
|
|
+<p>
|
|
|
+<p>
|
|
|
+<h2>RASTER MAP LAYER NAMES</h2>
|
|
|
Anything in the expression which is not a number, operator, or function name
|
|
|
is taken to be a raster map layer name.
|
|
|
Examples:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
elevation
|
|
|
x3
|
|
|
3d.his
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
Most GRASS raster map layers meet this naming convention.
|
|
|
However, if a raster map layer has a name which conflicts with the
|
|
|
above rule, it should be quoted. For example, the expression
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
x = a-b
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
would be interpreted as: x equals a minus b, whereas
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
x = "a-b"
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
-would be interpreted as: x equals the raster map layer named <EM>a-b</EM>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
+would be interpreted as: x equals the raster map layer named <em>a-b</em>
|
|
|
+<p>
|
|
|
Also
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
x = 3107
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
-would create <EM>x</EM> filled with the number 3107, while
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
+would create <em>x</em> filled with the number 3107, while
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
x = "3107"
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
-would copy the raster map layer <EM>3107</EM> to the raster map layer <EM>x</EM>.
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
+would copy the raster map layer <em>3107</em> to the raster map layer <em>x</em>.
|
|
|
|
|
|
-<P>
|
|
|
+<p>
|
|
|
Quotes are not required unless the raster map layer names
|
|
|
look like numbers or contain operators, OR unless the program
|
|
|
is run non-interactively. Examples given here assume the
|
|
|
program is run interactively. See NOTES, below.
|
|
|
-<P>
|
|
|
-<EM>r.mapcalc</EM> will look for the raster map layers according to the
|
|
|
+<p>
|
|
|
+<em>r.mapcalc</em> will look for the raster map layers according to the
|
|
|
user's current mapset search path.
|
|
|
It is possible to override the search path and specify the mapset
|
|
|
from which to select the raster map layer.
|
|
|
This is done by specifying the raster map layer name in the form:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
name@mapset
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
For example, the following is a legal expression:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
result = x@PERMANENT / y@SOILS
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
The mapset specified does not have to be in the mapset search path.
|
|
|
(This method of overriding the mapset search path is common to all
|
|
|
-GRASS commands, not just <EM>r.mapcalc</EM>.)
|
|
|
-<P>
|
|
|
-<H2>THE NEIGHBORHOOD MODIFIER</H2>
|
|
|
+GRASS commands, not just <em>r.mapcalc</em>.)
|
|
|
+<p>
|
|
|
+<h2>THE NEIGHBORHOOD MODIFIER</h2>
|
|
|
Maps and images are data base files stored in raster format, i.e.,
|
|
|
two-dimensional matrices of integer values.
|
|
|
-In <EM>r.mapcalc</EM>, maps may be followed by a <EM>neighborhood</EM> modifier that
|
|
|
+In <em>r.mapcalc</em>, maps may be followed by a <em>neighborhood</em> modifier that
|
|
|
specifies a relative offset from the current cell being evaluated. The format is
|
|
|
-<EM>map[r,c]</EM>, where <EM>r</EM> is the row offset and <EM>c</EM> is the column offset.
|
|
|
-For example, <EM>map[1,2]</EM> refers to the cell one row below and two columns
|
|
|
-to the right of the current cell, <EM>map[-2,-1]</EM> refers to the cell
|
|
|
+<em>map[r,c]</em>, where <em>r</em> is the row offset and <em>c</em> is the column offset.
|
|
|
+For example, <em>map[1,2]</em> refers to the cell one row below and two columns
|
|
|
+to the right of the current cell, <em>map[-2,-1]</em> refers to the cell
|
|
|
two rows above and one column to the left of the current cell,
|
|
|
-and <EM>map[0,1]</EM> refers to the cell one column to the right of the current cell.
|
|
|
+and <em>map[0,1]</em> refers to the cell one column to the right of the current cell.
|
|
|
This syntax permits the development of neighborhood-type filters within a single
|
|
|
map or across multiple maps.
|
|
|
|
|
|
-<P>
|
|
|
-<H2>RASTER MAP LAYER VALUES FROM THE CATEGORY FILE</H2>
|
|
|
+<p>
|
|
|
+<h2>RASTER MAP LAYER VALUES FROM THE CATEGORY FILE</h2>
|
|
|
Sometimes it is desirable to use a value associated with a category's
|
|
|
-<EM>label</EM> instead of the category value itself. If a raster
|
|
|
-map layer name is preceded by the <B>@</B>
|
|
|
+<em>label</em> instead of the category value itself. If a raster
|
|
|
+map layer name is preceded by the <b>@</b>
|
|
|
operator, then the labels in the category file for the raster map layer
|
|
|
are used in the expression instead of the category value.
|
|
|
-<P>
|
|
|
-For example, suppose that the raster map layer <EM>soil.ph</EM>
|
|
|
+<p>
|
|
|
+For example, suppose that the raster map layer <em>soil.ph</em>
|
|
|
(representing soil pH values) has a category file with labels as follows:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
cat label
|
|
|
------------------
|
|
|
0 no data
|
|
@@ -184,17 +184,17 @@ cat label
|
|
|
5 7.2
|
|
|
6 8.8
|
|
|
7 9.4
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
Then the expression:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
result = @soils.ph
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
would produce a result with category values
|
|
|
0, 1.4, 2.4, 3.5, 5.8, 7.2, 8.8 and 9.4.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
Note that this operator may only be applied to raster map layers
|
|
|
and produces a floating point value in the expression.
|
|
|
Therefore, the category label must start with a valid number.
|
|
@@ -202,96 +202,96 @@ If the category label is integer, it will be represented by
|
|
|
a floating point number. I the category label does not start
|
|
|
with a number or is missing, it will be represented by NULL
|
|
|
(no data) in the resulting raster map.
|
|
|
-<H2>GREY SCALE EQUIVALENTS AND COLOR SEPARATES</H2>
|
|
|
+<h2>GREY SCALE EQUIVALENTS AND COLOR SEPARATES</h2>
|
|
|
It is often helpful to manipulate the colors assigned to map categories.
|
|
|
This is particularly useful when the spectral properties of cells have meaning
|
|
|
(as with imagery data), or when the map category values represent real
|
|
|
quantities (as when category values reflect true elevation values).
|
|
|
Map color manipulation can also aid visual recognition, and map printing.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
The # operator can be used to either convert map category values to their
|
|
|
grey scale equivalents or to extract the red, green, or blue components
|
|
|
of a raster map layer into separate raster map layers.
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
result = #map
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
-converts each category value in <EM>map</EM> to a value in the range 0-255 which
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
+converts each category value in <em>map</em> to a value in the range 0-255 which
|
|
|
represents the grey scale level implied by the color for the category.
|
|
|
If the map has a grey scale color table, then the grey level is what
|
|
|
#map evaluates to. Otherwise, it is computed as:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
0.10 * red + 0.81 * green + 0.01 * blue
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
Alternatively, you can use:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
result = y#map
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
to use the NTSC weightings:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
0.30 * red + 0.59 * green + 0.11 * blue
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
Or, you can use:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
result = i#map
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
to use equal weightings:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
0.33 * red + 0.33 * green + 0.33 * blue
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
The # operator has three other forms: r#map, g#map, b#map.
|
|
|
These extract the red, green, or blue components in the named raster map,
|
|
|
-respectively. The GRASS shell script <EM><A HREF="r.blend.html">r.blend</A></EM> extracts each of these
|
|
|
+respectively. The GRASS shell script <em><a href="r.blend.html">r.blend</a></em> extracts each of these
|
|
|
components from two raster map layers, and combines them by a user-specified
|
|
|
percentage.
|
|
|
These forms allow color separates to be made. For example, to
|
|
|
-extract the red component from <EM>map</EM>
|
|
|
-and store it in the new 0-255 map layer <EM>red</EM>,
|
|
|
+extract the red component from <em>map</em>
|
|
|
+and store it in the new 0-255 map layer <em>red</em>,
|
|
|
the user could type:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
red = r#map
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
To assign this map grey colors type:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
-<A HREF="r.colors.html">r.colors</A> map=red color=rules
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
+<a href="r.colors.html">r.colors</a> map=red color=rules
|
|
|
black
|
|
|
white
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
To assign this map red colors type:
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
-<A HREF="r.colors.html">r.colors</A> map=red color=rules
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
+<a href="r.colors.html">r.colors</a> map=red color=rules
|
|
|
black
|
|
|
red
|
|
|
-</PRE></div>
|
|
|
-<P>
|
|
|
-<H2>FUNCTIONS</H2>
|
|
|
+</pre></div>
|
|
|
+<p>
|
|
|
+<h2>FUNCTIONS</h2>
|
|
|
The functions currently supported are listed in the table below.
|
|
|
The type of the result is indicated in the last column.
|
|
|
-<EM>F</EM>
|
|
|
+<em>F</em>
|
|
|
means that the functions always results in a floating point value,
|
|
|
-<EM>I</EM>
|
|
|
+<em>I</em>
|
|
|
means that the function gives an integer result, and
|
|
|
-<EM>*</EM>
|
|
|
+<em>*</em>
|
|
|
indicates that the result is float if any of the arguments to the function
|
|
|
are floating point values and integer if all arguments are integer.
|
|
|
-<P>
|
|
|
-<div class="code"><PRE>
|
|
|
+<p>
|
|
|
+<div class="code"><pre>
|
|
|
function description type
|
|
|
---------------------------------------------------------------------------
|
|
|
abs(x) return absolute value of x *
|
|
@@ -327,8 +327,8 @@ sin(x) sine of x (x is in degrees) F
|
|
|
sqrt(x) square root of x F
|
|
|
tan(x) tangent of x (x is in degrees) F
|
|
|
xor(x,y) exclusive-or (XOR) of x and y I
|
|
|
-</PRE></div>
|
|
|
-<div class="code"><PRE>
|
|
|
+</pre></div>
|
|
|
+<div class="code"><pre>
|
|
|
Internal variables:
|
|
|
row() current row of moving window
|
|
|
col() current col of moving window
|
|
@@ -337,14 +337,14 @@ Internal variables:
|
|
|
ewres() current east-west resolution
|
|
|
nsres() current north-south resolution
|
|
|
null() NULL value
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
Note, that the row() and col() indexing starts with 1.
|
|
|
-<H2>FLOATING POINT VALUES IN THE EXPRESSION</H2>
|
|
|
+<h2>FLOATING POINT VALUES IN THE EXPRESSION</h2>
|
|
|
Floating point numbers are allowed in the expression. A floating point
|
|
|
number is a number which contains a decimal point:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
2.3 12.0 12. .81
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
Floating point values in the expression are handled in a special way.
|
|
|
With arithmetic and logical operators, if either operand is float,
|
|
|
the other is converted to float and the result of the operation is float.
|
|
@@ -352,35 +352,35 @@ This means, in particular that division of integers results in a
|
|
|
(truncated) integer, while division of floats results in an accurate
|
|
|
floating point value. With functions of type * (see table above),
|
|
|
the result is float if any argument is float, integer otherwise.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
Note: If you calculate with integer numbers, the resulting map will
|
|
|
be integer. If you want to get a float result, add the decimal point
|
|
|
to integer number(s).
|
|
|
-<P>
|
|
|
+<p>
|
|
|
If you want floating point division, at least one of the arguments has
|
|
|
to be a floating point value. Multiplying one of them by 1.0 will
|
|
|
produce a floating-point result, as will using float():
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
r.mapcalc "ndvi=float(lsat.4 - lsat.3) / (lsat.4 + lsat.3)"
|
|
|
-</PRE></div>
|
|
|
-<H2>NULL support</H2>
|
|
|
+</pre></div>
|
|
|
+<h2>NULL support</h2>
|
|
|
<menu>
|
|
|
<li>Division by zero should result in NULL.
|
|
|
<li>Modulus by zero should result in NULL.
|
|
|
<li> NULL-values in any arithmetic or logical operation should result
|
|
|
in NULL. (however, &&& and ||| are treated specially, as described below).
|
|
|
<li> The &&& and ||| operators observe the following axioms even when x is NULL:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
x &&& false == false
|
|
|
false &&& x == false
|
|
|
x ||| true == true
|
|
|
true ||| x == true
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
<li> NULL-values in function arguments should result in NULL (however,
|
|
|
if(), eval() and isnull() are treated specially, as described below).
|
|
|
<li> The eval() function always returns its last argument
|
|
|
<li> The situation for if() is:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
if(x)
|
|
|
NULL if x is NULL; 0 if x is zero; 1 otherwise
|
|
|
if(x,a)
|
|
@@ -390,19 +390,19 @@ if(x,a,b)
|
|
|
if(x,n,z,p)
|
|
|
NULL if x is NULL; n if x is negative;
|
|
|
z if x is zero; p if x is positive
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
<li> The (new) function isnull(x) returns: 1 if x is NULL;
|
|
|
0 otherwise. The (new) function null()
|
|
|
(which has no arguments) returns an integer NULL.
|
|
|
<li>Non-NULL, but invalid, arguments to functions should result in NULL.
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
Examples:
|
|
|
log(-2)
|
|
|
sqrt(-2)
|
|
|
pow(a,b) where a is negative and b is not an integer
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
</menu>
|
|
|
-<P>
|
|
|
+<p>
|
|
|
NULL support: Please note that any math performed with NULL cells always
|
|
|
results in a NULL value for these cells. If you want to replace a NULL cell
|
|
|
on-the-fly, use the isnull() test function in a if-statement.
|
|
@@ -410,40 +410,40 @@ on-the-fly, use the isnull() test function in a if-statement.
|
|
|
Example: The users wants the NULL-valued cells to be treated like zeros. To
|
|
|
add maps A and B (where B contains NULLs) to get a map C the user can use a
|
|
|
construction like:<p>
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
C=A + if(isnull(B),0,B)
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
<p>
|
|
|
<b>NULL and conditions:</b>
|
|
|
<p>
|
|
|
For the one argument form:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
if(x) = NULL if x is NULL
|
|
|
if(x) = 0 if x = 0
|
|
|
if(x) = 1 otherwise (i.e. x is neither NULL nor 0).
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
<p>
|
|
|
For the two argument form:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
if(x,a) = NULL if x is NULL
|
|
|
if(x,a) = 0 if x = 0
|
|
|
if(x,a) = a otherwise (i.e. x is neither NULL nor 0).
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
<p>
|
|
|
For the three argument form:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
if(x,a,b) = NULL if x is NULL
|
|
|
if(x,a,b) = b if x = 0
|
|
|
if(x,a,b) = a otherwise (i.e. x is neither NULL nor 0).
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
<p>
|
|
|
For the four argument form:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
if(x,a,b,c) = NULL if x is NULL
|
|
|
if(x,a,b,c) = a if x > 0
|
|
|
if(x,a,b,c) = b if x = 0
|
|
|
if(x,a,b,c) = c if x < 0
|
|
|
-</PRE></div>
|
|
|
+</pre></div>
|
|
|
More generally, all operators and most functions return NULL if *any*
|
|
|
of their arguments are NULL.
|
|
|
<br>
|
|
@@ -456,7 +456,7 @@ used.
|
|
|
All forms of if() return NULL if the first argument is NULL. The 2, 3
|
|
|
and 4 argument forms of if() return NULL if the "selected" argument is
|
|
|
NULL, e.g.:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
if(0,a,b) = b regardless of whether a is NULL
|
|
|
if(1,a,b) = a regardless of whether b is NULL
|
|
|
</pre></div>
|
|
@@ -472,31 +472,31 @@ The behaviour makes sense if the user considers NULL as representing an
|
|
|
unknown quantity. E.g. if x and y are both unknown, then the values of
|
|
|
"x == y" and "x != y" are also unknown; if they both have unknown
|
|
|
values, the user doesn't know whether or not they both have the same value.
|
|
|
-<H2>EXAMPLES</H2>
|
|
|
+<h2>EXAMPLES</h2>
|
|
|
To compute the average of two raster map layers
|
|
|
-<EM>a</EM> and <EM>b</EM>:
|
|
|
-<div class="code"><PRE>
|
|
|
+<em>a</em> and <em>b</em>:
|
|
|
+<div class="code"><pre>
|
|
|
ave = (a + b)/2
|
|
|
</pre></div>
|
|
|
To form a weighted average:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
ave = (5*a + 3*b)/8.0
|
|
|
</pre></div>
|
|
|
To produce a binary representation of the raster map layer
|
|
|
-<EM>a</EM> so that category 0 remains 0 and all other categories become 1:
|
|
|
-<div class="code"><PRE>
|
|
|
+<em>a</em> so that category 0 remains 0 and all other categories become 1:
|
|
|
+<div class="code"><pre>
|
|
|
mask = a != 0
|
|
|
</pre></div>
|
|
|
This could also be accomplished by:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
mask = if(a)
|
|
|
</pre></div>
|
|
|
-To mask raster map layer <EM>b</EM> by raster map layer <EM>a</EM>:
|
|
|
-<div class="code"><PRE>
|
|
|
+To mask raster map layer <em>b</em> by raster map layer <em>a</em>:
|
|
|
+<div class="code"><pre>
|
|
|
result = if(a,b)
|
|
|
</pre></div>
|
|
|
To change all values below 5 to NULL:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
newmap = if(map<5, null(), 5)
|
|
|
</pre></div>
|
|
|
The graph function allows users to specify a x-y conversion using
|
|
@@ -512,11 +512,11 @@ pairs. Any x value lower the lowest x value (i.e. first) will have
|
|
|
the associated y value returned. Any x value higher than the last
|
|
|
will similarly have the associated y value returned. Consider the
|
|
|
request:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
newmap = graph(map, 1,10, 2,25, 3,50)
|
|
|
</pre></div>
|
|
|
X (map) values supplied and y (newmap) values returned:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
0, 10
|
|
|
1, 10,
|
|
|
1.5, 16.5
|
|
@@ -524,98 +524,98 @@ X (map) values supplied and y (newmap) values returned:
|
|
|
4, 50
|
|
|
100, 50
|
|
|
</pre></div>
|
|
|
-<H2>NOTES</H2>
|
|
|
+<h2>NOTES</h2>
|
|
|
Extra care must be taken if the expression is given on the command line.
|
|
|
Some characters have special meaning to the UNIX shell.
|
|
|
These include, among others:
|
|
|
-<P>
|
|
|
+<p>
|
|
|
* ( ) > & |
|
|
|
-<P>
|
|
|
+<p>
|
|
|
It is advisable to put single quotes around the expression; e.g.:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
result = 'elevation * 2'
|
|
|
</pre></div>
|
|
|
Without the quotes, the *, which has special meaning to the UNIX shell,
|
|
|
-would be altered and <EM>r.mapcalc</EM> would see something other than the *.
|
|
|
-<P>
|
|
|
-If the input comes directly from the keyboard and the <EM>result</EM> raster
|
|
|
+would be altered and <em>r.mapcalc</em> would see something other than the *.
|
|
|
+<p>
|
|
|
+If the input comes directly from the keyboard and the <em>result</em> raster
|
|
|
map layer exists, the user will be asked if it can be overwritten.
|
|
|
-Otherwise, the <EM>result</EM> raster map layer will automatically be
|
|
|
+Otherwise, the <em>result</em> raster map layer will automatically be
|
|
|
overwritten if it exists.
|
|
|
-<P>
|
|
|
-Quoting <EM>result</EM> is not allowed.
|
|
|
-However, it is never necessary to quote <EM>result</EM> since
|
|
|
+<p>
|
|
|
+Quoting <em>result</em> is not allowed.
|
|
|
+However, it is never necessary to quote <em>result</em> since
|
|
|
it is always taken to be a raster map layer name.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
For formulas that the user enters from standard input
|
|
|
(rather than from the command line), a line continuation feature now exists.
|
|
|
-If the user adds \e to the end of an input line, <EM>r.mapcalc</EM> assumes that
|
|
|
+If the user adds \e to the end of an input line, <em>r.mapcalc</em> assumes that
|
|
|
the formula being entered by the user continues on to the next input line.
|
|
|
There is no limit to the possible number of input lines
|
|
|
or to the length of a formula.
|
|
|
-<P>
|
|
|
-If the <EM>r.mapcalc</EM> formula entered by the user is very long,
|
|
|
+<p>
|
|
|
+If the <em>r.mapcalc</em> formula entered by the user is very long,
|
|
|
the map title will contain only some of it, but most (if not all) of
|
|
|
-the formula will be placed into the history file for the <EM>result</EM> map.
|
|
|
-<P>
|
|
|
-When the user enters input to <EM>r.mapcalc</EM> non-interactively on
|
|
|
+the formula will be placed into the history file for the <em>result</em> map.
|
|
|
+<p>
|
|
|
+When the user enters input to <em>r.mapcalc</em> non-interactively on
|
|
|
the command line, the program will not warn the user not to overwrite
|
|
|
existing map layers. Users should therefore take care to assign program
|
|
|
outputs raster map names that do not yet exist in their current mapsets.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
The environment variable GRASS_RND_SEED is read to initialise the
|
|
|
random number generator.
|
|
|
-<H2>BUGS</H2>
|
|
|
+<h2>BUGS</h2>
|
|
|
Continuation lines must end with a \ and have NO trailing white space
|
|
|
(blanks or tabs). If the user does leave white space at the end of
|
|
|
-continuation lines, the error messages produced by <EM>r.mapcalc</EM> will
|
|
|
+continuation lines, the error messages produced by <em>r.mapcalc</em> will
|
|
|
be meaningless and the equation will not work as the user intended.
|
|
|
This is important for the eval() function.
|
|
|
-<P>
|
|
|
-Error messages produced by <EM>r.mapcalc</EM> are almost useless.
|
|
|
-In future, <EM>r.mapcalc</EM> should make some attempt
|
|
|
+<p>
|
|
|
+Error messages produced by <em>r.mapcalc</em> are almost useless.
|
|
|
+In future, <em>r.mapcalc</em> should make some attempt
|
|
|
to point the user to the offending section of the equation, e.g.:
|
|
|
-<div class="code"><PRE>
|
|
|
+<div class="code"><pre>
|
|
|
x = a * b ++ c
|
|
|
ERROR: somewhere in line 1: ... b ++ c ...
|
|
|
</pre></div>
|
|
|
-<P>
|
|
|
-Currently, there is no comment mechanism in <EM>r.mapcalc</EM>.
|
|
|
+<p>
|
|
|
+Currently, there is no comment mechanism in <em>r.mapcalc</em>.
|
|
|
Perhaps adding a capability that would cause the entire line to be
|
|
|
ignored when the user inserted a # at the start of a line
|
|
|
as if it were not present, would do the trick.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
The function should require the user to type "end" or "exit" instead
|
|
|
of simply a blank line. This would make separation of multiple scripts
|
|
|
separable by white space.
|
|
|
-<P>
|
|
|
+<p>
|
|
|
r.mapcalc does not print a warning in case of operations on NULL cells.
|
|
|
It is left to the user to utilize the isnull() function.
|
|
|
-<H2>SEE ALSO</H2>
|
|
|
-<B><A HREF="http://grass.itc.it/gdp/raster/mapcalc-algebra.pdf">r.mapcalc: An Algebra for GIS and Image
|
|
|
-Processing</A></B>, by Michael Shapiro and Jim Westervelt, U.S. Army
|
|
|
+<h2>SEE ALSO</h2>
|
|
|
+<b><a href="http://grass.itc.it/gdp/raster/mapcalc-algebra.pdf">r.mapcalc: An Algebra for GIS and Image
|
|
|
+Processing</a></b>, by Michael Shapiro and Jim Westervelt, U.S. Army
|
|
|
Construction Engineering Research Laboratory (March/1991).
|
|
|
-<P>
|
|
|
-<B><A HREF="http://grass.itc.it/gdp/raster/mapcalc.pdf">Performing Map Calculations on GRASS Data:
|
|
|
-r.mapcalc Program Tutorial</A></B>, by Marji Larson, Michael Shapiro and Scott
|
|
|
+<p>
|
|
|
+<b><a href="http://grass.itc.it/gdp/raster/mapcalc.pdf">Performing Map Calculations on GRASS Data:
|
|
|
+r.mapcalc Program Tutorial</a></b>, by Marji Larson, Michael Shapiro and Scott
|
|
|
Tweddale, U.S. Army Construction Engineering Research Laboratory (December
|
|
|
1991)
|
|
|
<p>
|
|
|
Grey scale conversion is based on the C.I.E. x,y,z system where y represents
|
|
|
luminance. See "Fundamentals of Digital Image Processing,"
|
|
|
by Anil K. Jain (Prentice Hall, NJ, 1989; p 67).
|
|
|
-<P>
|
|
|
-<EM>
|
|
|
-<A HREF="g.region.html">g.region</A>,
|
|
|
-<A HREF="r.bitpattern.html">r.bitpattern</A>,
|
|
|
-<A HREF="r.blend.html">r.blend</A>,
|
|
|
-<A HREF="r.colors.html">r.colors</A>,
|
|
|
-<A HREF="r.fillnulls.html">r.fillnulls</A>
|
|
|
-</EM>
|
|
|
-<H2>AUTHORS</H2>
|
|
|
+<p>
|
|
|
+<em>
|
|
|
+<a href="g.region.html">g.region</a>,
|
|
|
+<a href="r.bitpattern.html">r.bitpattern</a>,
|
|
|
+<a href="r.blend.html">r.blend</a>,
|
|
|
+<a href="r.colors.html">r.colors</a>,
|
|
|
+<a href="r.fillnulls.html">r.fillnulls</a>
|
|
|
+</em>
|
|
|
+<h2>AUTHORS</h2>
|
|
|
Michael Shapiro, U.S.Army Construction Engineering
|
|
|
Research Laboratory
|
|
|
-<P>
|
|
|
+<p>
|
|
|
Glynn Clements
|
|
|
<p><i>Last changed: $Date$</i>
|
|
|
</body>
|