Saturday, December 10, 2016

ArcGis model builder

In this tutorial, I will take you through the core concepts of using ESRI model builder.  Model builder is used to automate GIS processes by... thumbnail 1 summary
In this tutorial, I will take you through the core concepts of using ESRI model builder.  Model builder is used to automate GIS processes by linking data input, ArcGIS tools/functions, and data output.  Model builder is part of the ArcGIS geoprocessing framework.  The main advantage of using the model builder for GIS work is that your processes can be automated without using any code.  Another advantage is that you can save your GIS process and rerun the model at any time.  This is particularly good when you need to go back and make adjustments to your process/analysis.  Rather than redoing the entire analysis, you can simply change 1 parameter and rerun the model to produce new results.

We will create a new toolbox and add a model that we will build. The final step will be to run our model and view the data output.

This tutorial has been designed for ArcGIS 9.x

Open ArcGIS. Within ArcMap, open the ArcToolbox window. Right-click inside the toolbox window and choose “New Toolbox”, give it a meaningful name.  We will call our model “Hazardous Buffers”.

ArcGIS New Toolbox

Right-click your new toolbox and choose “New > Model…”  This will open up the ModelBuilder window.

Under the Model Menu, choose “Model Properties...”.  Under the “General” tab, add a name for your model. This name must be unique within the toolbox and cannot contain any spaces.  Add a label for your model.  This is the label that you will see in your toolbox.  It can contain spaces and does not need to be unique.  If desired, add a description to your model to inform the user. This description will appear under the models help. Put a check next to “Store relative path names (instead of absolute paths)”.

ArcGIS Model Builder General Properties

Now click the “Environment” tab. Under “General Setting”, check “Current Workspace” and click the “Values…” button. Click on general settings and browse to the location of your work directory.  This is where your GIS data is stored and where the output from the model will be created.

ArcGIS Model Builder Environment Settings

If you do not do this, ArcGIS will not know where to create the output from the model and you will get an error on your first tool similar to the following message:

“Error in executing function
Failed to execute()”

Setting up this environment is a prerequisite to performing geoprocessing tasks.

You may also want to set up the “Extent” and “Output Coordinate System”.  I have set the Output Coordinate System to be the “Same as Input” and the Extent to be the “Union of Inputs”.

ArcGIS ModelBuilder Multiple=

Click “OK” in the “Environment Settings” and “Model Properties” window.  After making any changes to your model, you will need to save it.  Press the “Save” button now.

Now that we have created and set up our model, we can start to add analysis tools to it and automate our GIS process.  Before we develop the model, I will describe the methodology involved in our GIS analysis.  This model will have 2 data inputs: municipal boundary polygons and hazard point locations. You can download the sample data here. Below is a map showing the 2 input layers:

ESRI ModelBuilder Input Layers

The boundary file is split up into 2 sections of the municipality: Section 1 and Section 2. The goal of this analysis is to create regions around the hazard locations that are within Section 2. The regions will be created using a 600 meter buffer radius.

The first tool we will use is a spatial join to give the hazard points the attributes of the boundary file (Section 1 and Section 2).  The map below shows the output from this step.

ArcGIS Spatial Join Within

The next step will be to select only those points that have an attribute of Section 2.

ArcGIS Select Tool Points

With those points, we will buffer them by 600 meters and dissolve all boundaries.

ArcGIS Buffer Tool Points

We will then make a selection of the “Section 2” boundary.

ArcGIS Select Tool Polygon

The final step will be to perform an intersection between the Buffer Regions and the Section 2 boundary.

ESRI ArcMap ModelBuilder Output

The final result shows the Hazard Regions that are within the Section 2 boundary.

Now that you have an understanding of the method we are going to use, let’s start automating the process using Model Builder.  This process uses 4 ArcToolbox functions: Spatial Join, Select, Buffer and Intersect.  Our model will link these processes together.  We want to allow flexibility with this model so we will be creating model parameters that the user can change before they run the model.  For example, we will allow the user to modify the buffer radius distance.  When the user runs this model, they will fill out an input form with all of our parameters before running the model.

If the model builder window isn’t open, open it by right-clicking your model and selecting “Edit…”

Whenever you create a model, think of the parameters you would like the user to enter and the parameters that will be set in your model.  A parameter is any option within a tool. For example, the “expression” option within the “Select” tool. This is a parameter we might want to include so the user can easily run the analysis on a different selection of points.

In ArcToolbox, find the Spatial Join tool. An easy way to find tools is to use the “Index” tab and type in a keyword to find. Drag the “Spatial Join” tool and drop it in the Model Builder window. A new element will appear in your model.

Right-click the Spatial Join element and choose “Make Variable > From Parameter > Join Features”. Right-click again and choose “Make Variable > From Parameter > Target Features”. Click the auto-layout button and you should see 2 inputs to our model. Right-click the “Join Features” input and choose “Model Parameter”.  Do the same for the “Target Features”.  What we have just done is created 2 inputs to our model and specified that they are parameters that the user will enter.

Right-click the “Join Features” input and select “Rename”. Enter “Boundary Polygons”. This gives the input a more meaningful name.  Rename the “Target Features” to “Hazard Points”.

Double click the Spatial Join tool. Under “Output Feature Class”, enter “hazards_spatialjoin”. Choose “JOIN_ONE_TO_MANY” for the Join Operation. Under “Math Operation”, use “IS_WITHIN” and press OK.

Save your Model.

