0% found this document useful (0 votes)
80 views9 pages

Lab 4 Exercise 1: Converting Feet To Meters Using Raster Calculator

1) The document describes exercises for using raster calculator to analyze elevation, ownership, and soil rasters for identifying suitable tree farm sites. 2) Relational, Boolean, and combinatorial operators are used to identify areas that have suitable elevation, ownership by the Forest Service, and good soil types. 3) Logical operators are then used to update the landcover raster with the suitable tree farm sites identified.

Uploaded by

umar83
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)
80 views9 pages

Lab 4 Exercise 1: Converting Feet To Meters Using Raster Calculator

1) The document describes exercises for using raster calculator to analyze elevation, ownership, and soil rasters for identifying suitable tree farm sites. 2) Relational, Boolean, and combinatorial operators are used to identify areas that have suitable elevation, ownership by the Forest Service, and good soil types. 3) Logical operators are then used to update the landcover raster with the suitable tree farm sites identified.

Uploaded by

umar83
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/ 9

Lab 4

Exercise 1: Converting feet to meters using raster calculator


Map Algebra expressions are written and executed in the Raster Calculator. In this exercise, you
will convert the values in an elevation grid from feet to meters, use a function to convert the
results from floating point to integer, then learn how to save the results to a permanent grid
directly within the expression.

Step 1: Load in elevation raster


Start ArcMap. Open a new map. Load in the elevation raster from your ...\Data folder. This is the
elevation of an area near Lake Tahoe in the central Sierra Nevada Mountains. If necessary, load
the ArcGIS Spatial Analyst extension and make the Spatial Analyst toolbar visible.

Step 2: Convert feet to meters


In your Table of Contents, notice the elevation raster contains elevations that range from 6,020 to
8,835 feet. The projection of the Elevation layer is in UTM meters, so to ensure accurate
measurements, you will convert the elevation values from feet to meters. Note: 1 foot = 0.3048
meters. From the Spatial Analyst Tools menu in ArcToolbox, expand the Map Algebra menu and
double- click on Raster Calculator. Notice the Layers list shows the same raster layers that
appear in the ArcMap Table of Contents. The keypad area contains numbers and the most
commonly used operators. In the Layers list, double-click elevation to add it to the expression
box. Click the multiplication ( * ) operator. Enter the number 0.3048. Your expression should
read: "elevation" * 0.3048

Select OK. A new layer named rastercalc is added to the Table of Contents. Each cell value in
rastercalc contains the value of the corresponding cell in the elevation grid, multiplied by 0.3048.
Because the multiplier contained decimal points, the new grid is a floating-point grid. The name
rastercalc followed by a number is assigned to your output if you do not choose a name. The grid
may or may not be temporary depending on the Geoprocessing Options. To see if a layer is
temporary or permanent, open the Layer Properties for the layer and click the Source tab. Notice
the output grid was written to your scratch directory with a generic name (e.g., rastercalc), it is
floating point. You'll convert these values to integer in the next step.

Step 3: Convert floating-point values to integer


The Int Map Math function allows you to convert floating-point data to integer data. The Int
function and all other operators are case sensitive. To prevent errors, you can select operators
from the menu to the right of the keypad in Raster Calculator. The operators will not be
recognized if they are not typed correctly. Open Raster Calculator. When the Raster Calculator
opens, enter the following expression: Int("rastercalc")
Click OK. A new layer named rastercalc1 is created in which cell values are truncated (not
rounded) at the decimal place.

Step 4: Create a permanent grid


By default, your output raster when using Raster Calculator is stored to your Scratch Workspace.
The default scratch workspace is a geodatabase created under your user documents. The output
can be saved to any location during any operation as long as the file path is changed. To store

1
Raster Calculator outputs permanently in your Scratch Workspace, click on the Geoprocessing
menu and select Geoprocessing Options. At the bottom, uncheck the box next to “Results are
temporary by default.” Your outputs will now be permanent by default. Open the Raster
Calculator and enter the following expression: Int("elevation" *0.3048)

