From now on we will assume all grids have been resampled if necessary to the same cell size and mesh. By "mesh" we mean simply the set of coordinates of cell boundaries. A grid with a cell size of 10 may have a mesh in the X-direction of {..., -10, 0, 10, 20, ...} or it may have a mesh of {..., -3.1, 6.9, 16.9, 26.9, ...}, for example.
Therefore, unless it is otherwise specified, the cells in all grids involved in Map Algebra operations will overlap perfectly. This simplification is both conceptual and practical: it reduces grid operations to operations on rectangular arrays of numbers. For operations where the locations of the numbers matter, each grid value will be considered as located at the center of its cell. With an X-mesh of {..., -10, 0, 10, ...}, for example, the X-coordinates of cell centers will be at {..., -5, 5, 15, ...}.
The Spatial Analyst Map Calculator refers to grids by their theme names. The names are placed within square brackets []. In most cases, Spatial Analyst uses the familiar symbols of algebra to denote the corresponding grid operations.
The Map Calculator expressions are in computer font; they are followed by comments in italics. The following exposition does not provide an exhaustive list of all Map Algebra operations, nor does it give a complete summary of Spatial Analyst capabilities. For more information, consult the ArcView help for "Grid (class)".
![]()
Grid data sets come from many sources: remote sensing devices, converted topographic maps, interpolated point data, conversion from vector features, and derived from other features (through distance, proximity, and density calculations, for instance). Sometimes it is useful to create a grid ab initio for use in subsequent calculations or modeling.
|
Create a grid of constant values |
1.AsGrid Create an integer grid with a value of 1 in every cell.
3.1415927.AsGrid Create a floating-point grid with a value of Pi in every cell.
|
Create a grid of random values |
![]() |
Grid.MakeRandom Populate the cell values with independent identically distributed (iid) floating point values between 0 and 1. "Grid" in this expression is a keyword and should not be changed. |
![]() |
Grid.MakeNormal Populate the cell values with iid values from the standard Normal distribution (mean 0 and variance 1). |
Random grids are exceptionally useful. Use them (appropriately scaled) to add noise to real datasets. This is useful for sensitivity analysis and for representing uncertainty. Use them to create grids of data for testing algorithms and models. Use them as inputs to simulations having stochastic (random) components.
Anything you can do with a single number you can do with a grid of numbers, simply by processing each number independently. For example, you can negate numbers, rescale them (that is, multiply them by a constant), compare them to other numbers, and apply functions to them.
To illustrate different applications succinctly, suppose that three grids appear in the current view: "Integer" is an integer grid, "Float" is a floating-point grid, and "Indicator" is an integer grid containing only 0, 1, and NoData values. A value of 0 can be interpreted as a logical "false" and a value of 1 as a logical "true". In practice, of course, you will replace these names by the names of your themes.
| Rescale a grid: that is, multiply all its values by a constant value. |
[Float] * 3.1415927 Multiply all values by Pi
[Integer].Float * (39.37/12) Convert meters to feet
[Integer] * (-1) Negate all values
Not [Indicator] Negate all logical values: 0 becomes 1, 1 becomes 0
| Compare a grid to a constant value. The result of a comparison is 1 for the cells where the comparison is true, 0 where the comparison is false, and NoData where the original value is NoData. |
[Float] < 1 Returns 1 where values are less than 1, otherwise returns 0
[Integer] = 0 Converts all zeros to ones and all other values to zeros
| Apply a mathematical (or logical) function to a grid, cell by cell. |
[Float].Cos Computes the cosine of each value (interpreted as radians).
[Float].Int Rounds all values and converts the result to an integer grid.
[Float].Sqrt Computes the square root of each value. Negative values return NoData (because the square root is not defined for negative values).
[Float].IsNull Returns 1 at all cells with NoData values, otherwise returns 0.
Rescaling is good for converting units of measurement for later comparison or combination of grids.
Comparisons create feature grids: the places where the comparison is true can be considered features on the earth's surface. They map the regions where a logical condition (the comparison) holds. These could be regions where, say, ozone concentrations exceed a threshold, ocean depths are below a certain target, or land use equals a given code.
Mathematical functions are useful for changing the visualization of a grid. An equal interval classification using the square roots of the values will differ from an equal interval classification of the values themselves, for instance. Functions are also important as intermediate steps in many models.
Binary numeric operations act on ordered pairs of numbers. Likewise, binary grid operations act on the pairs of numbers obtained in each set of matching cells. The resulting grid is defined only where the two input grids overlap.
Suppose there are several floating-point grids represented by themes named "Float", "Float1", "Float2", and so on; with a similar supposition for integer and logical grids.
| Mathematical operators |
[Float] + [Integer] Converts the values in [Integer] to floats, then performs the additions.
| Logical operators |
[Float1] < [Float2] Returns 1 in each cell where [Float1]'s value is less than [Float2]'s value; otherwise, returns 0.
[Indicator1] And [Indicator2] Returns 1 where both values are nonzero, otherwise returns 0.
When you have many related grids defined in the same region, you often want to assess change: at each cell, how varied are the grid results? How large do they get? How small? What is the average? These questions make sense for numerical data.
For grids with ordinal data--that is, values that can be ordered, but which may not have any absolute meaning--you can still ask about order statistics. These are the relative rankings of values within the ordered collections of values observed at each cell.
For grids with categorical data, you might want to know at each cell whether one category predominates throughout the collection of grids and how many different categories actually appear at the cell's location.
![]() |
In all these cases, imagine a stack of grids with common mesh. |
![]() |
At each cell location there is a stack of
values, one for each grid.
The N-ary operators create a new grid whose values depend on the stack of input data at each cell location. |
The Spatial Analyst syntax for some of these requests is strange, because it wants to force expressions into the form "aGrid.Request({list of other grids})". This is inherently asymmetric because it singles out one grid in the collection to play the role of the object ("aGrid") to which the calculation is applied and leaves the other grids in the role of a list of arguments ("list of other grids"). Despite this syntax, for some requests, such as the local statistics, there is no asymmetry in the calculation itself: all the grids are equivalent. For some other requests, there is an asymmetry in the calculation: one grid plays a special role.
Spatial Analyst constructs lists with curly braces {} and separates the elements by commas.
| Compute local statistics |
[Float].LocalStats(#GRID_STATYPE_MAX, {[Float1], [Float2], [Float3]}) Computes the largest value among four grids.
[Float].LocalStats(#GRID_STATYPE_MEDIAN, {[Float1], [Float2]}) Computes the median of three values.
[Integer].LocalStats(#GRID_STATYPE_MAJORITY, {[Integer1], [Integer2]}) Computes the value occurring the most times (out of the three input values at each cell). If two or more values occur an equal number of times, Spatial Analyst returns NoData.
The Majority statistic evidently is not very useful when many ties occur: that is, when there are many cells where two or more values occur equally often.
| Compare one grid (a "base" grid) to many others simultaneously |
[Float].GridsGreaterThan({[Float1], [Float2], [Float3], [Float4]}) For each base cell in [Float], computes the number of times corresponding cells from [Float1], ..., [Float4] exceed (and do not equal) the base cell's value. There is a corresponding GridsLessThan operator.
| Combine the values of two grids based on values at a third grid |
[Indicator].Con([Float1], [Float2]) Creates a grid with the values of [Float1] where [Indicator] is nonzero and with the values of [Float2] where [Indicator] is zero.
The Con request is especially useful. You have already met it in the context of patching gaps in mosaics. In that application, [Indicator] is created as the result of a previous request (IsNull), as in
[Mosaic].IsNull.Con([Average], [Mosaic])
You can think of [Indicator] as being a stencil. The result of Con, by default, is the second grid ([Float2] or [Mosaic] in the examples). However, at cells where [Indicator] is true, the values of the first grid ([Float1] or [Average]) are "painted" over the default values. Thus the Con request is a natural vehicle for selectively editing grids.
Some more interesting examples of these operations include
| Force water to flow in river channels. In hydrological analyses, a digital elevation model (DEM) is the basis for computing water flow directions. However, irregularities in the data can perturb the results so that computed water flows wander in and out of known stream channels. To force water to stay in a channel, lower the elevations in the channels themselves. To do this you need a gridded representation of the streams and rivers, obtained perhaps by converting a vector dataset to a raster format. In this format cells containing a river channel will have values of 1 and other cells will have values of 0. Let this grid be called [River] and let the digital elevation model be called [DEM]. To lower all elevations within the river channels by 10 feet, say, use a Map Algebra expression like |
([River]=1).Con([DEM]-10, [DEM])
| Reclassify values by assigning them to bins. For example, suppose a grid [A] has floating point values known to range between 0 and 10. You would like to classify them into the ranges [0, 1], [1, 4], [4, 9], and [9, 10]. An expression like |
[A].GridsLessThan({1.AsGrid, 4.AsGrid, 9.AsGrid})
will return a value of 0 at cells where [A] is less than 1, 1 where [A] is between 1 and 4, 2 where [A] is between 4 and 9, and 3 otherwise. That is exactly what is needed.
| Identify change by computing the variety statistic. This is the number of distinct values found within a list of values. Suppose, for example, that you have grids of land use for each year in 1996, 1997, 1998, 1999, and 2000, named accordingly. You are interested in where change is occurring. A convenient way to identify locations of change is |
[1996].LocalStats(#GRID_STATYPE_VARIETY, {[1997], [1998], [1999], [2000]}) > 1
This expression will equal 1 wherever there are two or more values found among the five grids; otherwise, it will equal 0. This is much easier and faster to evaluate than by making direct comparisons among pairs of grids.
![]()
(To be continued)
![]()