snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/exe3_model builder_2017.docx · web viewexercise 3....

29
1 Exercise 3. Spatial Analysis- Applying Model Builder Geoprocessing Capability of ArcGIS 12 Spring 2017 Prepared by Ayse Kilic - revised March 8, 2017 Goal The goal of this exercise is to serve as an introduction to Spatial Analysis with ArcGIS. Objectives Conversion of ASCII grid into a raster format via ArcGIS. Use the Spatial Analyst Tool to calculate slope and aspect from a gridded elevation data set Apply the model builder geoprocessing capability of ArcGIS to program a sequence of functions to automate the importing of the ASCII grid and calculation of Slope, Aspect, Hydrologic Slope and Flow direction Computer and Data Requirements To carry out this exercise, you need to have a computer that runs ArcGIS for Desktop 10.3.0. The necessary data are provided in a zipped file (Exe3Data.zi) at the course web site: http://snr.unl.edu/kilic/gisrs/2017/ Readings Handout on "Computation of Slope" at http://snr.unl.edu/kilic/gisrs/2017/Slope.pdf 1 The structure of this exercise originated from Dr. David Tarbon, Utah State University.

Upload: trinhnhan

Post on 04-Apr-2018

227 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

1

Exercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability

of ArcGIS12

Spring 2017

Prepared by Ayse Kilic - revised March 8, 2017

Goal

The goal of this exercise is to serve as an introduction to Spatial Analysis with ArcGIS.

Objectives

Conversion of ASCII grid into a raster format via ArcGIS.

Use the Spatial Analyst Tool to calculate slope and aspect from a gridded elevation data set

Apply the model builder geoprocessing capability of ArcGIS to program a sequence of functions to

automate the importing of the ASCII grid and calculation of Slope, Aspect, Hydrologic Slope and Flow direction

Computer and Data Requirements

To carry out this exercise, you need to have a computer that runs ArcGIS for Desktop 10.3.0. The necessary data are provided in a zipped file (Exe3Data.zi) at the course web site:http://snr.unl.edu/kilic/gisrs/2017/

Readings

Handout on "Computation of Slope" at http://snr.unl.edu/kilic/gisrs/2017/Slope.pdf

1 The structure of this exercise originated from Dr. David Tarbon, Utah State University.

Page 2: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

2

1.1. Slope calculations using Arc Hydrology and Surface Toolbox functions:

Given the following grid of elevations that are on a 10 m grid, calculate the slope and aspect (slope direction) at the grid cell labeled A and B using ArcGIS.

The data has been saved to a text file (*.text) and name it 'elevation_data.txt'

NCols 5NRows 4XLLCorner 0YLLCorner 0Cellsize 10NODATA_value -99395.0 396.0 395.4 401.2 396.6390.2 391.6 393.6 397.2 395.2390.0 392.2 392.8 395.8 394.8390.8 392.2 394.0 397.2 395.4

This example also illustrates how raw grid data can be represented in an ASCII text format that ArcGIS can then import. Knowing how to get raw information into a form where it can be imported and analyzed using GIS is a useful skill.

Open ArcMap and Add “Elevation_Data.txt”. Click on the search icon (Ctrl+F) and ask for a local search. Type “ascii to raster” in the dialog box. Find the function ASCII to Raster (Conversion) (Tool).

Elevations for 5x 4 grid cells. The cell size is 10m.

395 396 395.4 401.2 396.6

390.2 391.6 393.6 A 397.2 395.2

390 392.2 392.8 B 395.8 394.8

390.8 392.2 394 397.2 395.4

Page 3: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

3

You can also open this tool directly from Arc Toolbox:

The tool should open that will import the data from the text file.

Specify the name of the Output raster as elevation.tif and give it a disk location. (Note that the extension specifies the grid file format, .tif for a TIFF file, .img for an ERDAS IMAGINE file, or no extension for an ESRI GRID raster format.).

Specify the Output data type as FLOAT because the given elevation data includes decimal values.

Page 4: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

4

You can use the identify button on the grid created to verify that the numbers correspond to the values in the table above.

Page 5: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

5

We are going to use the Spatial Analyst Tool of ArcGIS to calculate slope and direction (aspect) from this gridded elevation data set. Let’s make sure that function is available on our computer.

Open Customize Extensions and verify that the Spatial Analyst function is available and checked. This is where the spatial analyst license is accessed, so if Spatial Analyst does not appear you need to acquire the appropriate license.

If the spatial analyst tool does not show up, then you will need to speak to the software administrator to get it installed.

Page 6: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

6

Open the tool Spatial Analyst Tools under the Arc Toolbox. Then double click on Surface, then double click on Slope

Page 7: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

7

You should see the “Slope” Menu. Select elevation.tif as the input raster and specify names for the output raster (e.g. Slope). Note that raster file names cannot exceed 13 characters. Set the Output measurement to PERCENT_RISE and leave the Z factor at 1. Click OK.

Note: you can click on Tool Help button to read details on this tool. Note that when you click on each field in the dialog box, the help part of the dialog to the right explains the content of the file or option.

The resulting Slope grid should now be added to the display.