For the Output Raster change the name to NewElev. Click OK. A new permanent layer Named
NewElev appears in your working directory. You can keep this map open for the next exercise.

Key points
• You can build expressions in the Raster Calculator by typing directly into the expression
box, selecting layers in the Layers list, and selecting buttons on the keypad. When you
select an element it is added to the expression in the expression box.
• Map Algebra operators are case sensitive. Be sure to type them correctly or select them
from the menu to the right in Raster Calculator to prevent errors.
• Output rasters are either permanent or temporary by default and will be stored in your
scratch workspace unless another location is specified in Raster Calculator. To select
whether rasters are temporary or permanent, open the Geoprocessing options and check
or uncheck the box next to “Results are temporary by default.”
• Output grids are either integer or floating point, depending on the expression.

Exercise 2: Use relational, Boolean, combinatorial, and logical operators


In this exercise, you will write a simple model to find suitable sites for a tree farm. You have an
agreement with the United States Forest Service that will allow you to develop the tree farm on
their lands. You intend to raise pine and fir trees for decorative purposes. You know that these
types of trees grow best above 2,400 meters elevation.

Step 1: Use relational operators


Load the ownership raster to your map. Find land that is suitable for your tree farm (i.e., land that
is owned by the USFS and is located at an elevation above 2400 meters). You will start the
model using the relational equality operator (==) to test the ownership layer for values that equal
200 (USFS lands – look in the attributes table). The output grid will contain only values of 1 and
0 (true and false). Open the Raster Calculator and enter the following Map Algebra expression:
"ownership" == 200

For the Output Raster change the name to GoodOwn. Click OK. The Equal To operator has
returned values of 1 for Forest Service lands and values of 0 for all other ownerships. Turn off
the Ownership and GoodOwn layers. Next you will make a layer for suitable elevations. You'll
use the relational greater-than operator (>) to test the Elevation layer for values that are greater
than 2,400 meters above sea level. Open the Raster Calculator and enter the following Map
Algebra expression: "NewElev" > 2400

For the Output Raster change the name to GoodElev. Click OK. The Greater Than operator
returns values of 1 for all cells whose elevation is greater than 2,400 meters, and 0 for all other
elevations.

2
Step 2: Use Boolean operators
While your tree farm model has identified areas of proper land ownership and areas of adequate
elevation, the results remain in separate layers. You need to put them together to find only those
areas that are both the right ownership and elevation. Open the Raster Calculator and enter the
following Map Algebra expression: "GoodOwn" & "GoodElev"
For the Output Raster change the name to GoodFarm. Click OK. The new GoodFarm layer has
values of 1 (true) for cells that have both good ownership and elevations. Note: The whole model
could have been done with this one Map Algebra expression: ("ownership" == 200) &
("NewElev" > 2400)
Models of this type could consider dozens of variables (raster layers).

Step 3: Use combinatorial operators


Your tree farm model has identified the areas of land that have the correct ownership and
elevation. It also needs to consider soils because the trees grow better in some soils than others.
In this step, you will combine the candidate farm sites with soils. The combinatorial operators
(CombinatorialAnd, CombinatorialOr and CombinatorialXOr) are the equivalent of a vector
overlay because they combine the attributes of both inputs and write them as fields to the output
grid (a unique ID is generated for each combination, which becomes the output cell value). Also,
they follow the same rules as the Boolean operators: CombinatorialAnd only outputs combined
attributes for those cells where both inputs are true. The Combine function has a similar result,
but combines many inputs at once. Now you will use the CombinatorialAnd operator to find all
the different types of soils in the potential tree farm sites you have identified. Remember that the
operators are case sensitive. Load the soil data. Open the Raster Calculator and enter the
following Map Algebra expression: CombinatorialAnd("GoodFarm", "soil")

