Map Algebra Operations: Using The Help System To Learn About Objects and Functions
Map Algebra Operations: Using The Help System To Learn About Objects and Functions
Function lookup:
If you know the name of a function, the quickest way to look up its usage is to use the
Index method. Try using the index method to look up the description for '+'.
Consider this help area an important resource to find what you can do. In addition, you’ll
need to understand what these functions do, and what parameters they need in order to
use them.
Functions are also geoprocessing
¾ Explore the usage of the Aspect function (in the tools in ArcToolbox
index it’s listed as Remember that each of these Map
“Aspect tool/command”). Look at the Algebra functions is also a tool you can
Illustration section, Usage Tips, and Map Algebra access via ArcToolbox. Aspect is a
syntax. tool in the Surface toolset of the
¾ Now look at the Slope function. Spatial Analyst Toolbox. You can
also use the index tab in ArcToolbox to
? How does the syntax differ for these two find it by name. It’s a good idea to
functions? (Look at the inputs required) explore the various ways of accessing
tools: as map algebra functions and
ArcToolbox tools.
¾ Explore other functions to get an idea of what is
available, and remember how to get here in the
future. Remember that you can also find function descriptions by using the Index
method, and you should make a habit of looking them up this way as you learn about
them, or as you are using them in the future.
6-1
Arithmetic operators
While exploring cell and extent settings in the Analysis Properties, we used the arithmetic
addition operator (+) with expressions such as ([one] + [two]). What that did was add all
cells in one raster to the corresponding cell in another raster, assigning the resulting
values to a temporary raster as output. If you have a look at the Raster Calculator, you’ll
see that there are several other possibilities, and you can string these together into more
complex map algebra expressions, like ([four] – [one]) / [two]). Other operators are in
the form of functions, such as square root (sqrt([slope])), square (sqr([curvature]) or
raising a raster to a power (e.g. pow([slope], 1.5).
¾ Have a look in the help section we were just looking at to see what operators are
supported, and how to use them.
6-2
? How would you create a raster that represents all areas at greater than 500 feet
elevation?
¾ Now put them together with the AND operator: Find all areas cropland-pasture areas
above 500 feet [Note that you can use the result of the last operation for this, or you
could do it with one statement], as below:
HiFarm = ([Landuse] eq 21) and ([Elev] > 500)
Selection functions
Selection is similar to creating true-false (Boolean) rasters. The difference is you end up
with the values you select, not the 1’s and 0’s of Boolean rasters. Another difference is
the areas you don’t select end up with nodata assigned, instead of zero. There are several
selection functions – each creates a new raster with cell values retained for selected cells
and nodata assigned to unselected cells.
Selection methods include the in operator, the select function, the selectmask function,
and a set of graphical select functions (selectpoint, selectbox, selectcircle,
selectpolygon).
6-3
? First a review question: What constitutes a mask raster? Specifically, what value
in a mask raster is actually used?
¾ Add the pub layer, then select all areas not on public land, using the Raster
Calculator statement
private = select([pub], 'value = 0')
¾ Explore the private raster you've created. Turn off other rasters to better see what
you're looking at.
? What value is assigned to private lands in the output raster? __________
? What value is assigned to public lands in the output raster? __________
¾ Use Spatial Analyst Options to set the mask raster to Private, and both extent and cell
size to Same as Private.
¾ Use the Raster Calculator to apply the mask to elev (you'll need to add it first) with
the expression [elev].
? What does this tell you about the difference between zero and nodata?
Conditional Processing
Often we need to assign one value if a condition is true, and another if it is false. If
you've done much computer programming before, you will recognize the importance of
the if (condition) then (do this) else (do this other thing) structure. These situations are
very common, and can be applied to raster values as well.
Grid in fact supports the use of if...then...else structures (though only in AML programs),
but many seasoned Grid programmers find the Con statement more efficient since it
allows you to put in one line what would take several lines with if...then...else structures
[this preference is not at all universal however, since the more verbose if...then...else
structures are often seen as more readable.]
6-4
The value to assign could come from a single value, from a raster, or from any other
expression involving more than one raster or value. An expression has a value: for
instance the expression “2 + 2” has a value of 4, “[elev] – 100” has a value of 100 less
than the elevation for each cell.
¾ Let’s use the Con function to combine information from two data sources – land use
codes and public lands. We want to assign a 99 code to all public lands, and
otherwise assign the value from land use. Create an output raster called Lu_pub99
with Raster Calculator which has land-codes for all areas of non-public land (pub=0,
or pub=false), but assigns the value 99 to all public lands (pub>0, or pub=true). (By
now you should know that you need to add the Pub raster to the view.)
Since all non-zero values are considered “true” and zero is “false”, we could also write
this simply as Pub99 = Con([Pub], 99, [Landuse])
The con function is arguably the most important of all functions. Don’t leave this
section until you understand its use.
IsNull
The IsNull function has the usage: IsNull(<aRaster>)
and it returns a new Boolean raster with the value of 1 (true) if that cell in aRaster has a
value of nodata; otherwise, it returns the value of 0 (false).
6-5
SetNull
The SetNull function has the usage
SetNull (<Condition>, <Value to assign if false>)
and it returns a raster for which cells that mean the <condition> are assigned nodata, and
other cells are assigned the <value to assign if false>. The value assigned could come
from a raster you specify or a constant you give.
¾ Use Raster Calculator to create a new raster for which you change the zero cells in
pub (zero would represent non-public land) to nodata, using the following
expression (you'll need to create a new view and add the pub layer from hmbarea
first):
¾ Use SetNull to create a raster that excludes elevations of greater than 1000 feet or on
state land (pub == 2). Make sure to clear any mask settings first.
¾ Display this raster to see the result, then use this new mask to clip the geology raster.
As a good practice, you should get used to setting the mask to <None> in Spatial Analyst
Options when you're done. (Grid: setmask off)
6-6
Combining functions
Functions can be made of functions, and combining them can greatly extend the
analytical capabilities of Spatial Analyst without having to create a number of
intermediate rasters.
For example, by applying a conditional to the Boolean null detector IsNull as in the
example below, nodata values can be converted into numbers you can use. To change
nodata in the city raster to zero, for example, use the following Raster Calculator
expression:
Con(IsNull([City]), 0, [City])
¾ Try the above, and note how the legend and display differs from the city raster.
There are two useful operators in Grid that are not supported directly in Spatial Analyst,
but can be created by combining functions. One of these is OVER, which replaces values
in one raster with non-zero values in another, similar to a cover command in some other
raster GISs and also similar to the vector UPDATE command in Arc/Info. The other is
DIFF which returns the values of cells in one raster that differ from the second raster.
(Note that we didn’t include square brackets around the input rasters newdev and
landuse. This works as long as our working directory is set to the hmbarea folder we’ve
been using, since these rasters exist there. You should make sure that this is set
correctly.)
¾ In a view, compare the results with the original by alternately displaying the three
rasters (landuse, newdev, and lu-upd).
? What’s the most common type of land use replaced by the new development? You
might want to join the attribute table with landuse.exp in the info directory of
hmbarea, so you can use descriptive names instead.
6-7
Combinatorial and Boolean Operators
We’ve been using AND (&) and OR (|) operators. There is a set of comparable
combinatorial operators called CAND and COR. The only difference you’ll find is what
you end up with in the attribute table. We haven’t explored XOR (!), which does an
exclusive OR – only true if only one of the inputs is true, but there’s also a combinatorial
version CXOR.
¾ With two of the raster layers we have available, test to determine the difference
between AND and CAND. (The same should apply to OR and COR, XOR and
CXOR.)
? What does CAND do that AND doesn’t?
With the tools you’ve learned, do the following analysis and create a report with a
map that displays your results: You need to find areas that are generally south-facing
(aspect is between 90° and 270°), on granitic bedrock, in some kind of rangeland, and
not on a road or stream. Use the result as a mask and create a map of the type of
rangeland that exists. For areas outside the mask, display a hillshade that has been
altered to have a brighter value (200) in the ocean (derived from landuse), but make
sure to use 30-m cells as the output. In your report, record your steps, illustrating the
use of Boolean operators, nodata handling, and functions such as con. Save it using
the established naming convention (something like “Smith_06_Ras4.doc”) and a PDF
(named something like “Smith_06_Ras4.pdf”).
6-8