You are on page 1of 34
Working with Map Algebra Previous So far in this course, you've seen how ArcGIS® Spatial Analyst functionality is fully integrated with the geoprocessing framework. Much more functionality is available through Map Algebra, the analysis language of Spatial Analyst. Map Algebra is based loosely on the Map Algebra concepts presented by Dr. Dana Tomlin in his book entitled Geographic Information Systems and Cartographic Modeling (Tomlin, 1990). Map Algebra is a high-level computational language used for performing cartographic spatial analysis using raster data. Simply put, Map Algebra is math applied to rasters, a practice that's possible because rasters are geographically referenced arrays of numbers. If you stack rasters on top of each other as though you were creating a mathematical sandwich, you can perform simple arithmetic to the most sophisticated algorithms with them. In this module, you will learn how to use Map Algebra operators and functions to build your own expressions. You will also learn how to perform some of the most useful tasks in Map Algebra, such as conditional processing, testing for NoData, and setting cells to NoData « Learning objectives A student who completes this module will be able to: Build Map Algebra expressions. Use Map Algebra operators. Use Map Algebra functions. Perform conditional processing. Work with NoData. Previous | Next” Learning ArcGIS Spatial Analyst Working with Map Alcbra cipri SRL A ads ened Working with operators and “Previous |Next functions Map Algebra uses math-like expressions containing operators and functions. Map Algebra operators work with one or more inputs to develop new values. Functions perform specialized tasks, such as computing slope from elevation, and they usually return numeric values. Vegetation + Prey habitat Yap Abra expression [Vegetation] + [Prey habitat] + +{Landform} Landform Outpt raster ) ‘tat Canada Lynx habitat You don't have to be a programmer to know how to use operators and functions effectively; you just have to be taught how to use them. Operators and functions. are accessible through the geoprocessing framework, which provides access to tools in dialog boxes, command line, ModelBuilder™, and scripting. «Previous | Next” Learning Ae pata Anas | Working with Map Alga Capri 0200-200 ESR. Atak ened Map Algebra operators “Previous |Next You probably know more about Map Algebra operators than you think. Map Algebra operators are generally the same operators found on scientific calculators. The operators used most often (arithmetic, relational, Boolean, and logical) are also the simplest. Two less commonly used operators are combinatorial and bitwise. These operators are described as follows: Arithmetic operators—allow addition, subtraction, multiplication, and division. For ‘example, three rasters measuring three different types of fire risk could be added to create an overall risk analysis raster. Arithmetic operators can also be used to convert values from one measurement to another (e.g., feet x 0.3048 = meters). “€ ee Arithmetic Operators = + Addition = Subtraction * Multiplication 7, DIV Division MOD — Modulus = Unary minus A Arithmetic operators. Relational operators—allow you to build logical tests, returning values of true (1) and false (0). For example, this type of operator can be used to find vegetation “equal to" Sierra-type mixed coniferous forest, Relational Operators ==, EQ Equal Not equal Less thon Less then or equal Greater than Greater than or equal 1 — Relational operators. Boolean operators—such as “and,” "or," and “not” allow you to chain logical tests. Like relational operators, Boolean operators return values of true and false. For example, you could find all slopes that are "greater than" 45 degrees "and" that have an elevation that is "greater than" 5000 meters. | Boolean Operators *, NOT Logical complement & AND Logical A 1, OR Logical Or 1, KOR Logical Xor SE ———— Boolean operators. Logical operators—DIFF, IN, and OVER, also allow you to build logical tests on a cell-by-cell basis, but are implemented with specific rules. * ADIFF B: Ifa cell value in raster A and raster B are different, the cell value in raster A is returned. If the cell values are the same, the value zero is returned. « AJIN {value list): If a cell value in raster A is in the value list, the cell value in raster A is returned. Otherwise, NoData is returned. + A OVER B: Ifa cell value in raster A is not equal to zero, the cell value is raster A is returned. Otherwise, the cell value in raster 6 is returned. Logical Operators DIFF Logical difference IN {list} Contained in list Replace ud Logical operators. Combinatorial operators—combine the attributes of multiple input rasters, These operators find all unique combinations of values and assign a unique ID to each, which is then retui red to the output raster. The output VAT will have the Value fields from all the input rasters. ee _______=y Combinatorial Operators CAND — Combinatorial And COR — Combinatorial Or CXOR = Combinatorial Xor Tt Combinatorial operators. Bitwise operators are not used in this course, so they are not presented here. See the ArcGIS Desktop Help for details regarding the use of bitwise operators. «Previous | Next” [Learning AreGIS Spatial Analst| Working with Map Algebra CCopsigh ©2008-2008 ESRI. All nights reserved Map Algebra func ns The term "functions" might sound like programmers’ speak, but whether you realize it or not, you've probably already used them. In the previous module, you derived hillshade, slope, and aspect rasters using the ArcGIS Spatial Analyst geoprocessing tools. The tool dialog boxes simply implement Map Algebra functions—programs that perform specific tasks, such as calculating slope. Functions are the major element of the Map Algebra language, and there are over a hundred of them. “Previous | Next» ‘earning AreGIS Spatial Analyst | Working with Map Alzehra ‘Copyright ©2004-2008 ESRI. Allrighs reserved Understanding logical values «Previous| Next Logical values simply keep track of the values true and false. In Map Algebra, any non-zero input value is considered to be a logical true, and zero Is considered a logical false. Some Map Algebra operators and functions evaluate input cell values and return logical 1 values (true) and logical 0 values (false). The relational and Boolean operators all return logical values. Slope > 15 Steep slopes In this example, cells are evaluated as to whether their value is, greater than 15. The value 1, or logical true, is assigned to those cells that are greater than 15. The value 0, or logical false, is assigned to all other cells. «Previous | Next? Learning ArcGIS Spatial Analyt | Working with Map Algeben (Copyigh © 2008-2008 ESRI, Allrighis esered @ Print & Previous | Next” Work ith functions Functions provide the core of the raster processing capabilities in ArcGIS Spatial Analyst, In addition to accessing these functions using traditional Map Algebra expressions, most of these functions are now accessible through the geoprocessing framework. In this exercise, you'll work with functions at the command line and by using a Map Algebra expression. For this exercise, suppose that you want to find the best places fora 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. Estimated time to complete: 30 minutes Before you begin The data for exercise is contained in the following files: + LearnSA.exe (Course data file) ‘+ MapAlgebra.exe (Module data file) If you have not downloaded one of these files, you should download the data now. Need help? Course data instructions Step Open the map document If necessary, start AreMap™, Open the Functions.mxd map document from your VirtualCampus\LearnSA9\MapAlgebra folder. VIEW RESULT © Can't find your data? You see an elevation raster of an area near Lake Tahoe in the Sierra Nevada mountains. If necessary, load the AreGIS Spatial Analyst extension and make the AreToolbox™ window visible. The environment settings for this exercise have been set as follows: General Settings + Current Workspace: ...\LeanSA9\MapA lgebra\SierraNevada.edb + Scratch Workspace: ...\LearnSA9\MapAlgebra\SierraNevadaSeratch.gdb + Output Coordinate System: Same as Layer "Elevation" + Extent: Same as layer Elevation Raster Analysis Settings © Cell Size: Same as layer Elevation Mask: Step Create a hillshade 2 In this step, you'll use a function that should be very familiar to you, You'll use the Hillshade function to visualize the topography of the Lake Tahoe area. You'll run the function as a tool. If necessary, expand the Spatial Analyst Tools toolbox. Expand the Surface toolset, double-click the Hillshade tool, and fill out its parameters as follows: 6 Input raster: Elevation Output raster: ..\SierraNevadaScratch.gdb\Hillshade VIEW RESULT Click OK to run the tool. When the tool finishes, move Hillshade to the bottom of the table of contents, and change the transparency of the Elevation layer 050%. VIEW RESULT You can see that there are plenty of north facing stopes. Next, you'll perform a detailed analysis to find the amount of sun exposure these slopes get throughout the snow season, Step Create a command line variable 3 Next, you'll measure sun exposure for each of the snow months. While you could use the Hillshade tool to carry out your calculations, this time you'll use command line. Earlier, you learned that using the command line is one of the methods to run a geoprocessing tool. One of the advantages of running a geoprocessing tool from the command line is that you can quickly recall the command, modify it, and run it again. This will prove quite beneficial as you have six hillshades to create. Tools run in command line write their output to your current workspace. Since you want all of your output to be written to your scratch workspace, you'll create a command line variable to help direct the output to the right place. Click the Show/Hide Command Line Window button © to display the Command Line window Right-click in the command line and choose Variables, In the Variable Manager dialog box, click Add. In the first cell under Name, replace Variable0 with Serateh, Click the cell under Data Type, scroll down the list, and choose Workspace. Click the cell under Value, then click the ellipsis button «... In the Scratch dialog box, click the Browse button and navigate to your LearnSA9\MapAlgebra folder. Click SierraNevadaScrateh.gdb, then click Add. Click OK. VIEW RESULT The value for your variable is now defined. While you're in the Variable Manager, add another variable for the current ace with the following properties: Name: Current Data Type: Workspace Value: ...\LearnSA9\MapAlgebra\SierraNevada.gdb VIEW RESULT When you're finished, click OK to close the Variable Man: Step Change workspaces 4 In the command spacebar, ine window, type the command workspace and then press the The two variables, Current and Serateh, appear in a drop-down list. Scratch to add it to the command. VIEW RESULT Press the Enter key to run the tool, You won't see anything happen now, but the workspace has now been changed to point to SierraNevadaScratch.gdb based on the variable you set in the previous step. Step Create an analytic hillshade 5 Now you're ready to calculate sun exposure for these six months, starting with November. The Naval Observatory Web site has given you 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 In the command line, build the following command usi feature: HillShade_sa Elevation November 186.6 37.2 Note: If you don't see the HillShade_sa command, use the Hillshade command instead. ‘VIEW RESULT With your cursor still in the command line, press Enter to run the tool. g the code completion VIEW RESULT ‘The November hillshade looks inverted because the sun was positioned in the south, casting shadows at the top of the mountains. On your own, use the information above to create hillshades for the other five months. Name each hillshade the same as the month. Tip: Once you've run a tool in the command line, you can quickly run that tool again, modifying any parameter values as necessary. Scroll through the message area of the Command Line window until you find the tool you just ran and its parameters, which are displayed in blue text. Right-click anywhere in the blue text and choose Recall. The tool and its parameters are added to the command line, ready for you to modify. 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, April at the top) and turn them off Now tum them on one by one in order from the bottom to see the changes. The View Result link for this step contai through each month, VIEW RESULT Step Change workspaces Before moving on, you'll need to change the current workspace back to your SierraNevada.gdb geodatabase. In the command line window, type the command workspace and then press the spacebar, Double-click the Current variable to add it to the command. VIEW RESULT Press the Enter key to run the tool. ‘The current workspace has now been changed to point to SierraNevada.gdb, Step Compute mean illumination 1 In this step, you'll use the MEAN funetion to compute mean illumination for each cell based on the six input months. You'll access this function using the Cell Statistics tool. Expand the Local toolset and double-click the Cell Statistics tool. For Input rasters or constant values, select all of the month layers in the AreMap table of contents then drag them into this field. For Output raster, maintain the default geodatabase (SierraNevadaScratch), but change the raster name to SunExposure. For Overlay statistic, verify that MEAN is selected. VIEW RESULT This equates to the following Map Algebra statement: MEAN (Novenber, December, January, February, March, April) Click OK to run the Cell Statistics tool. VIEW RESULT 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 Find areas with minimal sun exposure 8 ‘Now you'll find those areas with average sun exposure values less than 100. From within the Math toolset, expand the Logical toolset. Double-click the Less Than Equal tool and fill out its parameters as follows: Input raster or constant value 1: SunExposure Input raster or constant value 2: 100 Output raster: ..\SierraNevada.gdb\GoodShade VIEW RESULT This equates to the following Map Algebra statement: SunExposure LE 100 Click OK to run the Less Than Equal tool. Symbolize the GoodShade layer using a purple color for value 1 and No Color for value 0. Turn off all layers except for GoodShade, Elevation, and HillShade. ‘The purple areas on the map are the best for ski runs, based only on sun exposure. Step Save the map document 9 If you want, save the map document as Funetions2.mxd in your LearnSA9\MapAlgebra folder. Map Algebra functions may be accessed through the multiple ways provided via the geoprocessing framework. In this exercise, you ran several functions from the command line as well as through tool dialog boxes. You also created Map Algebra expressions using the Single Output Map Algebra tool. Choosing to run a tool using its dialog box. using the command line, or by typing Map Algebra expressions is largely a matter of preference, although there are some differences between the methods. One difference is that in the command line you can create variables for parameter values that you can save and reuse. «Previous | Next” {earning ArcGIS Spatial Analyst | Working with Map Algebra = ata pina web noes spoil ‘eps! ooege chrome eusd nat eonnetiotarng ecm Teywoningtaraeaccon & Print « provi ws | Next Work with operators Map Algebra allows for complex analysis tasks to be simplified through the use of simple algebra-like expressions. In this exercise, you will combine Map Algebra operators and functions to model the best location to raise pine and fir trees to be used for reforestation. You know that these types of trees grow best above 2,400 meters elevation. Also, you have an agreement with the United States Forest Service that will allow you to develop the farm on their lands. Estimated time to complete: 30 minutes Before you begin ‘The data for this exercise is contained in the following files: + LearnSA.exe (Course data file) + MapAlgebra.exe (Module data file) If you have not downloaded one of these files, you should download the data now. Need help? Course data instructions Step Open a map document 1 If necessary, start ArcMap. Open the Calculations.mxd map document from your VirtualCampus\LearnSA9\MapAlgebra folder. You see an elevation raster of an area near Lake Tahoe in the central Nevada mountains. Ifnecessary, load the ArcGIS Spatial Analyst extension and make the ArcToolbox window visible. The environment settings for this exercise have been set as follow: General Settings: ierra + Current Workspace: ...\LeamSA9\MapAlgebra\SierraNevada.gdb * Scratch Workspace: ...\Lear$A9\MapAlgebra\SierraNevadaScratch.gdb + Output Coordinate System: Same as Layer "Elevati + Extent: Same as Layer Elevation Raster Analysis Settings: + Cell Size: Same as Layer Elevation * Mask: ‘Step Convert elevation in feet to meters 2 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, 80 to ensure accurate volume measurements, you need to convert the elevation values from feet to meters. Since one foot equals 0.3048 meters, you will multiply Elevation by 0.3048 using the Times operator. If necessary, expand the Spatial Analyst Tools toolbox. Expand the Math toolset, double-click the Times tool, then fill out the parameters as follows: Input raster or Constant Value 1: Elevation Input raster or Constant Value 2: 0.3048 Output raster: ..\SierraNevadaScratch. gdb\Times_clevat VIEW RESULT Click OK. Each cell value in the Times_elevatl layer contains the value of the corresponding cell in the Elevation raster, multiplied by 0.3048, The cell values of Times_clevat] now range from 1834.9 to 2692.91 meters. Because the multiplier contained decimal points, the new raster is a floating point raster. Next, you will convert the floating point raster back to an integer grid using the INT function. Step Convert floating point elevation values to integer 3 While this is an exercise about using Map Algebra operators, in this step, you need to use a Map Algebra function, The INT Map Algebra function allows you to convert floating-point data to integer data. REVIEW CONCEPT From the Math tooiset, open the Int tool and fill out the parameters as follows: Input raster: Times_clevatl Output raster; ..\SieraNevadaScratch.edb\Elevation_meters Click OK. The cell values in the Elevation_meters layer are truncated (not rounded) at the decimal place. They now range from 1834 to 2692 meters. Turn off the Times elevatl and the Elevation layers and collapse their legends, Step Find elevations above 2,400 meters using the Greater Than tool 4 Remember, your trees grow best above 2,400 meters. Therefore, you'll use the Greater Than operator to test the Elevation layer for values that are greater than 2,400 meters above sea level. the Math toolset, expand the Logical toolset and open the Greater Than tool. out the parameters as follows: Input raster or constant value 1; Elevation_meters Input raster or constant value 2: 2400 Output raster: ..\SierraNevadaScratch.edb\GoodElev Click OK. VIEW RESULT 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. ‘Tum off GoodElev. Elevation greater than 2,400 meters above sea level is one criterion of the land suitable for siting your tree farm. Furthermore, the land should be owned by the United States Forest Service. Step Identify United States Forest Service land 5 To find land that is owned by the United States Forest Service, you will use the Equal To operator to test the Ownership layer for values that encode United States Forest Service ownership. Turn off the Elevation_meters layer and collapse its legend. Turn on the Ownership layer and expand its legend. Note that a cell value of 200 encodes United States Forest Service ownership. From the Logical toolset, open the Equal To tool and fill out its parameters as follows: Input raster or constant value 1: Ownership Input raster or constant value 2: 200 Output raster; ...\SierraNevadaScratch.gdb\GoodOwn Click OK. VIEW RESULT ‘The Equal To operator has returned values of | for Forest Service lands and values of 0 for all other ownerships. Turn off the GoodOwn and Ownership layers and collapse their legends. So far, you have identified areas of proper land ownership and areas of adequate elevation, To find a suitable site for the tree farm, you need to put them together to find only those areas that are both the right ownership and elevation, ‘Step Combine the GoodElev and the GoodOwn layers 6 Step Combine good farm a To combine the GoodElev and the GoodOwn layers into one, you will use the Boolean And operator. From the Logical toolset, open the Boolean And tool then fill out the parameters as follows: Input raster or constant value 1: GoodOwn Input raster or constant value 2: GoodElev Output raster: ..\SierraNevadaScratch.edb\GoodFarm Click OK. ‘The new GoodFarm layer has values of | (true) for cells that have both appropriate ownership and elevation. ‘Tum off the GoodFarm layer and collapse its legend, ‘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. tes with soils In this step, you will combine the candidate farm sites with the corresponding values in the Soils layer using the combinatorial And operator. ‘The combinatorial operators (CAND, COR and CXOR) are the equivalent of a vector overlay because they combine the attributes of both inputs and write them as fields to the output raster (a unique ID is generated for each combination, which becomes the output cell value). Also, they follow the same rules as the Boolean operators: CAND only outputs combined attributes for those cells where both inputs are true. Turn on the Soils layer and expand its legend. Briefly review the code descriptions. From the Logical toolset, open the Combinatorial And tool then fill out its parameters as follows: Input raster or constant value 1: GoodFarm Input raster or constant value 2: Soils, Output raster: ..\SierraNevadaSeratch.gdb\FarmSoils Click OK. ‘Tum off the Soils layer and clos. legend. The effect of the CAND operator is not immediately obvious; you must examine the attribute table of the FarmSoils layer to see what it has done. Right-click FarmSoils and click Open Attribute Table. VIEW RESULT Notice the soil code values in the far right column of the attribute table. These represent the different soils that are found in the GoodFarm sites. Step Step Close the Attributes of FarmSoils table. Tum off the FarmSoils layer and collapse its legend. Update the Landeover layer with tree farm sites In this step, you'll use the OVER operator within a Map Algebra expression to update the Landcover layer with your tree farm sites. 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, Turn on Landeover and expand its legend. ‘You access Map Algebra using the Single Output Map Algebra and Multi Output Map Algebra tools in AreToolbox. Expand the Map Algebra toolset and open the Single Output Map Algebra tool. Type (or copy and paste) the following Map Algebra expression into the dialog box: [GoodFarm] OVER [Landeover] Rename the output raster NewLand. Click OK. ‘VIEW RESULT Compare the symbology of your output layer with that of the input Landeover layer. The OVER operator has replaced the Landcover cells that coincide with non-zero cells of GoodFarm with a cell value of 1. Find differences between the NewLand and the Landcover layers Tur off the NewLand and the Landeover layers and close their legends. Next, you will use the DIFF operator to find where your NewLand and Landcover layers are different while 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. From the Map Algebra toolbox, open the Single Output Map Algebra tool. Enter the following Map Algebra expression: [Landcover] DIFF [NewLand] Rename the output raster Land Diff. VIEW RESULT ‘The DIFF operator has retumed the Landcover values where they differ from the NewLand values. All other cells are set to zero. ‘Turn off the LandDiff layer and collapse its legend. Find suitable soils ‘Tum on the Soils layer and expand its legend. ‘You will find cells in the Soils layer that contain soils that are well suitable for your iree farm. 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 IN operator to create a new raster layer for just those cells, The IN operator is useful for "selecting" cells based on their values and writi them to a new raster. This operator compares the input values to those in the provided list and, if there is a match, returns the value to the output cell, or otherwise returns NoData. From the Map Algebra toolbox, open the Single Output Map Algebra tool. Enter the following Map Algebra expression: [Soils] IN {201, 204} For Output raster. maintain the default geodatabase (S' but change the raster name to GoodSoils. Click OK. Tum off the Soils layer and collapse its legend to better see the result. ’NevadaScratch.gdb), VIEW RESULT ‘The IN operator has returned the cells whose values were in the list (201 and 204). All other cells were set to NoData. The IN operator provides a quick way to create a processing mask. You can also use the CON, SETNULL, and SELECT. functions. Turn off the GoodSoils layer and collapse it legend. ‘Step Save the map document 1 Save the map document as Caleulations2.mxd in your LearnSA9\MapAlgebra folder. In this exercise, you've worked with several types of Map Algebra operators and a function. Operators and functions are available as individual geoprocessing tools or they can be used within Map Algebra expressions written in the Single Output Map Algebra tool. “Previous | Next” Putting Map Algebra to work In the previous topic, you saw how easy it is create Map Algebra expressions using operators and functions. Now you're ready to put your new skills to work, This topic covers how to perform some of the most common Map Algebra tasks: working with NoData values, doing conditional processing, and merging multiple rasters together. “Previous | Next” Learning ArcGIS Spatial Analyt | Working with Map Algebra Copyright ©2004-2008 ESRI, Al ihis reserved «Previous | Next?” Conditional processing Conditional processing makes it possible for you to specify which action to take, depending on the conditions. You can specify the conditions that must be evaluated as true before an action should be taken, as well as specify appropriate actions to take when the conditions are evaluated as false. The traditional If-Then-Else statement is an example of a conditional statement. Slope < 15? Y True = 100 False = NoData SlopeMask In this example, each input cell is tested for the condition of having a slope less than 15. If the cell tests true, a value of 100 is assigned to the output cell. If the cell tests false, a value of NoData is assigned to the output cell. The result can be used as an analysis mask to exclude undesirable areas from an analysis. Conditional processing is especially useful for creating analysis masks. For example, in a wildfire prevention and suppression analysis, high-risk areas (true) can be assigned a value of 100, while lower-risk areas (false) can be assigned a value of NoData. «Previous | Next” Learning ArcGIS Spatial Analyt | Working with Map Algebra 2008 ESRI. Al rights reserved Copyright 2 1 Print «Previous 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 expression: In this exercise, you will use CON to find the potential reservoir created by a proposed 0 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. Estimated time to complete: 15 minutes Before you begin The data for this exercise is contained in the following files: + LearnSA.exe (Course data file) * MapAlgebra.exe (Module data file) If you have not downloaded one of these files, you should download the now. Need help? Course data instructions Step Open the map document 1 Ifnecessary, start AreMap. Open the Conditional.mxd map document from your Virtual Campus\LearnSA9\MapaAlgebra folder. VIEW RESULT © Can't find your da ‘The map contains the proposed dam, the drainage basin upstream from the dam, and an elevation raster. If necessary, load the Spatial Analyst extension and make the AreToolbox window visible ‘The environment settings for this exercise have been set as follows: General Settings: » Current Workspace: + Scratch Workspace: ...\LearnSA9\MapAlgebra\BigBearSeratch.edb ‘+ Output Coordinate System: Same as Layer "DamElev" + Extent: Same as Layer DamElev _\LeamSA9\MapAlgebra\BigBear.gdb Raster Analysis Settings: * Cell Size: Same as Layer DamElev * Mask: Step Create a hillshade 2 To help you visualize the area upstream of the proposed dam, you'll create a hillshade. From the Surface toolset, open the Hillshade tool and fill out its parameters as follows: Input Raster: DamElev Output Raster: ...\BigBearScratch.gdb\DamHillshade Click OK. Move the new DamHillshade layer below DamBasin in the table of contents. VIEW RESULT . Next, you will find the cells that will be covered by the potential reservoir. Step Define the potential reservoir 3 ‘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, which is 790 meters. Here's where CON will come in handy. Its syntax is: CON(, , {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. Note: In the Conditional toolset, there is a Con too! available that performs the CON operation. However, this tool allows only one input layer. Since you have two input layers, you will use the Single Output Map Algebra tool. From the Map Algebra toolbox, open the Single Output Map Algebra tool and enter the following Map Algebra expressior CON({DamBasin] AND ({DamElev] <= 790), 790) ‘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. REVIEW CONCEPT Keep the path to the default geodatabase (BigBearScratch.gdb), but change the output raster name to Reservoir. Click OK. VIEW RESULT Change the coior of the Reservoir symbol to a shade of blue. Turn off the DamBasin layer. ‘VIEW RESULT Examine the Reservoir layer and note the extent of the reservoir. Click the Identify too! © and click anywhere within the map to open the Identify dialog box. In the Identify dialog box, click the Identify from drop-down arrow and choose DamElev, then move the dialog box so you can see the map. Now click several times within the reservoir, examining the returned values. ‘The values should all be less than 790 meters, VIEW RESULT Close the Identify dialog box. Once the dam is built and the reservoir is full, the elevation of the reservoir surface will be 790 meters. Therefore you will update the elevation layer for the area of the reservoir. ‘Step Update the elevation layer with the new reservoir 4 ‘To update the elevation layer, you'll use the ISNULL function together with CON, which are often used together to replace NoData values with something else. The ISNULL function tests the current cell to see if it contains NoData and returns cither 1 or 0 (true or false). ‘The Map Algebra syntax for ISNULL is: ISNULL( Step Create a mask 2 In this step, you will create a mask that can be used to exclude non-Forest Service land and water. Click the plus sign next to the Soil layer to expand its legend. Notice that Water has a value of 901 ‘Turn off the Soil layer and collapse its legend. Tum on the Ownership layer and expand its legend. Notice that U.S. Forest Service land is coded with the value 200, Turn off the Ownership layer and collapse its legend. Now you will create the mask using the SETNULL function. The SETNULL function's Map Algebra syntax is: SETNULL(, {expression} The SETNULL function applies a test against the current cell and if the test is true replaces its value with NoData. If the testis 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. From the Map Algebra toolbox, open the Single Output Map Algebra tool and enter the following Map Algebra expression: SetNull({Ownership] = 200 OR [Soil] == 901, 1) Keep the path to the default geodatabase (SierraNevadaSeratch.gdb), but change the output raster name to Mask. Click OK. VIEW RESULT The expression set non-Forest Service land and water to NoData. Since you are only interested in soils on Forest Service land, you will now clip the Soil layer using the mask you just created. Step Clip the soil layer using the mask 3 ‘To clip the Soil layer to the area that is defined by the Mask layer you will use the Extract by Mask tool. From the Extraction toolbox, open the Extract by Mask tool and fill out its parameters as follows: Input raster: Soil Input raster or feature mask data: Mask Output raster: ..\SierraNevadaScratch. gdb\ClipSoil Click OK. VIEW RESULT 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, as when extracting data for a specific city from a countywide database. © What would be an alternative way to clip the Soils raster? What would be an alternative way to clip the Soils raster? Alternatively, you could set the Mask layer as a mask under Raster Analysis Settings in your Environment settings. Then you could enter the expression [Soils] into the Single Output Map Algebra tool to evaluate the Soils layer with the mask. Step Save the map document 4 Save the map document as SetNull2.mxd in your VirtualCampus\LearnSA9\MapAlgebra folder ‘The SETNULL function assigns the value NoData to cells that meet a certain condition, otherwise it returns a user specified value. It can be used to create a mask. “Previous | Next” ‘Learning ArcGIS Spatial Analyt | Working with Map Algebra Copyright © 2001-2008 ESRI. Alt rghs reserved Combining multiple rasters “Previous| Next Sometimes you want to analyze an area that falls on more than one raster. To analyze the entire area, you must perform the steps of your analysis multiple times, once for each raster. Such a process could be time-consuming and error- prone, especially if you have a large number of rasters or @ multi-step analysis. However, by first combining the individual rasters to create a single larger raster, you'll only need to perform the analysis steps once. Pn Vegetation1 Vegetation2 Rasters can be combined as long as they share the same spatial reference and are of the same type, for example vegetation. Perhaps you want to analyze the variety of the vegetation in a particular agricultural or wildlife management area using a vegetation raster. Your area of interest happens to fall near the edge of the raster, so you need two different rasters to see the entire region. There are a few things you'll need to check before you combine rasters. First, the input rasters may be totally overlapping, partially overlapping, perfectly adjacent, or entirely separated, as long as they are in the same coordinate system. ‘Second, the input rasters must be of the same type. For example, you could combine a soils raster with one or more soils rasters or an elevation raster with another elevation raster. Third, you need to know if you are combining discrete or continuous rasters because the method used to join each type differs in how it handles areas where the input rasters overlap. «Previous | Next” ‘Learning AreGIS Spatial Amalss| Working with Map Algebra Merge and mosaic rasters © Prin « Previous| Next® In this exercise, you will assemble raster data for an area where a wildfire has occurred. You'll combine multiple input rasters into a single raster dataset through the process of mosaicking. As you work through the steps, you will see how you can control raster processing. Estimated time to complete: 10 minutes Before you begin ‘The data for this exercise is contained in the following files + LearnSA.exe (Course data file) + MapAlgebra.exe (Module data file) If you have not downloaded one of these files, you should download the data now. Need help? Course dat: Step Open the map document If necessary, start ArcMap. Open the Mosaie.mxd map document from your LearnSA9\Map Algebra folder. VIEW RESULT © Can't find your data? You see four adjacent elevation rasters. A group layer containing four adjacent vegetation rasters is turned off. If necessary, load the AreGIS Spatial Analyst extension and make the ArcToolbox window visible. ‘The environment settings for this exercise have been set as follows: General Settings: + Current Workspace: ...\LeanSA9\MapA lgebra\Piru.edb + Scratch Workspace: ...\earnSA9\MapAlgebra\PiruScratch.edb + Output Coordinate System: Albers Conical Equal Area + Extent: Same as layer Fire Perimeter Raster Analysis Settings: + Cell Size: 90 + Mask: Fire Perimeter Step Mosaic continuous rasters 2 In this step, you'll mosaic the four elevation rasters together. The overlapping areas of the mosaic can be handled in several ways, for example, you can set a parameter to only keep the first raster dataset’s data, or you could ‘choose to blend the overlapping cell values. ‘REVIEW CONCEPT If necessary, expand the Data Management Tools toolbox. Expand the Raster toolset, expand Raster Dataset, and double-click the Mosaic To New Raster tool to open it Fill in the parameters as follows: Input Rasters: Elevation\ElevNE, Elevation\ElevNW, Elevation\ElevSE, and Elevation\ElevSW Output Location: ...\MapAlgebra\PiruSerateh.gdb Raster dataset name with extension: ElevMosaic Pixel type: 16_BIT_UNSIGNED Celisize: 90 Mosaic Method: BLEND Note: You may have to scroll down in the tool dialog box to see some of the parameters. Click OK. Notice that the new raster appears to be dark, You need to symbolize it to see it better. Open the Layer Properties for ElevMosaic, Click the Symbology tab, and for Stretch Type, choose Standard Deviations. If prompted to compute statistics, click Yes. Click OK on the Layer Properties dialog box. You see a new elevation layer containing the combined four input rasters. Note: In this step. you've used the Mosaic tool with continuous rasters, but it would work with discrete rasters as well. Step Extract data using a mask 3 If the remaining analysis is going to be focused on the fire perimeter, you might as ‘well limit the output to the area within the fire perimeter. You'll use the Extract by Mask tool to accomplish this. If necessary, open the Spatial Analyst Tools toolbox. From the Extraction toolset, double-click the Extract by Mask tool and fill out its parameters as follows Input raster: ElevMosaic Input raster or feature mask data: Fire Perimeter (Output raster: ...\PiruScratch.gdb\ElevExtract VIEW RESULT Click OK. ‘When the tool is finished, turn off the Elevation group layer and the ElevMosaic layer. VIEW RESULT Notice that Elevation values are present within the fire perimeter. Cell values outside the fire perimeter are NoData. ‘Turn off the ElevExtract layer and turn on the Vegetation group layer. Step Merge diserete rasters 4 In this step, you'll merge the four vegetation rasters into a single raster. You could use the same process of using the Mosaic To New Raster and Extract by Mask tools. Or, you could accomplish the same thing using a Map Algebra merge expression within the Single Output Map Algebra tool. Since the Single Output Map Algebra tool is within the Spatial Analyst Tools toolbox, the raster analysis, settings, including the mask, are used. Expand the Map Algebra toolset and open the Single Output Map Algebra tool Enter the following Map Algebra expression: Merge (VegNE, VegNW, VegSE, VegSW) For Output raster, maintain the PiruSeratch.gdb geodatabase, but change the raster name to VegMerge. VIEW RESULT The MERGE function can merge up to 50 rasters of different extents. The input rasters should all have the same type of data and the same spatial reference. The rasters may partially overlap, be adjacent, or be completely isolated from one another. In areas of overlap, the cell value equals the cell of the last input raster, Click OK. When the tool s finished, turn off the Vegetation group lay The output of the merge expression has been limited to within the fire perimeter Note: To combine continuous rasters using Map Algebra, you would use the Mosaic function in the Single Output Map Algebra tool. Step Save the map document Save the map document as Mosaie2.maxd in your LearnSA9\MapAlgebra folder. ‘The Mosaic To New Raster tool allows you to combine multiple raster datasets into a new single raster dataset. In the tool's dialog box, you specify the pixel type of the output raster to match the input raster datasets. You also determine the method used to mosaic overlapping areas. However, since the Mosaic To New Raster tool is not a Spatial Analyst tool, a specified mask is ignored. To limit the mosaic output to the area of a mask, you need to use the Extract by Mask tool. Map Algebra allows you to perform the above-described tasks in one step. To combine discrete rasters using Map Algebra, you can use the merge function in the Single Output Map Algebra tool. Since the Single Output Map Algebra tool is within the Spatial Analyst Tools toolbox, the raster analysis settings, including the mask, are used. «Previous | Next” Review Previous | Next Map Algebra is the analysis language of ArcGIS Spatial Analyst and you can access Map Algebra through the geoprocessing framework. It has a simple syntax similar to any algebra. The inputs to an expression may be as simple as a single raster layer or shapefile, or as complex as a compound expression using many operators, functions, and input data With Map Algebra, not only can you access functions not available in the user interface, you can also build complex expressions and process them as a single command. For instance, you can calculate the sine of an input raster dataset or faster layer and add that to two other input raster datasets or raster layers. Like all languages, Map Algebra is defined by rules. By understanding the basic rules, you will be able to use ArcGIS Spatial Analyst in new ways. Review questions 1. What is the difference between an operator and a function? 2, Name two functions that can be used to set cell values to NoData, 3. Which geoprocessing tools allow you to enter and evaluate Map Algebra expressions? @ what are the correct responses? ~ Answer 1. Operators work against one or more objects to develop new values. Functions perform specialized tasks, such as computing slope from elevation, and usually return numeric values. 2. CON and SETNULL 3. There are two geoprocessing tools for Map Algebra: Algebra tool and Multi Output Map Algebra tool. ingle Output Map Key terms arithmetic operator Boolean operator combinatorial operator function logical operator Map Algebra NoData operal relational operator «Previous | Next” Exam This is the Working with Map Algebra exam. You need to correctly answer 8 of the 110 questions to pass. GOOD LUCK! 2. The Mosaic To New Raster tool recognizes a mask that is set in the environment settings. True False Which of the following is an example of a surface analysis Map Algebra function (tool)? Reclassify Extract By Mask é 5 Feature To Raster © ‘Slope “Less than’ is an example ofa surface analysis Map Algebra function © True False In AteMap, open SetNull.mxd, located in your LearnSA9\MapAlgebra folder. How many cells of the Soils layer contain foamy alluvial sols? " 88 8,426 46,678 166,836 7 > All of the following expressions are Map Algebra functions for converting data, except one. Which one? © Round Down © Float « Int © Deg Which of the following is a valid use of the CON function? CON({DamBasin] AND ({DamElev] <= 790), 790) CON[DamBasin] AND [DamElev] <= 790, 790 CON([DamElev] <= 790)) CON = ([DamBasin] AND ([DamElev] <= 790), 790) = a Ifyou add a cell with a cell value of 1.567 and a cell with NoData, what will be the result? o 30 1 NoData 1.567 8, When mosaicking discrete rasters with the Mosaic To New Raster tool, the BLEND or MEAN methods are best for handling overlapping areas. ‘True False ©, Which of the following is a required argument for the Hillshade function when run from the command line? azimuth - factor o. in_raster é altitude 10, In AreMap, open SetNullmxd, located in your LearaSA9\MapAlgebra folder. Use the SetNull function in the Single Output Map Algebra tool to answer the following question: How many cells of the Ownership layer are owned by the US Forest Serviee or by the State of California? © 67.740 99,165 71.233 165.159 729 CALCULATE MY GRADE Learning ArcGIS Spatial Analyst) Working with Map Alger Copyright 02010 Es Al sghs reserve Exam « Retake exam | Module Evaluation? You Passed the Exam! Congratulations, Eduardo — you correctly answered 8 of the 10 questions. You have now completed this module. Please take a moment to fill out the module evaluation. Continue to the next module when you are ready. at ie vs v7. The Mosaic To New Raster tool recognizes a mask that is set in the environment settings. False is correct! Refer to Merge and mosaic rasters, Step 2 Which of the following is an example of a surface analysis Map Algebra function (tool)? Slope is correct! Refer to Map Algebra functions "Less than" is an example of a surface analysis Map Algebra function. False is correct! Refer to Map Algebra operators In ArcMap, open SetNull.mxd, located in your LearnSA9\MapAlgebra folder. How many cells of the Soils layer contain loamy alluvial soils? 88 is correct! Refer to Use condi nal processing Hint: Open the attribute table of the Soil layer and look up the value of alluvial soils, loamy. All of the following expressions are Map Algebra functions for converting data, except one. Which one? Deg is correct! Refer to Work with operators. Step 3 Hint: Display ArcToolbox and expand the Math toolset to look up exis conversion functions, ing data Which of the following is a valid use of the CON funetion? CON([DamBasin] AND ([DamElev] <= 790), 790) is correct! Refer to Use conditional processing, Step 3 If you add a cell with a cell value of 1,567 and a cell with NoData, what will be the result? NoData is correct! Refer to Working with NoData When mosaicking discrete rasters with the Mosaic To New Raster tool, the BLEND or MEAN methods are best for handling overlapping areas, True is incorrect. Refer to Merge and mosaic rasters. Step Hint: Open the Mosaic to new Raster tool, click Show Hel,and read how the different methods work. $¢9. Which of the following is a required argument for the Hillshade function when run from the command line? azimuth is incorrect. Refer to Work with functions. Step 5 Hint: Type in Hillshade_sa in the ArcMap command line window and display the code completion feature, The arguments in are required, the ‘ones in {braces} are not required, 10. In AreMap, open SetNull.mxd, located in your LearnSA\MapAlgebra folder Use the SetNull function in the Single Output Map Algebra tool to answer the following question: How many cells of the Ownership layer are owned by the US Forest Service or by the State of California? 67,740 is correct! Refer to Create a mask to clip raster, Step 2 « Retake exam | Module Evaluation” tearing ArcGIS Spatial Analpst| Working with Map AIgebra Copyright ©2010 sn. Al tights served u a > 1 eles a re ee i Oo oe ee a — a a eee Bn ae oe a oe - Ss a

You might also like