For the Output Raster change the name to FarmSoil. Click OK. The effect of the
CombinatorialAnd operator is not immediately obvious; you must examine the attribute table of
the FarmSoil layer to understand the result. Right-click FarmSoil and click Open Attribute Table.
These are the different soils that are found in the GoodFarm sites.

Step 4: Use logical operators


The Over operator is useful for updating one raster with another. All non-zero values in the first
input are "pasted "over the corresponding cells in the second input. You will now use it to update
the landcover layer with your tree farm sites. Note that the symbology of your output layer will
not match that of the input landcover. Load landcover data. Open the Raster Calculator and enter
the following Map Algebra expression: Over("GoodFarm", "landcover")

For the Output Raster change the name to NewLand. Click OK. The Over operator has replaced
the landcover cells with the non-zero cells from GoodFarm. In reality, you would want to
reclassify the GoodFarm layer before doing the update, replacing the cell values of "1" with an
actual land cover code.

The Diff operator finds the differences between two rasters. For cells where both inputs are
different, it returns the value from the first input. Where they are the same, it returns zero. Diff is
especially useful for performing time-series studies, like finding those places where land use has
changed between 1980 and 1990. You will now use it to find where your NewLand and

3
landcover layers are different. Open the Raster Calculator and enter the following Map Algebra
expression: Diff("landcover", "NewLand")

For the Output Raster change the name to LandDiff. Click OK. The Diff operator has returned
the landcover values where they differ from the NewLand values. All other cells are set to zero.
Not only can you see where the layers are different, you see how they are different.

