0% found this document useful (0 votes)
60 views8 pages

Map Algebra Operations: Using The Help System To Learn About Objects and Functions

The document discusses various map algebra functions and operations that can be used to analyze geospatial data. It explains that functions like aspect, slope, addition, subtraction, and boolean operators can be used in raster calculator expressions to perform conditional analyses and selections. Graphical selection functions like selectcircle can also be used to extract data within a given radius of a point. The conditional (Con) function allows assigning one value if a condition is true and another value if it is false.

Uploaded by

James Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views8 pages

Map Algebra Operations: Using The Help System To Learn About Objects and Functions

The document discusses various map algebra functions and operations that can be used to analyze geospatial data. It explains that functions like aspect, slope, addition, subtraction, and boolean operators can be used in raster calculator expressions to perform conditional analyses and selections. Graphical selection functions like selectcircle can also be used to extract data within a given radius of a point. The conditional (Con) function allows assigning one value if a condition is true and another value if it is false.

Uploaded by

James Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Ras.4.

Map Algebra Operations


Now it’s time to get into the tools we’ll use to analyze data – many of which are map
algebra functions. To help us understand these tools, we should explore the help system
a bit more to help us understand what the tools do.

Using the help system to learn about objects and functions


¾ In the process of completing the upcoming exercises, you will be learning about new
functions available for map algebra operations. This might be a good time to review
the Map Algebra and Arc Objects Functional Reference described in the first
exercise, to learn how to do more with Map Algebra.

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.

Now on to the exercise.


¾ Start by setting the workspace to the hmbarea workspace folder in raster. Set your
extent to union of inputs, your cell size to maximum of inputs (the defaults).

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.

Creating true-false rasters with Boolean expressions


Boolean expressions are evaluated as true (1) or false (0) in any computer language, and
are produced using values and relational operators such as '>' '<' '='. Boolean expressions
can be composed of multiple Boolean expressions using Boolean operators such as AND
and OR, based on Boolean rules.
With GRID and Spatial Analyst map algebra, as with arithmetic expressions, variables
can either be constants or rasters. The result of Boolean expressions are rasters. These
can be created using the Raster Calculator.
[What you’ll be given below are Raster Calculator expressions, or sometimes not even
that. Note that in keeping with my philosophy of giving you less and less guidance on
how to do things, as you learn more, you may have to do other things, like open a new
view in some cases, or change the legend to better display results]
¾ Start a new map, add landuse, and create a raster that identifies all cropland and
pasture areas (landuse value equal to 21). Use the Raster Calculator buttons to make
sure you don’t enter a single equal sign – which would do something very different :
assigns the expression to the right to the object to the left. The following uses a
double equal sign, which simply means “is equal to”. Another way to be careful is to
use "eq" instead of double equal sign. Do one of these two equivalents:
[landuse] == 21 note: there are two equal signs in a row.
[landuse] eq 21
9 I recommend using "eq" if you're typing it, and "= =" if you're using the buttons.
There are also other abbreviations, "gt" for >, "ge" for >=, "lt" for <, "le" for <=.
? What if you didn't know the code meanings (e.g. that 21 means "cropland and
pasture"). How would you deal with this?

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).

Use Select to create an urban land use raster


¾ Use the statement
urbanlu = select([landuse], 'value < 20')
¾ Explore the result. Turn off other rasters to better see, and use the identify tool to
see values.
? What value is assigned to non-urban areas? _________

The selection we just completed is similar to using an attribute table to select by


attributes. You will remember that we used attribute tables to select granite bedrock
from the geology raster, and evergreen forest from landuse. Why two methods? The
previous method works well in an interactive environment, where we use ArcMap's
tools to explore and process our data, one step at a time. Using Map Algebra
functions like select does this via a command, and thus easily translates to automating
a sequence of steps in a macro. GIS professionals doing a lot of raster analysis have
found macros a great way to save time, since many analyses can require many steps.

Use Select to create a mask raster


In the earlier exercise, we used the attribute table to select records then used this selection
to create a mask raster. Let's continue with our Map Algebra method, using the Raster
Calculator.

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?

Select with a Graphic


There are three graphical selection methods: selectbox, selectpoint, selectpolygon, and
selectcircle. Look these up in the help system.
¾ Use selectcircle to select land uses within 1500 m of a location we've determined
UTM coordinates with a GPS receiver:
Lucircle = SelectCircle(landuse, 555845, 4149817, 1500)

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.]

The simplest use of the Con function is:

Con (<condition>, <value to assign if true>, <value to assign if false>)

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.)

Lu_Pub99 = Con([Pub] > 0, 99, [Landuse])

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.

Dealing with Nothingness


The nodata value is another very important thing to understand. The first thing to realize
is that it's not zero or false. It's used with cells that we have no values at all. We have
used it to create a mask raster, and it often results from conversion of various sorts – like
converting roads features to a raster – non-roads have nodata (null) values. Often
however we end up needing to change cell values to and from nodata. We may want
zero cells to be nodata and vice versa. The functions IsNull and SetNull have many uses,
giving us the means to detect nodata cells, and also to set cells to nodata.

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).

¾ Create a Boolean raster of unincorporated areas, with the statement:


Unincorp = IsNull([City])

? How might you use this?

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):

NewPub = SetNull([Pub] == 0, [Pub]) remember the double equal


sign

? Why did we have to use pub twice?

Using SetNull to create a mask


Another way to create a mask is with the SetNull function, which sets to nodata all areas
specified in the selection expression. We'll clip the

¾ 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.

mask2 = setnull(elev > 1000 or pub eq 2, 1)

¾ 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.

Updating an area with Over


¾ Update the landuse raster with a new (fictitious) development in Half Moon Bay:

lu-upd = newdev over landuse

(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).

? Can you see the effect? What is it?

Detecting change with Diff


DIFF in GRID returns the value of the first raster for cells where it differs from the
second raster.
¾ Use DIFF operation to find what land-use types had been replaced by the new
development.
The GRID method would be:
LuDiff = landuse diff 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”).

End of Exercise 4 -- save your project to raster as ras4.mxd

6-8

You might also like