Simple calculations

<< Click to Display Table of Contents >>

Navigation:  Building Blocks of Spatial Analysis > Queries, Computations and Density >

Simple calculations

Almost all GIS packages provide a wide range of calculation facilities. By simple calculations we mean arithmetic operations and standard functions applied to: (a) tabular data; (b) within queries and similar operations; and (c) applied to map layers (see further, Section 4.6, Grid Operations and Map Algebra). As with spatial queries, there are many different implementations of simple calculation operations and these are widely used, readily understandable, and applied as often to raster datasets as to vector data. A number of examples help to clarify the range of facilities provided:

(a) ArcGIS provides a field level calculator within attribute tables by right-clicking on any field (existing or newly added). This enables basic operations such as +, -, x and / to be performed, plus a range of standard functions such as cos(), exp(), log(), abs() etc. Operations are applied to one or more fields, e.g. current field=(field1+field2*100)/field3, and this process either updates the values for all records in the table selected or, if a subset have been pre-selected, updates records in just that subset. In addition an “Advanced” option is provided enabling Visual Basic for Application (VBA) commands to be entered and executed. Such commands are often needed in ArcGIS in order to add or update intrinsic data (as explicit fields in the attribute table) such as the area of a polygon or the (x,y) coordinates of a polygon centroid. Manifold implements such operations through its extended SQL query facilities and using the Query toolbar facility it provides.

(b) Simple calculations and expressions are extensively used in SQL queries and in association with spatial extensions to standard SQL. Again, the common arithmetic operators are used (extended in some cases to facilitate integer division, modulo arithmetic etc.) combined with comparison operators (e.g. =, >, < etc.) and Boolean operators (e.g. AND, OR, NOT, XOR). Since queries often involve non-numeric fields additional operators are provided to enable the use of strings, dates and times. Note that it is often possible, and sometimes simpler, to perform calculations outside of the GIS framework using standard tools, such as spreadsheet or database programs.

(c) Within raster-based GIS, and in the raster processing facilities of general purpose GIS, there is a very large set of simple calculation facilities. Such facilities are a standard part of the set of operations provided in specifically raster-based GIS packages (e.g. Idrisi, PCRaster), but are often additional components in general purpose (vector-oriented) GIS. For example in ArcGIS the majority of such tools are provided in the Spatial Analyst extension whilst in Manifold they are provided in the Surface Tools extension.

The term map algebra is often used to describe operations that combine two or more grid layers according to a simple algebraic expression, e.g. A+2*B+C/100 where A, B and C are matching grid layers (Figure 4‑36a). This is commonly the case with multi-band remote sensing data (e.g. 7 bands representing different spectral components of a single image). Map algebra may also be used where the grid resolutions do not match, in which case decisions have to be made (rules applied) on how resolution differences are to be accommodated. The example in Figure 4‑36b shows how grid C, being lower resolution, determines the resolution of the result grid. The general term for this kind of process is resampling.

Figure 4‑36 Cell-by-cell or Local operations


If distinct raster layers have different resolutions (cell sizes) then one or more must be resampled to ensure their resolutions match. The normal practice is to adjust the layers of finest resolution to match the coarsest, and to use simple nearest-neighbor interpolation to estimate values. By nearest-neighbor is meant that values are assigned based on the position of the center of the output grid relative to the centers of finer resolution input grids. Grids do not have to consist entirely of square zones, nor do they have to align precisely, but if they do not then resampling and some form of localized interpolation is inevitable.

However, map algebra refers to a far broader set of operations, extending to functions that operate on individual grid cells, blocks of grid cells or entire grid layers (often described as local, focal or neighborhood, zonal, and global analysis) as we shall see in Section 4.6 and Chapter 6. In this Section we restrict our consideration to operations that apply on a cell-by-cell or point-by-point basis (the term local is generally used for such operations).

In Idrisi, for example, pairs of images (grids of pixels) may be combined using the operators: +, -, x, /, ^ (power), maximum, minimum, and cover. These operators combine images A and B on a pixel by pixel basis, for example adding each pixel in image B to each matching pixel in image A. Operations such as maximum and minimum identify a value from corresponding positions in image A or B as appropriate, whilst the cover function creates an image just containing pixels from A except where these are zero, in which case the pixels of B are taken (showing through the “holes” in A). With the exception of + and -, all other operations are non-symmetric, i.e. A<operator>B is not equal to B<operator>A. An example application of operations of this kind would be the algebraic expression:


where C is the output raster, A and B are input raster maps (e.g. remote sensed images or image bands) of vegetation cover, with pixels in C being taken as a vegetation index (VI, with values being in the range ‑1 to +1). Note that a check is required to ensure that if A=B=0 for a pixel location then the calculation gives the result 0.

Many GIS packages allow the creation and saving of macros or scripts that implement regularly used map algebra expressions. For example TNTMips and ENVI include numerous pre-built combination formulas of this type. TNTMips holds such formulas as scripts that may be modified or augmented. For example, its two-band transformed vegetation index (TVI) script is of the form:

Here A might be the near infra-red band (Figure 4‑37A) from a remote sensing image and B the red band image (Figure 4‑37B), with the result being an index raster providing a measure of vegetation vigor (Figure 4‑37C). The basic index has the range [0,100], and as elsewhere, checks for division by 0 are required.

PCRaster, a non-commercial package designed specifically for manipulating raster data, provides a rich set of point operations, many of which have been derived from the work of Tomlin (1990). These include a similar set to those described above, i.e. arithmetic, trigonometric and logarithmic functions, coupled with Boolean and relational operators. Point operations are augmented by facilities for missing data detection and substitution, conditional expressions, data lookup and other facilities that mirror those provided in the extended SQL-type command structures described earlier.

Figure 4‑37 Map algebra: Index creation

A. Near infra-red band

B. Red band





Combination operations of this type are not confined to raster datasets. Polygon layers may be combined with raster layers, either by converting the polygon layers to rasters and then proceeding as above (the most common approach in GIS packages), or by direct support for such combinations within the GIS (as is the case with TNTMips for example).