The InList operator is useful for "selecting" cells based on their values and writing them to a new
raster. This operator specifies to compare the input values to those in the provided list and, if
there is a match, return the value to the output cell, or otherwise return NoData. For the purposes
of this step, assume that soil codes of 201 ("Loam, Cobbly") and 204 ("Loamy Sand, Coarse And
Stony") are best for growing fir and pine trees. You will now use the InList operator to create a
new raster layer for just those cells. Open the Raster Calculator and enter the following Map
Algebra expression: InList("soil",[201, 204])

For the Output Raster change the name to GoodSoil. Click OK. The InList operator has returned
the cells whose values were in the list (201 and 204). All other cells were set to NoData. The
InList operator provides a quick way to create a processing mask. You can also use the Con,
SetNull, and Pick functions.

Key points
• Relational operators compare two numbers and return a 1 if the comparison is true and 0
if it is false.
• Boolean operators take logical (true or false) inputs and create a logical output of 1 for
true or 0 for false.
• Combinatorial operators assign new output values corresponding to various combinations
of input values.
• Logical operators take two inputs and assign values based on a logical comparison of the
two.

Exercise 3: Cross-tabulation Statistics


Tabulate area (Zonal – Spatial Analyst Tool) calculates cross-tabulated areas between two
datasets and outputs a table. You can use these tabulations to calculate a Kappa statistic that will
tell you how different your areas are (-1 completely different, 0 no significant difference, +1
completely the same).

Step 1: Tabulate Area


Select the tabulate area tool. The first raster you read in is the input or zone raster. Here select
landcover for the input and value for the zone field. The second raster you read in is the class
raster. Here select NewLand for the raster and value for the class field. Save the output table as
crosstab and note the default cell size.

Step 2: Inspect the table


Open the table crosstab. The values are areas in meters of overlap between the land cover value
indicated in the row and the value indicated in the column. Notice most of the overlapping areas
are on the diagonal, which means that most of the pixel values did not change between the two

4
input rasters. All of the pixels that did change, converted to a land use value of 1. We can
consider this the tree farm area. You can easily derive the number of pixels from the area by
dividing the raster resolution (default cell size) by the tabulated area.

Step 3: Export data and calculate Kappa


Right click on the crosstab table and export data (probably you will want to do this as a text file).
Read into Word or Excel and make a nice table to calculate Kappa. Rename the rows and
columns to represent the land cover (you can look up the names in the attributes table of
landcover), sum all of the rows and columns, calculate the total area, then calculate Kappa.

K = (Po – Pe) / (1 - Pe)

Po is the proportion of cells (area) not changed (sum all of the diagonal values divided by the
total number of cells). Pe is the expected change due to chance. For each land cover category
multiple the total row by the total column and divide by the square of the overall total. Sum these
for each category and you get Pe.

Key points
• Spatial analyst has a tool cross-tabulate between two rasters.
• You can pull the table out of ArcMap to make further calculations on the tabulated data.
• Kappa is a statistic that tells you how different two rasters are.

Exercise 4: Work with functions


Functions provide most of the raster processing capabilities for Map Algebra. There are 168 of
them, as opposed to the 29 operators. In this exercise, you'll work with some of the surface
analysis functions. You can also derive these using the Surface Analysis menu. Here you'll
perform these tasks using the Raster Calculator.

Step 1: Use the raster calculator to derive aspect, slope, hillshade


In this step, you'll use a couple of functions that may already seem familiar to you. In order to
use a function, you simply need to refer to its syntax. For example, the syntax for the Aspect
function is: Aspect (<grid>) Open the Raster Calculator and build the following expression:
Aspect("NewElev")

For the Output Raster change the name to Aspect. Click OK. You created an aspect grid, just as
if you had chosen Aspect from the Surface Analysis menu. The only difference is that the menu
choice gives you a predefined legend.
Now you'll try the Slope function, which has a couple more arguments. The Syntax for the
SLOPE function is: Slope(<grid>, {DEGREE | PERCENTRISE}, {z_factor}) Open the Raster
Calculator and build the following expression:
Slope("NewElev", "PERCENT_RISE", 1)

For the Output Raster change the name to Slope. Click OK.

Now you'll try the Hillshade function. The Syntax for the HILLSHADE function is:
HILLSHADE(<grid>, {azimuth}, {altitude}, {NO_SHADOWS | SHADOWS}, {z_factor})

5
Open the Raster Calculator and enter the following expression: Hillshade("NewElev")

For the Output Raster change the name to Hillshade. Click OK. Notice the symbology may not
be appropriate for a hillshade. Double-click Hillshade to open the Layer Properties dialog. Click
the Symbology tab, and from the Show list choose Stretched. The color ramp should default to
Black to White. Click OK.

Step 2: Create an analytic hillshade


Hillshades also have analytic uses. The grayscale values that a hillshade returns (0 to 255) may
also be interpreted as an index of sun exposure, where cells that have little sun exposure have
low values (0) and those that are fully illuminated have high values (255). Using hillshades
analytically requires that you place the "sun" in its true position for a day and time of year. This
varies according to geographic location; that is, at 12:00 noon on any given day of the year, the
sun has a different azimuth and altitude in Seattle, Washington than it does in Dallas, Texas.
Suppose you are trying to find the best places for a ski resort in the Lake Tahoe area. As part of a
larger model, you want to identify slopes that are shaded for most of the snow months—
November through April. Your approach is to compute a hillshade for the middle of each month,
placing the sun in its correct location, and deriving the average sun exposure for the six months.
You'll use the following azimuth and altitude settings for the given months:

Month Azimuth Altitude


November 186.6 37.2
December 183.1 32.8
January 179.3 35.2
February 177.6 43.7
March 179.2 54.3
April 184.3 66.1

Now you're ready to calculate the hillshade for these six months, starting with November. Open
the Raster Calculator and enter the following Map Algebra expression:
Hillshade("NewElev",186.6,37.2)

For the Output Raster change the name to November. Click OK. The November hillshade looks
inverted because the sun was positioned in the south, casting shadows at the top of the
mountains.

Step 3: Create hillshades for December through April


On your own, use the information above to create hillshades for the other five months. Name
each hillshade the same as the month. TIP: You can use batch processing by right clicking on
raster calculator and selecting batch. Right click on the output raster field to browse to the output
folder and rename. If you want to see the illumination change over time, organize the new layers
by date - November at the bottom of the list of months in the Table of Contents and April at the
top. Turn them on one-by-one in order from the bottom to see the changes.

Step 4: Compute mean illumination


Now you will use the CellStatistics function to compute the mean illumination for each cell

6
based on the six input months. Turn off all layers except Elevation and close their legends.
Open the Raster Calculator and enter the following Map Algebra expression:
CellStatistics(["November", "December", "January", "February", "March", "April"],
"MEAN")

For the Output Raster change the name to SunExposure. Click OK. The new SunExposure layer
now shows the average sun exposure over a six-month period. In your ski resort model, you
would give more weight to slopes with lower sun exposure than those with high sun exposure.

Step 5: Find area with minimal sun exposure


Now you'll find those areas with average exposure values less than 100. Open the Raster
Calculator and enter the following Map Algebra expression: "SunExposure" <= 100
For the Output Raster change the name to LowSun. Click OK. Right-click the LowSun symbol
for code 1 and choose a purple color. Right-click the LowSun symbol for code 0 and choose No
Color. Turn off SunExposure. Turn on Hillshade and move it below Elevation. The purple areas
on the map are the best for ski runs, based only on sun exposure.

Key points
• Most of the functions available from ArcToolbox are also available as Map Algebra
functions.

Exercise 5: Use conditional processing


Conditional processing can be performed in ArcGIS Spatial Analyst using the CON (conditional)
function, which implements a traditional IF-ELSE construct in the form of a Map Algebra
function. With CON, you may implement simple or complex conditional expressions. In this
exercise, you will use CON to find the potential reservoir created by a proposed dam within a
basin. Once you have found the reservoir, you’ll use the CON function with the ISNULL
function to update an elevation raster with the new water surface.

Step 1: Create a hillshade


Open a new ArcMap session. Load in damelev and dambasin data. To help you visualize the area
upstream of the proposed dam, create a hillshade. Move the new Hillshade of damelev layer
below dambasin in the Table of Contents.

Step 2: Define the potential reservoir


The reservoir will be a subset of cells within the dam’s basin because cells not in the basin flow
away from the dam. To define the reservoir, you’ll write a Map Algebra expression that selects
cells inside the basin whose elevation is less than the proposed height of the dam, 790 meters.
Here’s where Con will come in handy. Its syntax is: Con(<condition>, <true_expression>,
{false_expression}) Any expression that evaluates to true or false (or non-zero and zero) may be
supplied as the condition argument. If the condition evaluates to true, then the true expression is
evaluated. If the condition is false, then the false expression evaluates.

These expressions may be simple, like a single value or raster, or complex expressions made up
of multiple nested functions—including other Con functions. If the optional false expression is
left blank and the condition evaluates to false, then Con returns NoData. Open the Raster

7
Calculator and build the following Map Algebra expression: Con("dambasin" & ("damelev"
<= 790), 790)

For the Output Raster change the name to Reservoir. Click OK. This Con statement translates as
"IF the cell is inside the basin AND its elevation is less than or equal to 790 meters, THEN
return a value of 790; ELSE return NoData". For the part about "inside the basin", recall that
Map Algebra considers any non-zero, non-NoData value to be a logical true. By omitting the last
Con argument (the False case), you are setting cells that don’t pass the test to NoData. Change
the color of the Reservoir symbol to a shade of blue. Turn off the dambasin layer. Examine the
Reservoir layer and note the extent of the reservoir.

Click the Identify tool and click within the map. Move the Identify Results dialog so you can see
the map. In the Identify Results dialog, click the Layers dropdown arrow and choose damelev.
Now click several times within the Reservoir, examining the returned values. The values should
all be less than 790 meters.

Step 3: Update the elevation layer with the new reservoir


Once the dam is built and the reservoir is full, you could update the elevation layer with the new
reservoir. You'll use the IsNull function together with Con, which are often used together to
replace NoData values with something else. The syntax for IsNull is: IsNull(<raster>) The IsNull
function tests the current cell to see if it contains NoData and returns either 1 or 0 (true or false).
Open the Raster Calculator and build the following Map Algebra expression:
Con(IsNull("Reservoir"),"damelev",790)

For the Output Raster change the name to NewDamElev. Click OK. This Con statement
translates as "If a cell within Reservoir contains NoData, return the original elevation layer, or
else return the value 790." If you want to see the new lake better, create a hillshade of the
NewDamElev layer.

Step 4: Descriptive statistics


Use another Int and Con statement to create a raster with the elevations from the damelev raster
only within the Reservoir: Int(Con("Reservoir","damelev"))
For the Output Raster change the name to OldElev. Click OK. Now open the attribute table and
right click on the values field. Select Statistics…. You will see a graph of the frequency
distribution of the data, as well as a list of standard descriptive statistics.

Key points
• You can use the Con function to control the flow of operations based on the evaluation of
one or more conditions.
• You can use the IsNull function to test for the presence of NoData. Con and IsNull are
often used together to replace NoData values with another value.
• You can calculate descriptive statistics within the attributes table.

Exercise 6: Create a mask to clip a raster


Turning cells into NoData and testing for the presence of NoData are two of the more important
tasks in Map Algebra. You have just seen one technique for setting cells to NoData—omitting

8
the {false_expression} argument in the Con function. There are many others, like the SetNull
function. In this exercise, you'll use SetNull to create a mask where non-Forest Service land and
water bodies are set to NoData, and then use the mask to clip the soil layer.

Step 1: Create a mask


Open a new ArcMap session. Load in the ownership and soil data. In this step, you will create a
mask that can be used to exclude non-forest service land and water. Open the attributes table for
the soil and notice that Water has a value of 901. Open the ownership attributes table and notice
U.S. Forest Service land is coded with the value 200. Now you will create the mask using the
SetNull function. The SetNull function's syntax is: SetNull (<condition>, {expression})
The SetNull function applies a test against the current cell and if the test is true replaces its value
with NoData. If the test is false, it writes the results of the expression to the cell. If you allow the
optional {expression} argument to default, SetNull will return NoData for every cell. Open the
Raster Calculator and enter the following Map Algebra expression: SetNull("ownership" !=
200, 1) | SetNull("soil" == 901, 1)

For the Output Raster change the name to Mask. Click OK. The expression set non-forest service
land and water to NoData.

Step 2: Clip the soil layer using the mask


Change your analysis extent settings. From the Geoprocessing menu, choose Environments…,
Raster Analysis and for mask choose Mask. Leave all other settings the same. Click OK. Open
the Raster Calculator and enter the following Map Algebra expression: "soil"
For the Output Raster change the name to ClipSoil. Click OK. The ClipSoil layer only has soil
data for Forest Service lands that are not water. This technique is useful for clipping rasters to an
irregular outline or when extracting data for a specific city from a countywide database.

Key points
• The SetNull function assigns the value NoData to cells that meet a certain condition,
otherwise it returns a user specified value.
• The SetNull functions can be used to create a mask.

Assignment Questions
1. Show the cross tabulation table from Exercise 3. Please label rows and columns with land
cover categories.
2. What is the value of Kappa you calculated from Exercise 3? Does Kappa change if you
use number of pixels instead of area?
3. Using data from Exercise 4, how many pixels in the study area are at elevations higher
than 1500 meters and less than an average sun exposure of 135 between the months of
November and April?
4. What is the mean and standard deviation in meters of the elevation within the reservoir in
Exercise 5? How many cubic meters of water will the reservoir hold (this question is
designed for you to figure out without step by step instructions)?
5. What is the area of rock outcrop in square meters within the Forest Service lands in
Exercise 6?

You might also like