Q1. Use the identify button and write the value of ArcGIS calculated slope for grid cell A and B (see the table of elevations on page 2 to know where A and B are).

Page 8: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

8

We are going to do a similar process to obtain a grid showing aspect (direction of the slope).

Open the tool Spatial Analyst Tools Surface Aspect. Select elevation.tif as the Input raster and specify a name for the output raster (e.g. Aspect). Click OK.

Note that the aspect legend shows eight compass points (North, Northeast, East, etc.) and “flat”.

The resulting Aspect grid should be computed and added to the display.

Q2. Use the identify button and note the value of ArcGIS calculated aspect for grid cells A and B.

Page 9: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

9

Now we can use the “Flow Direction” tool to tell us which direction water would flow from each of the elevation grids (pixels). This will tell us how a model should simulate overland flow, and how the flow will ‘concentrate’ into a stream.

Open the tool Spatial Analyst Tools Hydrology Flow Direction

In the menu that opens, Select elevation.tif as the input raster and specify names for output rasters (e.g. FlowDirection and PercDrop).

Note that the help explanation that appears when clicking on the output drop raster field in the dialog box explains that the Output drop raster is essentially the slope expressed as a percentage. Click OK

Page 10: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

10

Page 11: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

11

You should see the flow direction that looks something like the following. See the help screen shot later that explains what the 1, 4, 8, 16, 32 and 64 numbers mean. Note that each of the pixels has its own flow direction. The flow can go in one of eight different directions to one of eight adjacent pixels (N, NE, E, SE, S, SW, W or NW). You could draw arrows, based on the color, to see how the flow concentrates.

Note that these numbers are 2x where x goes from 1 to 8. This was done to reduce the storage requirements for the flow direction (it can be stored as an 8-bit number).

You can use Help in ArcGIS to get instructions and explanation on how the flow direction tool works.

To turn in: Table giving slope, aspect, hydrologic slope and flow direction at grid cells A and B. Please turn in a diagram or sketch that defines or indicates what each of these numbers means for the specific values obtained for cells A and B.

Q3. Use the identify button and record the value of the Flow Direction and hydrologic slope (PercDrop) for grid cell A and B. Record in a table flow direction and hydrologic slope (Output drop) for the grid.

Note that the coding of direction of flow numbers are 2x where x goes from 1 to 8. This was done to reduce the storage requirements for the flow direction (it can be stored as an 8-bit number)

Page 12: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

12

Setting Environment (Workspace) for your project:

It is useful to have all of your temporary and permanent files stored to a single folder for each homework/exercise. Otherwise, Arc will create these files under a default geodatabase. This will help set the default folder suggested by the menus of the tools.

Click on the Geoprocessing on the main menu and select Environments and then click on Workspace. Define the location for current workspace.

Page 13: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

13

1.1 Automating procedures using Model Builder.

Modelbuilder provides a convenient way to automate and combine together geoprocessing tools in ArcToolbox, especially those actions that you would like to do over and over again. ModelBuilder can automate complex analyses, and documents your “workflow” in a form that is visual and can readily be described. Modelbuilder can provide a visual display of calculation processed that can be included in a term project report to document how you’ve done your analysis.

Here we will develop a Modelbuilder tool to automate the importing of the ASCII grid and calculation of Slope, Aspect, Hydrologic Slope and Flow direction.

Right click on the whitespace within the ArcToolbox window and select Add Toolbox. Navigate to a folder where you want to store your work (e.g. Exe3). In the opened window, click on the New Toolbox icon and rename the “Toolbox.tbx” to Elevation Processing.tbx (or something else you might like).

Select the new toolbox and click Open.

A new toolbox should now appear in the list of tools in ArcToolbox. It will appear in alphabetical order.

Right-click on the new toolbox and select new and model.

Page 14: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

14

The model window should open. This is a window where you can drag, drop and link tools in a visual way much like constructing a flow chart.

Leave the Model window open, and go back (i.e. to the left) to the ArcToolbox window. Browse to Conversion Tools To Raster ASCII to Raster. Drag the ASCII to Raster tool onto the model window.

Page 15: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

15

Double click on the ASCII to Raster rectangle to set this tool's inputs and outputs.

Set the Input ASCII raster file to elevation_Data.txt and Output raster to elevm.tif (I used elevm.tif so as to distinguish it from the elevation.tif that already exists). Set the output data type to be FLOAT. Click OK to dismiss this dialog. Note that the model elements on the ModelBuilder palette are now colored indicating that their inputs are complete.

The above process will open the Elevation_Data.txt file and convert it to a tif file inside ArcGIS. Now let’s add the flow direction processing element to the model.

Locate the tool Spatial Analyst Tools Hydrology Flow Direction and drag it on to your window. Your window should appear as follows.

Page 16: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

16

We need to ‘connect the dots’ so that the output from the ASCII to raster function is taken as input to the Flow Direction function. To do this use the connection tool to draw a line from elevm.tif, the Output raster of ASCII to Raster, to the Flow Direction tool rectangle. At the dialog that pops up select Input surface raster to indicate that elevm.tif is to be used as the input Surface raster for the Flow Direction tool.

Page 17: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

