[GRASS-SVN] r67790 - grass/branches/releasebranch_6_4/raster/r.mapcalc
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 8 05:22:52 PST 2016
Author: neteler
Date: 2016-02-08 05:22:52 -0800 (Mon, 08 Feb 2016)
New Revision: 67790
Modified:
grass/branches/releasebranch_6_4/raster/r.mapcalc/r.mapcalc.html
grass/branches/releasebranch_6_4/raster/r.mapcalc/r3.mapcalc.html
Log:
r.mapcalc manual: fix if() statement formula (trac #2883); r3.mapcalc: partial sync to 70 HTML style
Modified: grass/branches/releasebranch_6_4/raster/r.mapcalc/r.mapcalc.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.mapcalc/r.mapcalc.html 2016-02-08 13:11:27 UTC (rev 67789)
+++ grass/branches/releasebranch_6_4/raster/r.mapcalc/r.mapcalc.html 2016-02-08 13:22:52 UTC (rev 67790)
@@ -578,9 +578,9 @@
<div class="code"><pre>
result = if(a,b)
</pre></div>
-To change all values below 5 to NULL:
+To change all values below 5 to NULL, keep otherwise:
<div class="code"><pre>
-newmap = if(map<5, null(), 5)
+newmap = if(map < 5, null(), map)
</pre></div>
The graph() function allows users to specify a x-y conversion using
pairs of x,y coordinates.
Modified: grass/branches/releasebranch_6_4/raster/r.mapcalc/r3.mapcalc.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.mapcalc/r3.mapcalc.html 2016-02-08 13:11:27 UTC (rev 67789)
+++ grass/branches/releasebranch_6_4/raster/r.mapcalc/r3.mapcalc.html 2016-02-08 13:22:52 UTC (rev 67790)
@@ -36,19 +36,19 @@
mapset.
<p>
The formula entered to <em>r3.mapcalc</em> by the user is recorded both
-in the <em>result</em> grid title (which appears in the category file for
+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>r3.mapcalc</em> on the command line, expressions
should be enclosed within single quotes. See NOTES, below.
-<p>
-<h2>OPERATORS AND ORDER OF PRECEDENCE</h2>
+<h3>Operators and order of precedence</h3>
+
The following operators are supported:
-<div class="code"><PRE>
+<div class="code"><pre>
Operator Meaning Type Precedence
--------------------------------------------------------------
- negation Arithmetic 12
@@ -76,7 +76,7 @@
|| logical or Logical 2
||| logical or[1] Logical 2
?: conditional Logical 1
-</PRE></div>
+</pre></div>
(modulus is the remainder upon division)
<p>
[1] The &&& and ||| operators handle null values differently to other
@@ -91,43 +91,44 @@
<p>
-<h2>3D GRID NAMES</h2>
-Anything in the expression which is not a number, operator, or function
-name is taken to be a 3D grid name. Examples:
-<p>
-<div class="code"><PRE>
+<h3>3D Grid names</h3>
+
+Anything in the expression which is not a number, operator, or function name
+is taken to be a 3D grid name.
+Examples:
+<p><div class="code"><pre>
volume
x3
3d.his
-</PRE></div>
+</pre></div>
<p>
Most GRASS raster map layers and 3D grids meet this naming convention.
However, if a 3D grid has a name which conflicts with the above rule, it
should be quoted. For example, the expression
<p>
-<div class="code"><PRE>
+<div class="code"><pre>
x = a-b
-</PRE></div>
+</pre></div>
<p>
would be interpreted as: x equals a minus b, whereas
<p>
-<div class="code"><PRE>
+<div class="code"><pre>
x = "a-b"
-</PRE></div>
+</pre></div>
<p>
-would be interpreted as: x equals the 3D grid named <em>a-b</em>
+would be interpreted as: x equals the 3D grid named <em>a-b</em>
<p>
Also
<p>
-<div class="code"><PRE>
+<div class="code"><pre>
x = 3107
-</PRE></div>
+</pre></div>
<p>
would create <em>x</em> filled with the number 3107, while
<p>
-<div class="code"><PRE>
+<div class="code"><pre>
x = "3107"
-</PRE></div>
+</pre></div>
<p>
would copy the 3D grid <em>3107</em> to the 3D grid <em>x</em>.
@@ -141,15 +142,15 @@
and specify the mapset from which to select the 3D grid. This is done by
specifying the 3D grid name in the form:
<p>
-<div class="code"><PRE>
+<div class="code"><pre>
name at mapset
-</PRE></div>
+</pre></div>
<p>
For example, the following is a legal expression:
<p>
-<div class="code"><PRE>
+<div class="code"><pre>
result = x at PERMANENT / y at SOILS
-</PRE></div>
+</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,
@@ -157,7 +158,8 @@
<p>
-<h2>THE NEIGHBORHOOD MODIFIER</h2>
+<h3>The neighborhood modifier</h3>
+
3D grids are data base files stored in voxel format, i.e., three-dimensional
matrices of float/double values. In <em>r3.mapcalc</em>, 3D grids may be
followed by a <em>neighborhood</em> modifier that specifies a relative offset
@@ -172,10 +174,9 @@
permits the development of neighborhood-type filters within a single 3D
grid or across multiple 3D grids.
-<p>
+<h3>Functions</h3>
-<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>
@@ -186,7 +187,7 @@
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>
+<div class="code"><pre>
function description type
---------------------------------------------------------------------------
abs(x) return absolute value of x *
@@ -222,8 +223,9 @@
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
@@ -235,16 +237,17 @@
nsres() current north-south resolution
tbres() current top-bottom resolution
null() NULL value
-</PRE></div>
+</pre></div>
Note, that the row(), col() and depth() indexing starts with 1.
-<h2>FLOATING POINT VALUES IN THE EXPRESSION</h2>
+<h3>Floating point values in the expression</h3>
+
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.
@@ -260,29 +263,30 @@
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>
- r.mapcalc "ndvi=float(lsat.4 - lsat.3) / (lsat.4 + lsat.3)"
-</PRE></div>
+<div class="code"><pre>
+ r3.mapcalc "ratio = float(soil.4 - soil.3) / soil.3)"
+</pre></div>
-<h2>NULL support</h2>
+<h3>NULL support</h3>
+
<ul>
<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>
+<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>
x &&& false == false
false &&& x == false
x ||| true == true
true ||| x == true
-</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>
+</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>
if(x)
NULL if x is NULL; 0 if x is zero; 1 otherwise
if(x,a)
@@ -292,17 +296,17 @@
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>
-<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.
+</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>
</ul>
<p>
NULL support: Please note that any math performed with NULL cells always
@@ -312,40 +316,40 @@
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>
-C=A + if(isnull(B),0,B)
-</PRE></div>
+<div class="code"><pre>
+C = A + if(isnull(B),0,B)
+</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>
+if(x,a,b,c) = c if x < 0
+</pre></div>
More generally, all operators and most functions return NULL if *any*
of their arguments are NULL.
<br>
@@ -358,7 +362,7 @@
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>
@@ -379,36 +383,37 @@
<h2>EXAMPLES</h2>
To compute the average of two 3D grids
<em>a</em> and <em>b</em>:
-<div class="code"><PRE>
+<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 3D grid
<em>a</em> so that category 0 remains 0 and all other categories become 1:
-<div class="code"><PRE>
+<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 3D grid <em>b</em> by 3D grid <em>a</em>:
-<div class="code"><PRE>
+<div class="code"><pre>
result = if(a,b)
</pre></div>
-To change all values below 5 to NULL:
-<div class="code"><PRE>
-newmap = if(map<5, null(), 5)
+To change all values below 5 to NULL, keep otherwise:
+<div class="code"><pre>
+newmap = if(map < 5, null(), map)
</pre></div>
-The graph function allows users to specify a x-y conversion using
+The graph() function allows users to specify a x-y conversion using
pairs of x,y coordinates.
In some situations a transformation from one value to another is not
easily established mathematically, but can be represented by a 2-D
-graph. The graph() function provides the opportunity to accomplish
-this. An x-axis value is provided to the graph function along with
+graph and then linearly interpolated. The graph() function provides
+the opportunity to accomplish this.
+An x-axis value is provided to the graph function along with
the associated graph represented by a series of x,y pairs. The x
values must be monotonically increasing (each larger than or equal to
the previous). The graph function linearly interpolates between
@@ -416,14 +421,14 @@
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
+1, 10
+1.5, 17.5
2.9, 47.5
4, 50
100, 50
@@ -438,7 +443,7 @@
* ( ) > & |
<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,
@@ -471,38 +476,38 @@
random number generator.
-<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
+<h2>KNOWN ISSUES</h2>
+
+Continuation lines must end with a <tt>\</tt> and have <em>no</em> 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>r3.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
-to point the user to the offending section of the equation, e.g.:
-<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>r3.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>
-The function should require the user to type "end" or "exit" instead
+This is particularly important for the <tt>eval()</tt> function.
+<p><!-- STILL TRUE ??-->
+Currently, there is no comment mechanism in <em>r3.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>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>
-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.
+<p><em>r3.mapcalc</em> does not print a warning in case of operations on
+NULL cells. It is left to the user to utilize the <tt>isnull()</tt> function.
<h2>SEE ALSO</h2>
-<b><a href="http://grass.osgeo.org/uploads/grass/history_docs/mapcalc-algebra.pdf">r.mapcalc: An Algebra for GIS
-and Image Processing</a></b>, by Michael Shapiro and Jim Westervelt, U.S. Army
+<em>
+<a href="g.region.html">g.region</a>,
+<a href="r3.colors.html">r3.colors</a>,
+<a href="r.mapcalc.html">r.mapcalc</a>
+</em>
+
+
+<h2>REFERENCES</h2>
+
+<b><a href="http://grass.osgeo.org/uploads/grass/history_docs/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.osgeo.org/uploads/grass/history_docs/mapcalc.pdf">Performing Map Calculations on GRASS Data:
@@ -510,10 +515,11 @@
Tweddale, U.S. Army Construction Engineering Research Laboratory (December
1991)
<p>
+Neteler, M. (2001): Volume modelling of soils using GRASS GIS 3D tools. - in:
+Brovelli, M. (ed.)(2001): The Geomatics Workbook N. 2. Politecnico di Milano,
+Italy (ISSN 1591-092X) (<a href="http://geomatica.como.polimi.it/workbooks/n2/articoli/mn2.pdf">PDF</a>)
-<em><a href="r.mapcalc.html">r.mapcalc</a></em>
-
<h2>AUTHORS</h2>
Tomas Paudits & Jaro Hofierka, funded by GeoModel s.r.o., Slovakia
<br><a href="mailto:tpaudits at mailbox.sk">tpaudits at mailbox.sk</a>,
@@ -523,6 +529,6 @@
<i>Last changed: $Date$</i>
<hr>
<p><a href="index.html">Main index</a> - <a href="raster3D.html">raster3D index</a> - <a href="full_index.html">Full index</a>
-<p>© 1999-2012 <a href="http://grass.osgeo.org">GRASS Development Team</a>
+<p>© 1999-2016 <a href="http://grass.osgeo.org">GRASS Development Team</a>
</body>
</html>
More information about the grass-commit
mailing list