This tool will give the attributes of the Boundary Polygons to all Hazard Points that are within its boundaries.  We have specified a one to many join because each boundary polygon can contain many hazard points.

ArcGIS Model Builder Not Ready to Run

You will notice that your model has no color to it and all elements are white.  This means that your model is not ready to run.  Even though we have specified that boundary polygons and hazard points are inputs to the model, it is not considered ready to run unless you tell ArcGIS the location of your data.

Double-click the Boundary Polygons element and enter the location of the boundary file.  Double-click the Hazard Points element and enter the location of the shapefile.

Your model will now have color to it, meaning it is ready to run.  The blue round elements mean these are inputs to the model.  Yellow rectangular elements are tools.  Green round elements are derived data that is output from the model.

ArcGIS Model Builder Ready to Run

Next, let’s add a Select tool to select only those records that have a value of 2 in the section attribute.

Find the Select tool and drag it onto the end of your model. Then use the “Add Connection” button ArcGIS Model Builder Add Connection Button to connect the hazards_spatialjon.shp output to the Select tool. Double-click the Select tool to open up its options. Enter a meaningful name for the Output Feature Class (I have used hazards_selectsection.shp). Under "Expression", enter "section = 2". This is the attribute and value that we are using to base our selection. Click OK.

Since we would like this model to be flexible, we will allow the user to specify this expression within the model parameters. Right-click the Select tool and choose "Make Variable > From Parameter > Expression". You will see a new element appear. The element will be light blue, meaning it contains a value. Use the "Auto Layout" button ArcGIS Model Builder Auto Layout Button to adjust the layout of your model. Right click this new Expression element and choose "Model Parameter". This will give the user the option to adjust this parameter before running the model. Right-click the element again and choose Rename... Add a meaningful name. This will be the name the user will see when setting up the parameters for the model (I have used Hazard Selection). Save your model.

ArcGIS Model Builder Value Parameter

Now that we have a selection of our hazard locations that are within Section 2, we will buffer these points by 600m. Drag the Buffer tool to the end of your model and connect it to the last output (hazards_selectsection.shp). Within your model, double-click the Buffer tool. Add a meaningful name to the Output Feature Class such as hazards_buffer.shp. Under Distance, choose Linear Unit and enter 600 meters. Under Dissolve Type, select "ALL". This will dissolve any boundaries between buffers and create a single feature from any overlapping buffers. Click OK.

Let's make the buffer distance a parameter that the user can adjust. Right-click the Buffer tool and select "Make Variable > From Parameter > Distance [value or field]". Right-click the Distance element and choose "Model Parameter". Rename this Parameter to "Buffer Distance". Save your model.

ESRI Model Builder

Next we will add another Select tool to isolate Section 2 from our Boundary Polygons.Drag the Select tool onto your model. Connect the original "Boundary Polygons" element to the Select tool. Double-click this element to specify its values. Specify the Output Feature Class to be "boundary_select.shp" and the expression to be "section" = 2. You can build this expression using the SQL Query Builder. Click OK.

Let's make this a parameter so the user can rerun this analysis on a different selection. Right-click the Select tool and choose "Make Variable > From Parameter > Expression". Rename the Expression element to "Boundary Selection" by right-clicking it in your model and choosing "Rename...". Model the parameter by right-clicking and selecting "Model Parameter".

ArcGIS Model Builder

You should now have 2 branches to your model, both ending with an output (hazards_buffer.shp and boundary_select.shp). The last step will be to perform an intersect between these 2 outputs.

Drag the Intersect tool onto you model. Use the "Add Connection" tool to connect both these outputs to the Intersect tool. Double click the Intersect tool and specify the Output Feature Class to be "boundary_hazard_intersect.shp" and click OK. By default, all output layers are intermediate, meaning they are temporarily created while the model runs and are deleted at the end. We would like our last output to be permanent. To do this, right-click the "boundary_hazard_intersect.shp" and uncheck "Intermediate". In order to add this layer to the display it must be a modeled parameter. Do this now by right-clicking the final output and selecting "Model Parameter". Save your model.

ArcMap Model Builder Complete Final

The model is now complete. Close the ModelBuilder window.

Make sure the final output will be added to the display by going to "Tools > Options...". Click on the Geoprocessing tab and under "Display / Temporary Data" make sure there is a check next to "Add results of geoprocessing operations to the display."

We will now run our model. In ArcToolbox, double click your model. You should see an input form with the parameters that we specified in our model (these are the elements with a P next to the top right of them in ModelBuilder).

ArcGIS Model Input Form

If you would like to rearrange the order of parameters in your model, go to the model properties and click the "Parameters" tab to edit these options.

Since all of the parameters have been specified, just click OK to run the model. You should see the following output:

ArcGIS Model Final Output

Any errors that occur will be shown in the Progress Dialog window in red font.

To really understand the power of model builder for automating geo processes, we will rerun this model but this time adjusting the parameters. This will in effect run the same analysis but on a different subset of data. This removes a lot of manual step by step processes. For example, we will run this model but for Section 1 with a 1000m buffer.
Double click the model to open the input form. Change "Hazards Selection" to section = 1. Adjust "Boundary Selection" to "section" = 1. Change the buffer distance to 1000. You must use a different name for the final output because the current name already exists from our first run. I have used "section1_buffer1000.shp".

ArcGIS Model Input Form Adjusted

Click OK to run the model. You should see the following output:

ArcGIS Model Rerun Analysis Output

No comments

Post a Comment

Recent