17

Notice that the "output drop" oval is hollow. This is because this is an optional output that has not been specified.

Now Double click on the Flow Direction tool and specify names for both the Output flow direction raster and optional Output drop raster. We will use new names for these. Click OK.

Alternatively you could double click on output ovals individually to specify the output rasters. The model is now ready to run.

Page 18: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

18

Run the model by clicking on the run button .

The Model progress box opens and the progress bar indicates when the model completes. You can then add the outputs to the map and examine the results.

Page 19: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

19

In the model, use the layout tool to organize the layout.

In the future, you can run this Elevation Processing tool with any txt data file by double clicking on the blue txt symbol and pointing it to a different file.

We can add the Slope tool to this same Elevation Processing tool. Add the Spatial Analyst Surface Slope tool to your model by dragging it onto the model window. Connect the elevm.tif output to this tool, specifying that it is the Input Raster for the Slope Tool.

Add the Spatial Analyst Surface Aspect tool to your model connecting it to elevm.tif as an input in a similar way. Double click on the Slope and aspect tool outputs and specify file names for the outputs. Use slopem for the slope output file.

When setting names you need to be careful that you do not use a name of a grid that already exists, or else you will get a yellow warning sign in the display and the model will not run, as shown below:

Page 20: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

20

Change the output raster name to “slopem” instead. Double click on the Slope tool and set the Output measurement to PERCENT_RISE. Your model should appear as follows.

Page 21: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

21

You can now click run and do all the processing required to import the data, compute Slope, Aspect, Flow Direction and Hydrologic Slope at the click of a button. The good part is that you can use this new ‘tool’ again and again by just changing the name of the elevation_data.txt file.

We can set up the model to be even more automated, regarding the naming of input and output files. Right click on elevation_data.txt and select Model Parameter.

Right click on each of the outputs FDirectionm, percdropm, slopem and aspectm in turn and select both Model Parameter and Add to Display:

Page 22: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

22

A letter “P” now appears next to these elements in the diagram indicating that they are 'parameters' of the model and they may be adjusted at run time.

Close your model and click Yes at the prompt to save it. Right click on the model in the Toolbox window to rename it something you like (e.g. FlowDirection).

Right click on the whitespace within the ArcToolbox window and select Save Settings To Default

This saves your toolbox settings so that your system remembers the tools you have loaded (in this case the tool you have written in Elevation Processing.tbx). This is useful if you want to not have to search for this Toolbox and load it again if you exit from ArcGIS or if there is a crash. However, this procedure applies to the specific computer you are using. Therefore, on a shared lab computer it will not help if the next time you work in the lab you are at a different.

If you go back to your model in the ArcToolbox list and now double click on it or Open it, you’ll see that the input files are shown as parameters of the model just like when you execute a tool in ArcToolBox.

Page 23: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

23

Where you see warnings or a red X near one of your files, it usually means that there is already a file of that name in the place where you propose to put the output or there is no input file. These can be resolved by setting the inputs and outputs correctly.

You can leave the names like they are, or you can change them anytime you re-run the model.

Editing the ModelIf at some point you want to go back and modify your model you should open it to Edit and make the changes you want.

You are done creating this model. Congratulations!!!! You are a programmer!!

You can now close ArcMap and have a coffee to celebrate.To turn in: A screen capture of your final model builder model.

Page 24: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

24

If you would like to save this tool to take to another computer or share with someone else you can copy the file XXX.tbx (where XXX is the name you gave your tool) from its location to a removable media to take with you.

If you are going to be sharing this tool more widely there are additional steps to take to clean up the interface (to avoid red X's), label the input fields and write help documentation for it. Close ArcMap.

Using a DEM tif file as input. We have converted the FlowDirection model to use a TIF file for elevation data (a DEM) rather than a text file. This is much more common. We made the conversion by going into the model edit mode and 1. deleting the “Elevation_Data.txt” object. The three processes were then left without an input. 2. Double clicked on “slope” to get the dialog box, and specifying the “Elevation.tif” file as the input

raster. This turned the Slope object back to a pretty green and yellow.3. Used the ‘connect’ tool to connect Flow Direction and aspect objects to the Elevation.tif object.

We now have a working model that uses a tif file for input.4. We modified the order of the file entry so that the Elevation.tif is not at the ‘bottom’ of the menu.

We did this by unchecking all of the “Model Parameter” and “Add to Display” settings for the five raster objects. We then rechecked them, starting with “Elevation.tif.” That made that input the first in the list. That is good since it is the input file.

5. We saved this new model under the name “FlowDirection_from_Tiff” (see below). You will use this file for the next exercise.

Summary of Items to turn in:

1. Table showing slope, aspect, hydrologic slope and flow direction at grid cells A and B. Please turn in a diagram or sketch that defines or indicates what each of these numbers means for the specific values obtained for cells A and B.

Page 25: snr.unl.edusnr.unl.edu/kilic/gisrs/2017/word/Exe3_Model Builder_2017.docx · Web viewExercise 3. Spatial Analysis-Applying Model Builder Geoprocessing Capability of ArcGIS. The structure

25

2. A screen capture of your final model builder model.