[go: up one dir, main page]

0% found this document useful (0 votes)
169 views148 pages

Model Builderfor Pro

Model Builder ArcGIS Pro

Uploaded by

Waleed GIS
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)
169 views148 pages

Model Builderfor Pro

Model Builder ArcGIS Pro

Uploaded by

Waleed GIS
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/ 148

ArcGIS Pro:

Working with ModelBuilder

Workbook
v3.1
ArcGIS Pro: Working with ModelBuilder

© ESRI (UK) Ltd Page ii


ArcGIS Pro: Working with ModelBuilder

Copyright
Copyright © 2010-2021 Environmental Systems Research Institute, Inc. and ESRI (UK) Ltd
All rights reserved. Printed in Aylesbury, Bucks, England.
The information contained in this document is subject to change without notice and is the exclusive property of ESRI (UK)
Ltd. and Environmental Systems Research Institute, Inc., and any respective copyright owners. This work is protected under
United Kingdom and United States copyright law and other international copyright treaties and conventions and except with
the prior written consent of ESRI (UK) Ltd, shall be used solely for the purpose of undergoing training provided by or with
the express written permission of ESRI (UK) Ltd. To the extent permitted by law, no part of this work may be reproduced or
transmitted in any form or by any means, electronic or mechanical, including but not limited to photocopying and recording,
or by any information storage or retrieval system, except as expressly permitted in writing by ESRI (UK) Ltd. If any lawful
copies are made, all such copies, whether in whole or in part, shall include the appropriate ESRI (UK) Ltd and
Environmental Systems Research Institute, Inc. copyright notice. All requests should be sent to Attention: Contracts
Manager, ESRI (UK) Ltd., Millennium House, 65 Walton Street, Aylesbury, Bucks HP21 7QG, England.

@esri.com, 3D Analyst, ADF, AML, ARC/INFO, ArcAtlas, ArcCAD, ArcCatalog, ArcCOGO, ArcData, ArcDoc, ArcEdit,
ArcEditor, ArcEurope, ArcExplorer, ArcExpress, ArcFM, ArcGIS, ArcGrid, ArcIMS, ArcInfo Librarian, ArcInfo,
ArcInfo—Professional GIS, ArcInfo—The World's GIS, ArcLogistics, ArcMap, ArcNetwork, ArcNews, ArcObjects,
ArcOpen, ArcPad, ArcPlot, ArcPress, ArcQuest, ArcReader, ArcScan, ArcScene, ArcSchool, ArcSDE, ArcSdl, ArcStorm,
ArcSurvey, ArcTIN, ArcToolbox, ArcTools, ArcUSA, ArcUser, ArcView, ArcVoyager, ArcWatch, ArcWeb, ArcWorld,
Atlas GIS, AtlasWare, Avenue, BusinessMAP, Database Integrator, DBI Kit, ESRI, ESRI—Team GIS, ESRI—The GIS
People, FormEdit, Geographic Design System, Geography Matters, Geography Network, GIS by ESRI, GIS Day, GIS for
Everyone, GISData Server, InsiteMAP, MapBeans, MapCafé, MapObjects, ModelBuilder, MOLE, NetEngine, PC
ARC/INFO, PC ARCPLOT, PC ARCSHELL, PC DATA CONVERSION, PC STARTER KIT, PC TABLES, PC
ARCEDIT, PC NETWORK, PC OVERLAY, Rent-a-Tech, RouteMAP, SDE, SML, Spatial Database Engine, StreetEditor,
StreetMap, TABLES, the ARC/INFO logo, the ArcAtlas logo, the ArcCAD logo, the ArcCAD WorkBench logo, the
ArcCOGO logo, the ArcData logo, the ArcData Online logo, the ArcEdit logo, the ArcEurope logo, the ArcExplorer logo,
the ArcExpress logo, the ArcFM logo, the ArcFM Viewer logo, the ArcGIS logo, the ArcGrid logo, the ArcIMS logo, the
ArcInfo logo, the ArcLogistics Route logo, the ArcNetwork logo, the ArcPad logo, the ArcPlot logo, the ArcPress for
ArcView logo, the ArcPress logo, the ArcScan logo, the ArcScene logo, the ArcSDE CAD Client logo, the ArcSDE logo,
the ArcStorm logo, the ArcTIN logo, the ArcTools logo, the ArcUSA logo, the ArcView 3D Analyst logo, the ArcView
Business Analyst logo, the ArcView Data Publisher logo, the ArcView GIS logo, the ArcView Image Analysis logo, the
ArcView Internet Map Server logo, the ArcView logo, the ArcView Network Analyst logo, the ArcView Spatial Analyst
logo, the ArcView StreetMap 2000 logo, the ArcView StreetMap logo, the ArcView Tracking Analyst logo, the ArcWorld
logo, the Atlas GIS logo, the Avenue logo, the BusinessMAP logo, the Data Automation Kit logo, the Digital Chart of the
World logo, the ESRI Data logo, the ESRI globe logo, the ESRI Press logo, the Geography Network logo, the MapCafé
logo, the MapObjects Internet Map Server logo, the MapObjects logo, the MOLE logo, the NetEngine logo, the PC
ARC/INFO logo, the Production Line Tool Set logo, the RouteMAP IMS logo, the RouteMAP logo, the SDE logo, The
World's Leading Desktop GIS, Water Writes, www.esri.com, www.geographynetwork.com, www.gisday.com, and Your
Personal Geographic Information System are trademarks, registered trademarks, or service marks of ESRI in the United
States, the European Community, or certain other jurisdictions.
Other companies and products mentioned in this document may be trademarks or registered trademarks of their respective
trademark owners.
INFO and PC-INFO are trademarks of Doric Computer Systems International Ltd.
ArcView GIS uses Neuron Data’s Open Interface

© ESRI (UK) Ltd Page iii


ArcGIS Pro: Working with ModelBuilder

Contains Ordnance Survey data © Crown copyright and database right 2021

© ESRI (UK) Ltd Page iv


ArcGIS Pro: Working with ModelBuilder

Table of Contents

Copyright ............................................................................................................................... iii


Table of Contents ................................................................................................................... v
Course Introduction.......................................................................................................... 8
Course introductions .............................................................................................................. 9
Course goals ......................................................................................................................... 10
Logistics ................................................................................................................................ 11
The ArcGIS System ............................................................................................................... 12
Additional resources ............................................................................................................ 13
1 - Introducing ModelBuilder .......................................................................................... 14
Introduction.......................................................................................................................... 14
Learning objectives .............................................................................................................. 14
Introducing ModelBuilder .................................................................................................... 15
Exercise 1: Introducing ModelBuilder .................................................................................. 16
2 - What you need to know about ModelBuilder ............................................................. 20
Introduction.......................................................................................................................... 20
Learning objectives .............................................................................................................. 20
Geoprocessing Environment Settings .................................................................................. 21
Elements of a model............................................................................................................. 24
Adding elements into the model.......................................................................................... 27
How do I validate and run my model? ................................................................................. 29
Accepting user input into your model ................................................................................. 31
Model properties ................................................................................................................. 33
Exercise 2: Basic processing techniques in ModelBuilder ................................................... 36
3 - Batch processing using ModelBuilder ......................................................................... 56
Introduction.......................................................................................................................... 56
Learning objectives .............................................................................................................. 57
Activity: Investigate model iteration .................................................................................... 57
Iterating over the contents of workspaces .......................................................................... 59
Looping using iterators......................................................................................................... 61

© ESRI (UK) Ltd Page v


ArcGIS Pro: Working with ModelBuilder

Processing selected features ................................................................................................ 62


Iterate over layers and values .............................................................................................. 64
Using inline variable substitution ......................................................................................... 69
Using the memory keyword ................................................................................................. 70
Sharing your model .............................................................................................................. 72
Exercise 3: Iteration on a raster dataset .............................................................................. 76
ModelBuilder’s Utility and Logic tools ............................................................................. 91
Introduction.......................................................................................................................... 91
Learning objectives .............................................................................................................. 92
Utility Tools .......................................................................................................................... 93
Model Preconditions ............................................................................................................ 98
Logic Tools ............................................................................................................................ 99
Activity: Investigate the logic tools .................................................................................... 100
Examples of the logic tools................................................................................................. 102
Tools which do not rely on a precondition ........................................................................ 105
Exercise 4: Performing some advanced modelling techniques ......................................... 107
Advanced Techniques in ModelBuilder ......................................................................... 116
Introduction........................................................................................................................ 116
Learning objectives ............................................................................................................ 116
Interactive Feature Input ................................................................................................... 117
Using Feedback in your model ........................................................................................... 119
Embedding one model inside another ............................................................................... 120
Schedule a model to run .................................................................................................... 122
Exercise 5: Working with multiple models ......................................................................... 124
Glossary of ModelBuilder terms.................................................................................... 134
Term ................................................................................................................................... 134
Description ......................................................................................................................... 134
Appendix 1: Running a model via Task Scheduler .......................................................... 136
Appendix 2 – Answers .................................................................................................. 139
Exercise 1 ............................................................................................................................ 139
Exercise 2 ............................................................................................................................ 140

© ESRI (UK) Ltd Page vi


ArcGIS Pro: Working with ModelBuilder

Activity 3 ............................................................................................................................. 142


Exercise 3 ............................................................................................................................ 143
Activity 4 ............................................................................................................................. 144
Exercise 4 ............................................................................................................................ 146
Exercise 5 ............................................................................................................................ 148

© ESRI (UK) Ltd Page vii


Course Introduction

The aim of this course is to teach you how to use ModelBuilder within ArcGIS Pro.

ModelBuilder allows you to create models which let you to automate, visualise, and
document your spatial analysis and data management processes.

A model is represented as a diagram that chains together sequences of processes and


geoprocessing tools, using the output of one process as the input to another process.

ModelBuilder is a visual programming language for building geoprocessing workflows; it is


intuitive, easy-to-learn and use, and can help you be more productive from the first day you
use it.

© ESRI (UK) Ltd Page 8


Course introductions
• Student introductions
• Name
• Organisation
• What do you do?
• ArcGIS Pro experience
• Goals and expectations for this class

© ESRI (UK) Ltd Page 9


Course goals
By the end of the course you will be able to:

• Understand what ModelBuilder is and what it can do.


• Become familiar with the geoprocessing environment settings.
• An overview of the ModelBuilder user interface.
• Recognise the parts of a model.
• Introduce model Iterators.
• Understand how to use in-line variable substitution and when to use the in-memory
workspace keyword.
• Investigate ModelBuilder’s logic and utility tools.
• Embed an existing model inside a parent model.

© ESRI (UK) Ltd Page 10


Logistics
If delivery is virtual:
• Virtual classroom and exercise area tour
• Please use a wired internet connection if possible
• Please mute when not speaking
• Please make use of ‘Step Away’ function when necessary
• Morning, lunch, and afternoon breaks

If delivery is face-to-face:
• Internet access
• Please turn off mobiles or set to silent
• Using Student ID badges and passes
• Refreshment, toilet and smoking facilities
• Emergency procedures
• Morning, lunch, and afternoon breaks

© ESRI (UK) Ltd Page 11


The ArcGIS System
Many people think of ArcGIS as "a family of products" but it is much more than that. The
diagram below displays the ArcGIS Platform as a tiered approach.

Where do you think ArcGIS Pro and ModelBuilder fit in?

The capabilities of the Platform can be grouped into the following categories:

Mapping & Visualization: Create, share, and use interactive high-quality 2D maps and 3D
scenes.

Spatial Analytics: Perform spatial analysis on your (or other organisation's) data; from
visualizing and measuring patterns and relationships, to complex feature overlay and
proximity analysis, and predictive modelling.

3D GIS: Convert data into 3D GIS to analyse and solve real-world problems.

Near Real-time GIS: Monitor and analyse live data feeds from sensors to make timely
decisions and to obtain a common operational picture.

Imagery & Remote Sensing: Collect, process, analyse, manage, and share imagery from
satellite, aerial, drone, and full motion video.

Data Collection & Management: Collect, integrate, geo-enable, store, access, and share
your data efficiently and securely.

© ESRI (UK) Ltd Page 12


Additional resources
Documentation for ArcGIS – https://pro.arcgis.com
This site provides unified access to web-based help, online content and technical support.

Esri Inc videos https://mediaspace.esri.com/


International User Conference and DevSummit session videos are posted here for your
viewing or you can download them to view at a more convenient time.

ESRI GIS Dictionary – https://support.esri.com/en/other-resources/gis-dictionary


This dictionary includes definitions of GIS terms related to geodata, analysis, GIS modelling
and web-based GIS, cartography and ESRI software.

GIS Glossary - http://wiki.gis.com/wiki/index.php/GIS_Glossary


This glossary is another great resource to demystify some GIS terminology

Esri Inc Training website: https://www.esri.com/training/catalog/search/

Access additional learning related to geoprocessing and additional ArcGIS.

© ESRI (UK) Ltd Page 13


1 - Introducing ModelBuilder

Introduction
You will have come across ModelBuilder in one of the previous courses, namely “An
Introduction to ArcGIS Pro for GIS Newcomers” and “Introduction to ArcGIS Pro for GIS
Professionals”. This is just a quick overview of things which you should already be fairly
familiar with.

Learning objectives
After completing this lesson, you will be able to:

• Understand the purpose of ModelBuilder


• Create a model
• Explore the ModelBuilder tab

© ESRI (UK) Ltd Page 14


Introducing ModelBuilder

Geoprocessing models automate, visualise, and document your spatial analysis and data
management processes. You create and modify geoprocessing models in ModelBuilder,
where a model is represented as a diagram that chains together sequences of processes and
geoprocessing tools, using the output of one process as the input to another process.
ModelBuilder is a visual programming language for building geoprocessing workflows; it is
intuitive, easy-to-learn and use, and can help you be more productive from the first day you
use it.

ModelBuilder in ArcGIS Pro allows you to:

• Build a model by adding geoprocessing tools, map layers, datasets, and other
variables, and connecting them into a process.
• Iteratively process every feature class, raster, file, table, etc. in a workspace.
• Visualise your workflow sequence as an easy-to-understand diagram.
• Run tools step-by-step, up to a selected step, or run the entire model.
• Make your model into a geoprocessing tool that can be shared with others or can be
used in Python scripting and other models.

© ESRI (UK) Ltd Page 15


Exercise 1: Introducing ModelBuilder
Estimated Time: 20 minutes

Let’s create a simple mode which performs a simple operation of creating a new feature
class and then adding a new field to it. You will then answer 6 questions about the
ModelBuilder interface.

a. Start ArcGIS Pro and log in using the supplied credentials.

b. Use a Catalog template and for Name type in MyModel and for Location browse to:

C:\EsriTraining\MBOP\MyFirstModel

A default geodatabase and toolbox based on the name of the ArcGIS Pro project is created.

c. Create a Folder Connection to C:\EsriTraining\Database.

d. Create a new model in the Catalog > Toolboxes > MyModel toolbox.

e. The ModelBuilder view opens.

f. Display the Geoprocessing pane (Analysis tab > Geoprocessing group > Tools)

g. Search for the Create Feature Class tool and drag it on to the model canvas.

h. Double click the Create Feature Class tool in the model to display the Properties
dialog box.

© ESRI (UK) Ltd Page 16


i. Fill in the box as follows:

Feature Class Name: MyFeatureClass

The parent geodatabase has already been selected and is based upon the project’s default
geodatabase.

As the mandatory parameters have been filled in the model is coloured in:

j. Search for the Add Field tool and drag it onto the model canvas.

k. Connect the MyFeatureClass output to the Add Field tool and choose Input Table.

l. Double click the Add Field tool and fill in the following:

Field Name: MBOP

© ESRI (UK) Ltd Page 17


As before the model is coloured in indicating that all mandatory tool parameters have been
chosen.

m. Run the model and inspect the results.

The new feature class and field are created!

As you have seen the ModelBuilder tab is displayed when a new model is created or
activated. As with all ribbons, the interface is divided up into a series of groups which contain
the various UI controls (buttons, drop down boxes, tools etc).

Answer the following six questions:

Using the model you have created, answer the following questions by hovering over the
relevant UI controls on the ModelBuilder ribbon:

Question 1: What is the difference between Auto Layout and Fit To Window?

___________________________________________________________________________

___________________________________________________________________________

Question 2: What is the purpose of the Insert group of UI elements?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 18


Question 3: What is the purpose of the Lock Element button?

___________________________________________________________________________

___________________________________________________________________________

Question 4: What use can the Group button be put to?

___________________________________________________________________________

___________________________________________________________________________

Question 5: How many types of label are there?

___________________________________________________________________________

___________________________________________________________________________

Question 6: How do you undo a mistake you have made?

___________________________________________________________________________

___________________________________________________________________________

End of exercise

© ESRI (UK) Ltd Page 19


2 - What you need to know about
ModelBuilder

Introduction
In the introductory chapter you created a model which created a new feature class and
added a new attribute field into an existing geodatabase. You chose many default options
and as such your model was quite static.

In this section you will learn how to make your model more dynamic by working with model
parameters. You will also investigate the ModelBuilder user interface and the role the
geoprocessing environment settings play in running your model.

Learning objectives
After completing this lesson, you will be able to perform the following tasks:

• Understand geoprocessing environment settings.


• Add parameters and make them dynamic.
• Investigate the ModelBuilder user interface.
• Work with some model properties.
• Understand model symbology.

© ESRI (UK) Ltd Page 20


Geoprocessing Environment Settings
In ArcGIS Pro there are four levels of analysis environment settings:

• Application
• Model
• Tool
• Model process
These levels form a hierarchy in which the application level is highest.

In this hierarchy, environment settings are passed down to the next level. At each level, you
can override the inherited environment settings with a manual setting.

The exception to this hierarchy is at the model level.

If you run the model from the ModelBuilder window, the application environment settings
are passed down.

If you run the model using its tool dialog box (i.e. from within a toolbox), then the tool
environment settings are passed down.

© ESRI (UK) Ltd Page 21


The four levels of the environment setting hierarchy are as follows:

Application-level
Application-level settings are system wide defaults and are saved within the project. They
are applied to any tool when it is executed.

Application level settings can be accessed via the Analysis tab > Environments button.

© ESRI (UK) Ltd Page 22


This will display the Environments dialog box:

Tool settings
Tool settings are applied to a single run of a tool. They temporarily override application-level
settings and are not saved anywhere.

Model settings
These are specified within a model's tool dialog box. Model settings override tool and
application-level settings depending upon where the model is run.

Model process-level
These settings are specified at the model process-level (a process is a tool with its inputs
and outputs) and saved with the model. They override all other settings.

© ESRI (UK) Ltd Page 23


Elements of a model
Your model is made up of elements. These are the geoprocessing tools which perform the
work in your model, different types of variables (ovals representing data and values) and the
connector lines which join the variables and tools together. Groups allow you to group
together elements which you do not wish to see as they are not your focus for some reason.

The different types of model elements are displayed in the diagram below:

Geoprocessing Tools
Geoprocessing tools perform various operations on geographic and tabular data – there are
over 1000 tools in ArcGIS Pro. As with tools run from the toolbox, a geoprocessing tool
which is part of a model must have mandatory arguments assigned either through a
variable, parameter variable or from within the dialog box of the tool element.

Existing custom model and script tools can be added as well as so-called Model-Only tools
which are grouped as Iterators, Utilities and Logical tools. You will investigate these more in
the course.

© ESRI (UK) Ltd Page 24


Variables
Variables hold a value – think of a variable as a storage container. ModelBuilder has a
hierarchy of types of variables and they store different things:

Data variables store either input data or derived data.

Input data can be pathways (workspaces), and datasets such as feature classes, feature
layers and rasters.

Derived Data can be thought of as output data or data created by a tool in the model.
Derived Data can either be New Derived Data – this is a new dataset written to disk – or In /
Out Derived Data which is created when a tool alters its input data; a good example being
the result of the Add Field geoprocessing tool.

Value variables store standard data types such as numbers, strings and booleans and can
either be input values or derived values.

Input Values can be a range of things such as numbers, strings, booleans, spatial references,
linear units and extents.

Derived Values relates to data created by tools and are usually used as the inputs to other
geoprocessing tools, such as the Calculate Value tool.

© ESRI (UK) Ltd Page 25


Connector Lines
The lines that connect variables to tools are known as connectors. Connectors can connect
data or environment settings to tools. There are a couple of specialised connectors too:

Precondition connectors control the order in which a series of processes are run. For
example, a process can be made to run only after a previous process has run.

Feedback connectors allow the output of one process to be the input of a previous process.

Groups
Groups contain elements and they are no more than a visual grouping. They can be
expanded and collapsed to show or hide their contents.

You can select elements and use the Group button to group them together. Elements inside
of the group can be automatically re-arranged by right clicking the group and choosing Auto
Layout.

If necessary, you can create a group inside of a group.

Some things to note:

• Be aware that iterators cannot be added to groups.


• Ungrouping many elements can lead to confusion so use them sparingly.

© ESRI (UK) Ltd Page 26


Adding elements into the model
A model is made up of elements (tools, variables and connectors). Data and tools can be
added to a model by dragging and dropping data, layers, and tools from other windows.

Adding Tools
A tool is added to the canvas in one of three ways:

• Drag geoprocessing tools from the Geoprocessing pane.


• Drag geoprocessing tools from the Catalog pane.
• Add a previously run tool from the Geoprocessing tab of the History pane. This will
add the tool to the model, plus the parameters which were used to run the tool.
When a geoprocessing tool is added to a model, a tool variable and related output variables
are created. Both the tool and the output variables are gray when added, as required
parameters for the tool have not yet been specified.

Once the required tool parameters are specified, the tool variable changes to a yellow
colour, indicating the process is ready to run.

The tool parameters can be populated by either opening the tool dialog and filling in the
parameters or by adding or filling in existing variables associated with a tool.

© ESRI (UK) Ltd Page 27


Adding Variables
Variables can be added in a number of ways.

• Data variables can be added by populating the tool dialog directly. This will create an
input value which references the source data.
• Data variables can be dragged and dropped from the Catalog pane onto the canvas.
• The Insert group contains the Variable button which is used to add variables to the
canvas.
• Variables can be added through a right click on the model canvas, which can be
optionally connected to a tool.
• Right clicking the tool allows for the creation of a variable from the tool’s
parameters.

Once the variable has been created it usually needs to be connected to the tool.

All you need to do is click and hold the left mouse button while you move the cursor to the
tool to make a connection. When the cursor is over the tool decide which tool parameter
the variable should be connected to.

In the example on the next page the Buffer tool has been added. It requires three
mandatory arguments; Input feature class, output feature class and linear unit (buffer
distance or field.

The linear unit variable has been added and is in the process of being connected to the
Buffer tool. When the cursor moves over the tool a list of possible parameters displays; the
one relevant (and mandatory) parameter and a list of optional parameters. The choice to be
made should be the Distance (value or field) parameter.

© ESRI (UK) Ltd Page 28


How do I validate and run my model?
You have created the model and you now wish to test and run your model. Before you can
do this, you need the model to be validated.

Validating the model

Validation is the process of checking that the model is in a ready to run state.

Validation occurs automatically when the data and tools are added and connected.

Validation performs three things:

Checks that the data exists.

The data is valid for use with the tool.

Tool parameters are correctly specified.

As changes are made to the model then it is necessary to re-validate the model; for example
the data changes or tools are modified (for example, pathways are changed), moved,
renamed or deleted. You can manually validate the model by choosing ModelBuilder tab >
Run group > Validate.

The model will need to be validated if all processes have been run inside of ModelBuilder to
set the model back to its ready to run state.

© ESRI (UK) Ltd Page 29


Running your model
You can run your model in one of two ways:

Run the model inside of ModelBuilder

Run the model as a Model Tool from within the Toolbox.

The model can be run inside of ModelBuilder, predominantly for testing. The model, or a
portion of a model, can be run.

Run a single process: Running a single process allows you to run an individual tool in the
model. To achieve this just select a tool, right-click, and select Run.

The model will run all processes up to the selected tool.

Run the entire model: When you click ModelBuilder tab > Run group > Run on the ribbon,
all ready to run tools execute in sequence. If some tools have already been run, they are not
re-executed; the model will begin executing from the first tool that has not yet been run.
Derived datasets will be created and stored in the specified workspace for the tool which
allows you to inspect them. This is handy in the testing process.

© ESRI (UK) Ltd Page 30


Accepting user input into your model
As well as running a model directly from within ModelBuilder, it can also be run as a model
tool. Model tools can be run just like any other geoprocessing tool from the Geoprocessing
pane; or used in other models and Python scripts.

A static model
If the model is in its ready to run state then the required data names and locations are
hardcoded: the model is said to be static. When a model is opened in the Geoprocessing
pane, the tool dialog box will display no parameters.

When the model is run it uses its internal hard-coded values and any output datasets will
not be added to the active map.

Make your model dynamic


Your model can receive user input when it is a model tool by making the variables into
model parameters. If an output variable is specified as a parameter then it will be added to
the active map automatically once the model tool has finished processing.

In ModelBuilder, right-click any variable and select Parameter.

© ESRI (UK) Ltd Page 31


When a variable is made into a parameter, a letter P appears beside the variable in the
model.

When the model tool dialog is opened via the Geoprocessing pane then the parameter is
displayed and ready to receive user input.

 NOTE: Any changes you make to the model must be saved within the model
using the Save button on the ModelBuilder ribbon.

As you can see the name of the variable is used as the model tool parameter label. You can
rename a model parameter by renaming the model variable in ModelBuilder. Right-click the
variable, select Rename, and enter the new name.

The renamed parameter is displayed on the model tool dialog along with its default value.

© ESRI (UK) Ltd Page 32


Model properties
Model properties determine how the model is named, how it is found in the geoprocessing
framework and how parameters behave.

The properties dialog box is opened from the ModelBuilder ribbon.

Or by right clicking the model in the Catalog pane and choose Properties.

There are two tabs: General and Parameters.

General
General properties determine the internal (Name) and visible (Label) names of the model.

A password can be set which provides a degree of protection against those who might wish
to alter your model.

© ESRI (UK) Ltd Page 33


Parameters
The Parameters page displays a table of all variables that have been marked as model
parameters. The table includes properties for each parameter. Some of these properties can
be modified, while some are read-only.

The Label, Data Type and Direction are read only – the other parameter properties can be
modified as long as they are not required by the associated geoprocessing tool.

Tool parameters have a Type which can be required or optional. The designation for optional
or required parameters happens automatically based on how the parameter is used in the
model. The model parameter that ModelBuilder designates as optional can be changed to
required for the model tool, but a required tool parameter cannot be set to optional.

A parameter can belong to a category. Parameters in a category are displayed in a drop-


down section:

Parameter filters are used to limit or restrict the input values or data that can be specified
for a model tool parameter. For example, a Value List filter requires that only values from a
list can be specified for the parameter. The model cannot be executed until a valid value is
entered.

© ESRI (UK) Ltd Page 34


The following filters are available.

Value list A list of valid keywords. You can set a value list filter for
string and numeric model parameters.
Range: Specify a minimum and maximum numeric value. The
range is inclusive, meaning both the minimum and
maximum are valid choices.
Feature Type A list of allowable feature shape types, such as point,
multipoint, polyline, polygon, and multipatch.
File A list of valid file extensions such as txt or gpx.
Field A list of allowable field types, including short, long, single,
double, test, date, OID, geometry, BLOB, raster, GUID,
global ID, and XML.
Workspace A list of valid workspaces, including file system, local
geodatabase, and enterprise geodatabase.

The Feature Type filter is displayed below:

Dependency allows for one parameter to be dependent upon another. An example of this
would be to have a field info parameter be dependent upon an input feature class or table
so when the dataset is updated the field info object is updated with a new list of attribute
fields.

The Symbology of an output parameter can be used to specify how the model outputs
should be symbolised when added to a map. The Symbology option achieves this by
specifying a pathway to a layer (.lyrx) file.

The order of the parameters on the model tool dialog can be controlled by dragging and
dropping the parameters to the desired order in the Parameters page.

© ESRI (UK) Ltd Page 35


Exercise 2: Basic processing techniques in
ModelBuilder
Estimated Time: 30 Minutes

In this exercise you will work with an existing model to change the way it behaves.

You have been given a model which is static; the input variables are hardcoded. This means
that every time the model is run the same output is created. You have been asked to amend
the model to allow the end user to make choices as to the inputs which the model can
receive. You have also been asked to annotate the model as you may want to use the model
as a training aid for future models.

In this exercise, you will:

• Investigate an existing model.


• Understand how derived data is dealt with depending upon whether the model is
run as a model tool or within ModelBuilder.
• Make the model dynamic by adding parameters.
• Optional step of changing the model properties:
Label the model.
Re-order the dialog parameters.
Apply output symbology using a layer file.
If you complete all of the steps, plus the optional steps then your model will look like the
following:

© ESRI (UK) Ltd Page 36


Step 1: Inspect an existing model
In this step you are going to load a project which contains an existing model. You will
investigate the model and understand what it is currently doing.

a. Start ArcGIS Pro and load the following project:

C:\EsriTraining\MBOP\ModelBuilderBasics\BufferAndClip\BufferAndClip.aprx

The project opens to display a map displaying central Bristol. It contains two feature layers;
Major Bristol Roads and Planning Applications, as well as the GB Light Grey basemap.

© ESRI (UK) Ltd Page 37


A book mark has also been set, just in case you lose your way.

A folder to C:\EsriTraining\MBOP has also been created which provides access to the
contents of that folder.

You will first investigate a useful geoprocessing setting.

b. Click the Project tab > Options.

c. Locate the Geoprocessing section.

Question 1: What is the current value for ‘Allow geoprocessing tools to overwrite existing
datasets’?

___________________________________________________________________________

___________________________________________________________________________

The checkbox is ticked which means that any existing datasets can be overwritten by
geoprocessing processes such as running a model or a geoprocessing tool.

d. Cancel the dialog and return back to the map.

e. In the Catalog pane expand Toolboxes.

Inside is a toolbox called BufferandClip and inside that is a model called Buffer and Clip.

You will now investigate the model.

f. Right click the model and choose Edit.

© ESRI (UK) Ltd Page 38


The model is displayed.

Question 2: What does the model do?

___________________________________________________________________________

___________________________________________________________________________

___________________________________________________________________________

Question 3: What is the distance to which the Bristol roads are being buffered to?

___________________________________________________________________________

___________________________________________________________________________

Question 4: On the Clip tool what is the name of the Input Features and what do they
represent?

___________________________________________________________________________

© ESRI (UK) Ltd Page 39


___________________________________________________________________________

Question 5: What is the name of the clipped output dataset and which location is it written
to?

___________________________________________________________________________

___________________________________________________________________________

Now that you understand what the model does you are now ready to investigate the
different ways in which the model can be run.

Step 2: Running the model


In this step you will have a look at some of the differences which you will notice when you
run a model directly within ModelBuilder or as a model tool.

First of all you will make a selection in the Major Roads layer as you want to use just those
selected features as input into your model.

a. Open the map.

b. Use the Select by Attributes tool to construct a query which selects those Major
Bristol Roads called Park Street.

 HINT: Investigate the attribute table to identify the field name containing the names of the
roads.

Once the tool has run you should have 9 features selected.

© ESRI (UK) Ltd Page 40


These selected features will be used as the input into the model.

c. Return back to the Buffer and Clip model tab.

d. Press the Validate button.

This makes sure that all data references are available and sets your model state to “ready to
run”.

e. Run the model.

As the model runs the geoprocessing dialog is displayed which contains the progress
messages.

© ESRI (UK) Ltd Page 41


After a few moments the model will finish processing – notice the “Succeeded at….”
message.

Notice the location where the output dataset is written to. This is the same location which
you noted as the answer to Question 5

f. Close the geoprocessing dialog.

g. In the Catalog tab locate the Databases icon and expand it.

There are two geodatabases:

The BufferAndClip geodatabase is the default geodatabase for the project where the output
of the model is written to.

h. Expand the BufferAndClip geodatabase.

Question 6: How many feature classes are in the geodatabase?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 42


Question 7: How was the st57_Road_Line_Buffer feature class created?

___________________________________________________________________________

___________________________________________________________________________

The st57_Road_Line_Buffer feature class is created by the Buffer tool. It is classed as a


derived dataset as it is created by a tool. As it is then used as an input into the Clip tool you
can think of this dataset as an intermediate dataset.

i. Add both feature classes into the map and zoom to the extent of the buffer layer.

You can see that there are multiple buffers as there are multiple street selected.

A couple of things to note:

When running a model inside ModelBuilder all intermediate datasets are created and kept in
the workspace. This is useful for testing and validating your model logic.

© ESRI (UK) Ltd Page 43


The datasets are not added automatically to the map.

j. In the BufferAndClip geodatabase delete the two feature classes.

k. Press the OK button to confirm that the feature classes are to be deleted.

Now you will run the model from the toolbox.

l. Expand Toolboxes > BufferAndClip to display the Buffer and Clip model.

m. Double click the model to display the dialog.

Notice that the dialog has no opportunity to enter any information or data into it. This is
because no variables have been exposed to allow user input.

n. Run the tool.

The geoprocessing progress is displayed at the bottom of the dialog.

You will be informed once the model has finished processing.

Notice again that no datasets are added to the map. You will fix this in the next step.

© ESRI (UK) Ltd Page 44


o. Once again in the Catalog pane, expand the Databases icon and display the
BufferAndClip geodatabase.

p. Refresh the geodatabase.

Question 8: How many feature classes are in the geodatabase?

___________________________________________________________________________

___________________________________________________________________________

As you can see only the output feature class is stored in the geodatabase. The intermediate
buffer dataset has not been created this time.

When you run a model from the toolbox only the output dataset is created – no intermediate
datasets are written to the workspace at all. This is an important distinction between the
two environments – run the model from ModelBuilder when you are testing the model.

Step 3: Add parameters to the model


When you ran the model via the toolbox you could not interact with the model – you could
not make any choices to affect the processing of the model. Also you had to go and look for
the data to manually add the results of the processing to the map.

You will change this in this step.

The key to making a model dynamic – that is to allow user input – is to make the variables
model parameters.

Let’s make the model add the output to the map automatically.

a. Open the Buffer and Clip ModelBuilder tab

© ESRI (UK) Ltd Page 45


b. Locate the ClippedPlanningApps variable and choose Parameter.

You have made the ClippedPlanningApps variable a model parameter.

This is a requirement to add the output dataset to the display automatically.

If you make any change to the model and you want the toolbox to pick up the changes then
you must save the model.

c. Save your model.

 NOTE: You MUST save your changes in the model if you want to see the
effect of those changes when you run the model in the toolbox.

 Saving the model is a completely separate process to saving the project

d. Double click the model in the toolbox.

Notice this time that the ClippedPlanningApps parameter is displayed on the dialog:

© ESRI (UK) Ltd Page 46


You will rename this in a moment.

Notice the yellow warning triangle ? This is displayed because there is already a dataset of
that name in the output geodatabase. You are allowed to overwrite it because the ‘Allow
geoprocessing tools to overwrite existing datasets’ checkbox is ticked. If it wasn’t ticked then
there would be an error icon displayed.

e. Return to the map and run the model.

Once processing has finished the ClippedPlanningApps dataset is automatically added to the
map:

You will now rename the ClippedPlanningApps variable.

f. Close the Geoprocessing pane.

g. In ModelBuilder right click the ClippedPlanningApps variable and choose Rename.

h. In the box type in Output Dataset Name and save the model.

© ESRI (UK) Ltd Page 47


The value in the variable is the label for the parameter on the model tool dialog box.

i. To confirm this, double click the Buffer and Clip tool in the toolbox.

You will do one more thing in this step and that is allow the user to choose the buffer
distance and units via the tool dialog.

j. In ModelBuilder double click the Buffer tool to display the tool dialog.

Notice that the Distance [value or field] parameter is filled in already. This is a mandatory
parameter which the tool needs for it to run.

k. Remove the value 75 and press the OK button on the tool dialog.

When you do this then many of elements turn grey. This indicates that the model is no longer
in a fit state to run.

© ESRI (UK) Ltd Page 48


This is not surprising as you have just removed a mandatory argument in the Buffer tool. This
effect cascades its way through the model.

You will now add the Distance variable as a parameter.

l. Right click the Buffer tool and choose Create Variable > From Parameter > Distance
[value or field].

The Distance [value or field] variable is added.

m. Move it to a new location.

n. Make it a model parameter (HINT Right click > Parameter).

o. Add a default value of 100 metres by double clicking the parameter.

© ESRI (UK) Ltd Page 49


When this (required) default value is added, the model changes into its ready to run state.

p. Rename the Distance [value or field] variable to Enter Buffer Distance.

q. Save and validate the model.

Your model should look similar to the one displayed below:

r. Close the Geoprocessing pane.

s. Double click the Buffer and Clip tool in the toolbox.

Notice the changes you have made are now reflected on the dialog:

© ESRI (UK) Ltd Page 50


t. Run the tool!

The model performs its processing as you might expect.

That is the end of the mandatory part of the exercise. If you wish you can go to the optional
step on the next page or you can go and get a cup of tea or have a smoke.

Optional Step: Alter model properties


In this optional step you will do the following:

• Add some labelling to your model.


• Associate a layer file which will determine the output symbology of your model.
• Alter the order of the parameters on the tool dialog.
First, you will add a title to your model.

a. On the ModelBuilder ribbon click the Label button on the Insert group.

A Label will be added to the canvas.

b. Move it to centre top of the canvas.

 HINT: You will need to click the Select tool in order to move the Label
element.

© ESRI (UK) Ltd Page 51


c. Using your skills add the following text (or something similar to the label):

Geoprocessing model which will take a selection of the Bristol Roads layer and perform a
proximity analysis to identify the planning applications within a specified distance

 HINT: If you need to add a newline to your title you can do by choosing <shift> + <Return> at
the same time.

d. Set the size of the text to be 14 using the tools in the Text group on the ModelBuilder
ribbon and change the text colour to red

e. Right click the derived dataset and choose Create Label.

f. Amend the text in the label to display:

Intermediate dataset (Not created as part of final output)

g. Set the size to 12 and resize the text box to display the text.

When a label is created via the element then when the element is moved the label moves in
conjunction with it.

Your model should look similar to the one displayed below:

© ESRI (UK) Ltd Page 52


Next you will do alter the order of the parameters on the dialog. It is traditional to have the
Output Dataset Name parameter underneath the parameters, and currently it is above the
Enter Buffer Distance parameter.

h. In the ModelBuilder ribbon click the Properties button.

This will display the Tool Properties: Model dialog box.

i. Click the Parameters entry.

This display the properties of the variable parameters in the model. These are the
parameters which are displayed on the dialog.

© ESRI (UK) Ltd Page 53


Notice the ordering of the parameters.

This determines the ordering on the dialog.

j. Click the 1 in the gutter and drag it above the 0.

In the diagram below the parameter is in the process of being moved.

You will do one more thing while the dialog box is open. You will associate a layer file to the
Output Dataset parameter. This means that anytime the model runs the output will always
have a set of standard symbols.

k. In the Output Dataset parameter scroll along until the Symbology field is located.

l. Click inside this grid square (as indicated in the above picture).

m. Click the browse button, browse to the following location


C:\EsriTraining\MBOP\ModelBuilderBasics and add the ClippedApps.lyrx layer file.

n. Press the OK button on the properties dialog, validate and save your model.

Let’s see how the changes affect the dialog and the output symbology.

o. Double click the model tool to display the dialog.

© ESRI (UK) Ltd Page 54


The parameters have been re-ordered!

p. Run the tool with the default values in the dialog.

The output dataset has the symbology properties of the layer file!

End of exercise

© ESRI (UK) Ltd Page 55


3 - Batch processing using
ModelBuilder

Introduction
Batch processing is the process of repeating a workflow based upon some sort of condition,
such as running a model exactly three times, or apply a workflow to all feature classes in a
particular geodatabase.

The key to batch processing in ModelBuilder is using the iteration tools. Iteration is very
important because automating repetitive tasks reduces the time and effort required to
perform the tasks. With iteration in ModelBuilder, a process can be executed over and over
using different settings or data in each iteration.

In this section you will investigate and understand the different types of iterator and how to
use them.

ModelBuilder also provides flexibility in iteration, as an entire model or a single tool or


process can be executed repeatedly.

© ESRI (UK) Ltd Page 56


Learning objectives
After completing this lesson, you will be able to perform the following task:

• Batch Processing in ModelBuilder.


• Iterating over different datasets in workspaces and files.
• Iterate over the contents of a table or feature class.
• Iterate over a list of layers or fields.
• Looping over datasets.
• Using in-line variable substitution.
• Using the memory keyword.

Activity: Investigate model iteration


Before you look at the iterators in detail you will do some investigative work of your own.

Browse to the following location either in the installed ArcGIS Pro help or online at
https://pro.arcgis.com/en/pro-app/latest/help/main/welcome-to-the-arcgis-pro-app-
help.htm Analysis and Geoprocessing > Geoprocessing > ModelBuilder > Advanced
Techniques > Iterators

Read the page and answer the following questions:

Question 1: How many model iterators are there?

___________________________________________________________________________

___________________________________________________________________________

Question 2: How many iterators can be included in each model?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 57


Question 3: How might you provide a unique name to the output of a tool which is affected
by an iterator?

___________________________________________________________________________

___________________________________________________________________________

Question 4: What iterator would you choose if you wanted to run a workflow a specific
number of times?

___________________________________________________________________________

___________________________________________________________________________

Question 5: How would you iterate over each row or feature in a table or feature class?

___________________________________________________________________________

___________________________________________________________________________

Question 6: How do you add an iterator to your model?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 58


Iterating over the contents of workspaces
There are a number of iterators which process the contents of a workspace – a workspace
being a geodatabase of some description or a folder containing file-based datasets (such as
a shapefile, raster datasets, word documents etc).

ArcGIS Pro supports the following folder / workspace iterators:

Iterate Feature Classes Iterate through each feature class in a workspace.


Iterate Rasters Iterate through each raster in a workspace.
Iterate Tables Iterate through each table in a workspace.
Iterate Datasets Iterate through datasets such as a Feature Dataset, or a CAD
file dataset.
Iterate Workspaces Iterates through each workspace, such as a folder or a
geodatabase.
Iterate Files Iterates through each file in a folder such as a docx, txt, png
etc.

Each iterator has many arguments such as a wildcard, or input workspace. Many iterators
produce two outputs such as Name and the output object which the iterator is processing.

Examples are shown below and on the next page:

© ESRI (UK) Ltd Page 59


Iterate Rasters has one mandatory argument, which is the workspace, and produces two
outputs:

• Name: Name of the raster, currently being processed, as a string.


• Raster: Current raster object which is being processed by the iterator.

Iterate Files processes all the files in a directory. The required argument is a folder, and
there are three optional arguments (wildcard, File type and recursive) and it produces two
outputs; Name and File.

Notice how inline variable substitution is utilised in the iterators.

© ESRI (UK) Ltd Page 60


Looping using iterators
ModelBuilder provides two iterators which allow you to process the model either a set
number of times or while a particular condition is (Boolean) true. These iterators are:

• For
• While

For iterator
The For iterator uses a start number, an end number and an optional step number. In the
example below the For iterator is used to buffer the features in an input feature class based
upon the current value. The first buffer distance (From Value) is 500 units, the next one is a
distance incremented by 500 units (i.e. 1000 units, and so on until the To Value value has
been processed.

While iterator
A While iterator will process a model’s workflow while a condition is Boolean true. An
example of this might be to continue processing a model to create a service area while the
population count in the service area is less than 25,000.

The While iterator allows for the checking of a condition downstream of the workflow.

© ESRI (UK) Ltd Page 61


Processing selected features
A dataset is a feature class or a table – in this context it does not relate to a Feature Dataset.

There are two iterators which will process selected records in datasets:

Iterate Feature Selection Iterates over features in a feature class.


Iterate Row Selection Iterates over rows in a table.

Iterate Feature Selection


The Feature Selection iterator acts on selected records. It calls the Make Feature Layer
geoprocessing tool to make a selection and it creates two outputs: Selected Features and
Value.

Selected Features refers to the feature layer that is produced while Value refers to attribute
information based upon the fields in the Group By Fields argument.

In the example below the Input Features are hurricane tracks, grouped by the NAME field. A
feature layer is made based upon each group of features and applied against a landuse
raster to work out statistics of land cover based upon the track of the hurricane.

© ESRI (UK) Ltd Page 62


Iterate Row Selection
The Iterate Row Selection iterator is very similar to the Iterate Feature Selection – the
difference being that it works on a table and not a feature class.

The similarities between the two iterators can be seen via the diagram below:

Both tools provide the possibility of inline variable substitution being used later on in the
model.

© ESRI (UK) Ltd Page 63


Iterate over layers and values
You can iterate the contents of a map, or the fields and values contained in an attribute
table using these five iterators.

Iterate Layers List all the layers in a map


Iterate Fields Iterates all the fields from a table
Iterate Field Values Iterates over each value in a field
Iterate Multivalue Iterates over a list of values
Iterate Time Iterates over time in a date field

Iterate Layers
In the image below, the Input Map variable shows a list of layers to be projected. The
iteration is restricted to only iterate over point feature layers in the map. The output of the
Iterate Layers tool is tested against a defined coordinate system using the If Coordinate
System Is tool. If the coordinate system of a layer does not match the defined coordinate
system, the value of the output False variable changes to true and the connected Project
tool runs to project the incoming layer to a specified coordinate system.

© ESRI (UK) Ltd Page 64


Iterate Fields
In the image below, the model uses the Calculate Field tool to convert the null values in
multiple fields to zeros.

The Incidents feature layer variable has unique fields with count for number of incidents by
date. Some of the fields have missing values stored as nulls. In this case, the Iterate Fields
tool is used to filter the days based on a wild card and a subset of filtered field list. Each field
is then passed to the expression of the Select Layer By Attribute tool, and the selected
records are then passed to the Calculate Field tool.

© ESRI (UK) Ltd Page 65


Iterate Field Values
If you wish to get access to the contents of an attribute field, then the Iterate Field Values
iterator will be of interest to you.

The output of the tool is a variable named Value and contains the value of the field that is
being processed. This variable can be used in for inline variable substitution (%Value%).

The Data Type parameter specifies the data type of the output variable. The default data
type is string, but depending on how the output will be used in the model, different data
types may be specified. For example, if your field contains the path to a text file, you can set
the Data Type to Text File and use the output variable as input to a tool that accepts a text
file such as the Make XY Event Layer tool.

© ESRI (UK) Ltd Page 66


Iterate Multivalue
A useful iterator for looping over inputs as chosen by a user is the Iterate Multivalue
iterator. The inputs must be of the same type, for example, raster datasets, feature classes,
text files etc.

The nice thing about this tool is that the tool accepts input from different workspaces based
upon the choice of the user.

In the above example the Iterate Multivalue iterator has one output called Value which is a
string representing the feature class name that is currently being processed.

The recommended way to create a multivalue input is to create a stand alone variable by
clicking Insert > Variable.

In the Variable Data Type dialog box, choose the data type and check Multiple Values.

Connect the variable to the Input Values parameter of the iterator.

© ESRI (UK) Ltd Page 67


Iterate Time
The iterator filters rows that fall in different time intervals and time extents. For example,
you can iterate over hourly data for the full temporal extent of the data or a subset of it. The
tool creates different temporal slices that can used as input in other tools.

In the example above, the input table has precipitation data from 1981 to 2020 excluding
the dry days. The Iterate Time tool divides the input data into one-month temporal slices
using the Date field. From the selected rows for each month, the average precipitation and
the count of rainy days are calculated using the Summary Statistics tool. The Calculate Field
tool is used to add the formatted Start Time value of each iteration in the summarized table
using inline variable substitution. The summary table for each month is appended back to
generate a single table using the Append tool.

© ESRI (UK) Ltd Page 68


Using inline variable substitution
An important concept which iterators take advantage of is inline variable substitution as this
provides a unique output to your iterator.

Inline variable substitution uses a pair of % signs either side of a variable name:

%
A_Variable_Name%

If a variable or parameter called inFC has a value of “ConsArea” then a pathway can be
constructed to take advantage of the in-line variable:

The pathway would look like the following:

..\MyProject.gdb\bristbus_ConsArea

Inline variable substitution can be used in the following circumstances:

• Model variables (as presented above).


• System variables: ModelBuilder allows the use of a system variable n that is used in
iteration workflows when %n% is the iteration number in the model.
The first number in the system variable n is 0. This is a handy mechanism to use when using
a For iterator in conjunction with a feedback operator:

© ESRI (UK) Ltd Page 69


Using the memory keyword
The concept of the workspace is well known in geoprocessing. It is an area where input data
is read from and output datasets are written to. Traditionally the workspace is either a
folder or a geodatabase of some description.

Type of geoprocessing workspaces


Before discussing the memory workspace it is useful to understand the other workspace
options which are available and how they relate to ModelBuilder. These are environment
settings options and can affect the running of tools which support them.

Current Workspace: This is used to specify the default location for geoprocessing tool inputs
and outputs when running a tool in ModelBuilder. The default location is the project’s
default geodatabase.

Scratch Workspace: Tools that honour the scratch workspace use the specified location as
the default location for output datasets. Its primary purpose is for use in ModelBuilder and
Python. It defaults to the project’s default geodatabase.

One thing to note –if the Scratch Workspace is set then this location will be used in a model
tool. If the Scratch Workspace is not set the then Current Workspace will be used.

The Scratch Folder and Scratch Geodatabase environment settings should be used by a
Python script or a model if the resource is going to be published as a geoprocessing service
as the workspace is guaranteed to exist.

The memory workspace


So… what is the memory workspace? It relates to system memory (also known as RAM)
where output feature classes, tables and raster datasets can be written to. Subtypes and
domains are also supported.

As datasets are written to RAM it must be noted that larger datasets may impact on
processing performance as the machine may start to run low on memory.

As the dataset is not been written to a disk-based location it is significantly faster when used
for processing.

Datasets written to RAM are also known as “in-memory layers”.

© ESRI (UK) Ltd Page 70


It is straightforward to implement in your geoprocessing tool output:
memory\Wards_Buffer

Data written to the memory workspace is temporary in nature and will be deleted once the
application closes or using the Delete GP tool. It is a good idea to use memory workspaces
when working with so-called intermediate datasets and as soon as possible, free up system
memory resources.

© ESRI (UK) Ltd Page 71


Sharing your model
Once the model has been created you will now want to distribute it to your customers – you
will want to share the model.

The model is contained inside of a toolbox (.atbx) file if it is stored in a folder. The .atbx file
and any associated data that the model might be dependent upon can be zipped up and
distributed.

A popular way to share any analysis is by creating a geoprocessing package. A package


contains any tools (models or scripts) and data required to run the task. They can be used to
share your analysis within your organisation or to a broader audience of ArcGIS users
through ArcGIS Online. Colleagues who use the geoprocessing package will be able to open
and run it with the data in the package, or they can add their own data through the tool
parameters.

© ESRI (UK) Ltd Page 72


A geoprocessing package is first of all created by running the model successfully - it has to
have a geoprocessing history item. Only then can it be shared.

Notice that a geoprocessing package can be shared via the History pane.

A geoprocessing package can also be created by clicking the Share tab > Package group >
Geoprocessing Package.

You can decide what properties and content the package will include via the Geoprocessing
Package pane.

The package can be saved to either disk as a gprx file or to your Portal (ArcGIS Online or
ArcGIS Enterprise).

Provide a name and, if saving the package to a file, the location for your new package on
disk.

© ESRI (UK) Ltd Page 73


There are two mandatory parameters which must be filled in:

Summary:Provide a brief description as to what the package does and what data or files are
associated with it.

Tags: Tags need to be included as it is through tags that your colleagues and interested
parties can find your geoprocessing package within your portal.

Use the Include Enterprise and UNC Path Data option if you want to extract data from an
enterprise geodatabase, or UNC path data into a file geodatabase. If this option is not
checked, map layers continue to reference enterprise geodatabase data and UNC path data.

If you're uploading your package to an online account, specify how it will be shared:

• My Content
• My Organisation
• Groups
• Everyone—This option makes your content public. Anyone can access and see it.

© ESRI (UK) Ltd Page 74


The Tools tab allows for multiple tasks to be added into a single package by selecting
additional history items. All tasks added into the package will be extracted and available for
use when the package is extracted back into ArcGIS Pro.

The Attachments tab allows you to include other content, such as detailed documentation,
reports, and graphs.

For the package to be created successfully it must be analysed to check for any errors or
issues. All errors must be resolved. If any issues are discovered, they appear on the
Messages tab. Right-click each message to get more information, read the help for the error
or warning, and access suggested fixes.

Finally, the package can be created by clicking the Package button.

© ESRI (UK) Ltd Page 75


Exercise 3: Iteration on a raster dataset
Estimated Time: 40 Minutes

In this exercise you will perform some processing on a raster dataset to create a resampled
version of the raster dataset for viewing at different scales by using the For iterator.

In this exercise you will:

• Create a custom toolbox, build a model and set its properties.


• Identify a workflow for resampling a raster and create contours.
• Add a For iterator to process the raster.
• Implement inline variable substitution to create a unique output.
• Optional: Use the memory workspace for any intermediate datasets.
The finished model will look like the following:

© ESRI (UK) Ltd Page 76


Step 1: Create the model
In this first step you will create the model and set some model properties.

a. Start ArcGIS Pro and create a new map-based project called SoCal and store it in the
following location:

C:\EsriTraining\MBOP\WorkingWithIterators

b. Add a folder connection to the following location:

C:\EsriTraining\MBOP\WorkingWithIterators

Inside the ..\WorkingWithIterators folder is a Data folder which contains a file geodatabase
called Vineyard.

c. Expand the file geodatabase and add the Elevation dataset into the Map window.

Question 1: What units is the raster measured in?

___________________________________________________________________________

___________________________________________________________________________

Question 2: What is the resolution of the Elevation raster?

___________________________________________________________________________

___________________________________________________________________________

Now you will create a new toolbox and the model.

d. In the Catalog pane expand Toolboxes.

Inside is the Project toolbox called SoCal.atbx.

e. Create a new toolbox in the Toolboxes folder called IteratorTools.

© ESRI (UK) Ltd Page 77


g. Set the properties of the toolbox as follows:

Name: IteratorTools

Label: Iterator Tools

Alias: IteratorTools

Description: Toolbox containing tools which perform iterations on datasets.

It is always best practice to fill in the Label, Alias and Description.

The Alias is important as it allows for the unique identification of tools within the
geoprocessing framework, and it is part of the geoprocessing tool naming convention within
the Python window.

Now you will create a model and set its properties.

h. Create a new model by right clicking the IteratorTools toolbox > New > Model.

A new model canvas is created.

i. Display the model properties dialog box and fill in the dialog box with the following
information:

Name: ResampleRaster
Label: Resample Raster

j. Save the model.

When the model is saved the model in the toolbox is updated with the changes you just
made in the Tool Properties dialog box.

© ESRI (UK) Ltd Page 78


You are now ready to build the model.

Step 2: Build the basic model


In this step you are going to build a static model which will resample a DEM raster dataset
and create a contour dataset from it.

At the end of the step your model should look like the following:

Let’s add the tools to the model.

a. In the Geoprocessing pane search for the Resample tool and drag it onto the canvas.

b. Repeat the process for the Contour tool. Choose the Spatial Analyst version of the
tool.

 There is no difference between the Contour tool found in the Spatial Analyst
extension and the equivalent tool found in the 3D Analyst extension. This is
one of a number of surface-based tools which are common between both
extensions.

c. Double click the Resample tool and in the tool’s dialog box fill in the parameters as
follows:

Input Raster: Elevation


Output Raster Dataset: <Default location>\ElevResample
o Output Cell Size X & Y: 40
Resampling Technique: Nearest

© ESRI (UK) Ltd Page 79


The dialog should look like the following:

d. Press the OK button on the dialog.

The Resample tool process is coloured to indicate that the process is ready to run:

The output of the Resample tool is going to be used as the input dataset for the Contour tool.

e. Connect the ElevResample variable to the Contour tool and choose Input Raster as
the parameter.

Notice that once the ElevResample tool is connected to the Contour tool, the Contour tool is
not “ready to run”.

Question 3: Why is the tool not “ready to run”?

___________________________________________________________________________

___________________________________________________________________________

Question 4: What required parameter does the tool need to be populated with?

___________________________________________________________________________

© ESRI (UK) Ltd Page 80


___________________________________________________________________________

Once the tool has been populated with the Contour interval parameter the Contour process
is then “ready to run”.

f. Add a value of 50 for the Contour interval.

Your model should look like the following:

Your model is ready to test.

g. Save, validate and run the model.

h. Once the model has run, add the finished contour dataset and the intermediate
resampled DEM to the map.

© ESRI (UK) Ltd Page 81


i. Identify the contour polylines and check that the interval is every 50 metres.

j. Zoom into the raster dataset and check that the ElevResample dataset has been
resampled and the resolution of the raster is 40 metres.

 You can inspect the ElevSample properties to determine the resolution. You can
investigate visually if the raster has been resampled by highlighting the ElevResample
dataset in the Contents pane and then in the ribbon go to Raster Layer > Compare >
Swipe.

k. Remove the two output datasets from the Contents pane and delete them from the
project’s SoCal default geodatabase

You have created and tested your model. You are now ready to add the For iterator which
will allow you to process the model based on a number of resample cell sizes.

Step 3: Add the For iterator


You are going to resample the raster DEM to a number of resolutions. What resolution
should your raster be viewed at for a given scale?

An Esri blog article discusses how to work out what these scales are based upon the raster
resolution:

https://www.esri.com/arcgis-blog/products/product/imagery/on-map-scale-and-raster-
resolution/

It is worth reading the article!

The current cell size is roughly 28 metres – let’s round it up to a more workable number of 30
metres.

A formula in the blog article is available which will calculate the scale at which the raster
dataset should be viewed at if the resolution is 30 metres:

Map Scale = Raster resolution (in meters) * 2 * 1000

Based upon the formula a scale of 1:60000 is the optimum scale to view this raster dataset.

a. Set the map scale to be 1:60000.

© ESRI (UK) Ltd Page 82


You will create a series of resampled rasters based upon the above formula which will be
based upon several scales:

Resolution (metres) Map Scale


30 60,000
45 90,000
60 120,000
75 150,000
90 180,000
You will use a For iterator to create a series of resampled datasets which can then be viewed
at relevant scales.

b. In the Resample Raster model add the For iterator and move it above the existing
processes.

c. Double click the For iterator.

d. In the For dialog box type a value of 30 for From Value (this is the starting value); 90
for To Value (this is the end value) and 15 for By Value (this is the value which the
From Value will be incremented by for each iteration of the model).

The dialog should look like the following:

© ESRI (UK) Ltd Page 83


e. Press the OK button.

Question 5: What is the purpose of the For iterator’s Value variable?

___________________________________________________________________________

___________________________________________________________________________

In this model the Value variable relates to the output (resampling) cell size.

You will try and connect the For iterator’s Value variable to the Output Cell Size for the
Resample tool.

f. Try to connect the Value to the Resample tool.

Notice that there is no Output Cell Size option. This means you can not connect the For
iterator directly to the Resample tool.

So how are you going to add the current iterated value into the Resample tool?

One thing you can do is use the Calculate Value tool. This is a tool we will cover later – it is
an extremely powerful tool. It receives an input, performs a calculation or transforms the
data into a chosen output which can then be passed into another process.

g. On the ModelBuilder tab go to Insert group > Utilities > Calculate Value.

This adds the Calculate Value tool to the model.

h. Move the Calculate Value tool to the right of the For iterator.

© ESRI (UK) Ltd Page 84


i. Connect the Value variable to the Calculate Value tool via the Expression parameter.

j. Double click the Calculate Value tool to display the dialog box.

The Calculate Value tool receives a value in the Expression parameter; it is capable of then
performing a calculation in the Code Block area before passing the result out via the Data
Type parameter.

Question 6: What is the current Data Type?

___________________________________________________________________________

___________________________________________________________________________

k. Change the Data Type from Variant to Cell Size XY and press the OK button.

This is the required data type for the Resample tool!

l. Connect the Output Value of the Calculate Value tool to the Resample tool.

 Notice that the Output Cell Size parameter is now available as an


acceptable input into the Resample tool.

© ESRI (UK) Ltd Page 85


m. Choose the Output Cell Size option.

n. Validate, save and run the model.

As the tool runs notice that the Value increments by values of 15 from 30, 45 all the way to
90.

o. Once the model has finished close the geoprocessing progress dialog, refresh the
project’s default geodatabase and inspect its contents.

Notice that there are only 2 datasets:

Question 7: Based upon the values you entered into the iterator, how many output datasets
would you expect to see?

___________________________________________________________________________

___________________________________________________________________________

You will correct this is in the next step.

© ESRI (UK) Ltd Page 86


Step 4: Add inline variable to create unique output datasets
In the previous step your model iterated over a process five times, but only one output was
created instead of the expected five. What happened was that the output was created by the
first iteration of the model but was then overwritten by the next iteration. This continued
until the last iteration which had a value of 90 and this is the final resampled raster which is
present along with the contour dataset produced from it. You can check this by looking at
the resolution of the raster.

So how can five separate contour datasets be produced marking one for each iteration?

The answer is to use in-line variable substitution.

You know currently that the datasets will be overwritten with each iteration – this is what
you want for the intermediate resampled raster dataset, but you want the final dataset to be
unique. This is where you will apply the in-line variable substitution.

The current value processed by the iteration is held in the Value variable. This variable can be
surrounded by percentage signs (%Value%) and added to an output dataset to create the
unique output for that iteration.

a. First of all delete the datasets in the project’s default geodatabase.

b. Open the Contour_ElevRes variable (the output of the Contour tool).

c. Add the following after the name of the dataset: _%Value%

This will add an ‘underscore’ to the name of the dataset followed by the current value stored
in the Value variable.

It should look like the following:

d. Press the OK button to close the dialog.

The label of the output dataset has now been updated:

© ESRI (UK) Ltd Page 87


You are now ready to run the model.

e. As before, validate, save and run the model.

 Make sure the project’s geodatabase (SoCal.gdb) is empty.

f. Once it has run investigate the project’s database.

You will notice that 5 output contour datasets have been created as well as the intermediate
resampled raster dataset. The unique names are due to the %Value% being appended onto
the output name.

g. Finally remove all the datasets from the SoCal.gdb.

In this exercise you have created a model and added an iterator to it which allows the
processing of a resampling / contour creation workflow a set number of times. You have
used inline variable substitution to make sure that each output is unique, which is a
requirement for any output created by an iterator.

You have a couple of options now. You can look at the following optional step, followed by a
quick challenge step or you can go and have a break.

End of exercise

© ESRI (UK) Ltd Page 88


Optional step: Use “memory” for intermediate data
When your model runs it is writing out the intermediate resampled dataset to disk for reach
iteration. This means that there are five “writes” to disk for each run of the model. This will
slow down the time it takes to run the model. The use of the memory workspace will speed
up processing as the intermediate dataset is written to RAM and not to disk.

a. First of all, delete all of the datasets which are found inside of the SoCal default
geodatabase.

b. Locate the ElevResample variable:

c. Double click it to display the dialog box.

d. Select the current workspace but leave the name of the output dataset.

e. Remove the selected workspace text and replace it with memory

The dialog should look like the following:

f. Press the OK button to close the dialog.

g. Validate, save and run the model.

h. Refresh the SoCal geodatabase.

© ESRI (UK) Ltd Page 89


Notice there is no ElevResample dataset in the geodatabase. You may have noticed that
execution of the model, especially the Resample tool process was quicker!

i. Finally remove the contour datasets from the geodatabase.

If you feel like it have a go at the challenge step. This will be a test to see if you can
remember how to obtain user input to change the To Value.

Challenge step: Receive user input into the model


In this challenge step you will allow a user to enter a To Value.

So…

a. Add an additional variable to the For iterator which represents the To Value and
make it into a model parameter:

b. Validate and save the model.

c. Run the model as a model tool.

The dialog will look like the following:

d. For the To Value number enter 105 and run the model.

Once the model has finished processing you can add the datasets onto the map for your
inspection.

Notice that there are six contour datasets which have been created – the additional one is
created because you have changed the To Value to 105.

End of exercise

© ESRI (UK) Ltd Page 90


4 - ModelBuilder’s Utility and
Logic tools

Introduction
ModelBuilder has been described as a visual programming language. If you have carried out
some programming using any language then you have probably noticed that ModelBuilder
shares terms which are common to languages such as C#.net, VB and Python.

Languages have the concept of variables, syntax checking (validation) and looping. One
thing which has not been covered yet, which computer languages share, are the ability to
perform logic tests, such as “does this dataset exist”, “if this condition is true then run this”.
ModelBuilder also possesses the ability to perform these (and other) sorts of test.

ModelBuilder also supplies some so-called utility tools. Think of these as ‘helper’ tools – for
example the Calculate Value tool.

In earlier versions of ModelBuilder you would have had to have written a Python script to
achieve the same functionality which is now available in ModelBuilder.

This section will lead you through what tools are available and how to use them.

© ESRI (UK) Ltd Page 91


Learning objectives
In this section you will learn how to use the following tools:

• Utility tools

• Logical tools

© ESRI (UK) Ltd Page 92


Utility Tools
The five Utility tools are designed to run exclusively inside models and not inside a Python
script. This is because Python already provides this functionality through a mixture of core
tasks and through the Esri ArcPy site package (this allows you to perform geoprocessing
inside a Python script).

The tools perform a varied number of tasks.

Calculate Value
The Calculate Value tool returns a value based upon a Python expression.

This is an incredibly powerful tool in that it receives a value(s), possibly passed in by the
user, and performs a calculation and returns a value back to the model which can then be
used in the next model process.

Variables created in ModelBuilder can be used by this tool, but variables desired for use in
the expression parameter cannot be connected to the Calculate Value tool. To use them in
the expression, enclose the variable name in percent signs (%) using inline variable
substitution.

 Inline variable of type string should be enclosed within quotes ("%string


variable%") in an expression. Inline variables of type numbers (double, long)
do not require quotes (%double%).

The above model calculates a buffer distance. The Calculate Value tool receives the circle
circumference and then creates the radius (buffer distance) which is passed to the Buffer
tool.

© ESRI (UK) Ltd Page 93


The formula for the calculation is based on the following:

The Calculate Value tool represents the above formula as follows:

© ESRI (UK) Ltd Page 94


In the last exercise you saw how this tool can be used when the Resample tool received a
number of different inputs for the Output Cell Size parameter. It can receive either a layer, a
pair of X Y cell sizes or a single number if the X Y cell size is the same. The Resample tool in
ModelBuilder would not receive the single number so you had to employ the Calculate
Value tool to perform a conversion and set the output to the correct datatype:

Collect Values
The Collect Values tool is designed to collect output values of an iterator or to convert a list
of multivalues into a single input. The example below employs the Collect Values tool in a
sub model (more about embedding a model in an existing model later on in the course). The
output of Collect Values can be used as input to tools like Merge, Append, Mosaic, and Cell
Statistics which are found in the parent model.

The output of the Collect Values tool is Output Values. It is a multivalue of rasters and is
input to the Mosaic To New Rasters tool.

Another use of the Collect Values tool is for removing output parameters from the tool
dialog and still have the output added to the display. For example, suppose your model uses
the Buffer tool and the output of Buffer tool is a model parameter. When you run your
model from its tool dialog, the tool dialog displays this parameter and the user of your
dialog can change the location where the output of Buffer is written. But what if you don't
want the user of your dialog to change this location? That is, you want to write it to a
specific location they cannot change.

The solution is to change the output of Buffer so it is not a parameter and connect the
output to the Collect Values tool. Then make the output of Collect Values a model
parameter. When the model is run from the tool dialog, the parameter is not displayed in
the dialog and your user cannot change it. Yet, because it's an output parameter, it gets
added to the map.

© ESRI (UK) Ltd Page 95


Get Field Value
The Get Field Value tool gets the value of the first row of a table for the specified field.

The Summary Statistics tool creates a table which will only ever have one record in it. It
might contain the sum of a series of selected population values as specified by the input.

The value in the specified field is then extracted by the Get Field Value tool.

The Value passed to the next part of the model is 27210.

Parse Path
The Parse Path tool parses the input into its file, path, name, or extension derived variables.
The output can be used as inline variables in the output name of other tools.

Consider the following: if the input to the Parse Path tool is C:\Data\InputFC.shp, then in
the model below, multiple Parse Path tools are added to the model to extract the desired
portion of the Input.

© ESRI (UK) Ltd Page 96


The output of Parse Path is a string and cannot be connected directly as an input to the
tools such as Create Feature Class in parameters like Feature Class Location which requires a
workspace data type as input. Use %Value% inline variable substitution to rectify this.

Select Data
The Select Data tool selects data in a parent container, such as a folder, geodatabase or
feature dataset.

In the example below, the model copies two shapefiles to a geodatabase and merges one of
these feature classes with another feature class. The Select Data tool is used to select one of
the two feature classes in the geodatabase and pass it to the Merge tool.

© ESRI (UK) Ltd Page 97


Model Preconditions
A model can have multiple processes; for one process to run it may be dependent upon an
existing process to have already run. The processes may be in the same model but also
completely unrelated (or even disconnected). In such cases, preconditions can be used to
explicitly control the order of operations.

Preconditions can be used in the following ways:

A process can be made to run after another process by making the output of the first
process a precondition to the second process.

Any variable can be made a precondition to tool execution.

Any tool can have more than one precondition

Consider the following scenario:

The model contains two separate processes; the first process must execute before the
second process. If the model is executed as is, there is no way to control the order of
operations; the Clip tool may execute before its output location is even created, resulting in
an error.

A precondition allows for this requirement to be achieved:

Preconditions are used by many of the logic tools.

© ESRI (UK) Ltd Page 98


Logic Tools
The many logic tools control the flow of processing in a model. The model is able to make a
decision or evaluate a situation and decide which step to do next. The model implements if
– then – else logic, for example, if a particular feature class’s feature type is polygon then
run this branch of the model else run that branch of the model.

At some point in the model it may be necessary to merge the different branches together.
And stop execution of the model.

The following tools all require the boolean outputs to be set as a precondition.

Name Description
If Data Exists Evaluates if the specified data exists.
If Field Exists Evaluates if the input data has the specified fields.
If Selection Exists Evaluates if the input data has a selection and if a
certain number of records are selected.
If Row Count Is Evaluates if the row count of the input data matches a
specified value, for example, Is there more than one row
in a table?
If Coordinate System Is Evaluates if the input data has the specified coordinate
system, such as WGS 1984 Web Mercator.
If Data Type Is Evaluates if the input data matches the specified data
type, for example, check to see if the input is a feature
class or a shapefile.
If Feature Type Is Evaluates if a feature class is of the specified feature
type, such as point, polyline, polygon etc.
If Field Value Is Evaluates if the values in an attribute field match a
specified value, expression, or second field.
If Spatial Relationship Is Evaluates if the inputs have a specified spatial
relationship, for example, do any of the listed buildings
intersect a conservation area?
If Expression is Evaluates whether a Python expression is true or false
If Value is Evaluates an input value compared to a single value, a
list of values, or a range of values using a defined
comparison operator

© ESRI (UK) Ltd Page 99


Activity: Investigate the logic tools
Now that you have an understanding as to what some of the logic tools do, see if you can
answer the following questions or identify a useful scenario in which to use the tools.

Open the Desktop or web-based help at the following location:

Help > Analysis and geoprocessing > Geoprocessing > ModelBuilder > ModelBuilder toolbox
> Logical

Question 1: Do the Stop and Merge Branch tools implement a precondition?

___________________________________________________________________________

___________________________________________________________________________

Question 2: I am interested in identifying if a feature class is multipatch feature class. Which


logic tool would I choose to use?

___________________________________________________________________________

___________________________________________________________________________

Question 3: Which logic tool would I use if I want to identify if the input dataset is a raster?

___________________________________________________________________________

___________________________________________________________________________

Question 4: Write down a scenario in which you would use the If Dataset Exists logic tool.

___________________________________________________________________________

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 100


Question 5: What tool should be added to the model to complete the logic flow?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 101


Examples of the logic tools
The following are examples of when the use of logic tools might be useful to you:

If Field Exists
This tool checks to see if a particular attribute field (OWNER) exists. If it does not (False
condition) then the OWNER field is created and populated with the expression in the
Calculate Field tool.

The field_test_type parameter allows for different scenarios to be applied; for example – a
test to see that the input table has at least one expected field.

The boolean output of the If Field Exists tool has to be set as a precondition to the
downstream tools for those to execute if either the precondition is set to True or False.

If Selection Exists
The If Selection Exists tool checks to see if a selection set exists in a layer or table view.

Consider the model below:

© ESRI (UK) Ltd Page 102


If an input has features selected by the Select Layer By Attribute tool then the True output
variable and the precondition are set to True thus allowing the Summary Statistic tool to
run. If the False output variable is true (meaning no features are selected), then the model
ends as no tools are connected to the False branch.

There are many options available regarding how the selection criteria is tested:

In the model above the “Is Greater Than” option was selected and then a Count of 0 applied
so if a selection was made of any number then the precondition is set to True for the If
Selection Exists tool.

 This tool does not make a selection or evaluate an SQL expression or where
clause. It simply checks if a selection set matches a specified value. If you
need to make a selection then you should use the Select Layer By Attribute
tool to make a selection in ModelBuilder.

If Spatial Relationship Is
The If Spatial Relationship Is tool determines if the inputs have a specified spatial
relationship. The spatial relationships are the operators associated with the Select Layer By
Location tool:

© ESRI (UK) Ltd Page 103


The tool dialog determines the spatial relationship and also the condition which determines
whether the precondition is True or False.

In the dialog below the test is to see if any Schools are intersected by the Floods feature
layer. If some schools are intersected (the Selection Condition is set to Greater Than 0) then
the precondition is set to True.

The role of the tool can be seen in the model below:

It is important to note that the If Spatial Relationship Is tool does not select any features –
that is why the Select Layer By Location tool is used. The If Spatial Relationship Is tool just
evaluates a spatial relationship with the additional Selection Condition.

© ESRI (UK) Ltd Page 104


Tools which do not rely on a precondition
There are two Utility tools which do not rely on preconditions to work, and they are used to
bring separate branches of a model together or to cease processing within the model.

Name Description
Merge Branch The tool merges two or more logical branches
(created by, for example, If Data Type Is) into a
single output.
Stop Stops processing if all inputs values meet the
specified condition of True or False.

The Merge Branch tool


The Merge Branch tool merges two or more logical branches into a single output. It is used
in conjunction with the other logic tools, or a Python script tool which implements, if –
elif – else logic.

 You will cover how to work with a Python script tool in the next section.

For each run of the model only one branch of the model will run and produce an output.

In the model below the Merge Branch tool is used to merge the two separate branches. The
False branch creates the OWNER field on the existing Listed Buildings layer while the True
branch is processed when the OWNER field already exists and so the Listed Buildings layer is
passed into the Merge Branch tool.

Once a single branch has been created downstream tools are then applied to within that
single branch as opposed to having the same tool run on each separate branch.

© ESRI (UK) Ltd Page 105


The Stop tool
The Stop tool stops the iteration of a model based on a condition.

Consider the following model:

In the example above, the For iterator has been used to iterate values from 500 to 4000 and
incrementing by a value of 500. At the first iteration, the Value variable is 500, then 1000,
then 1500, and so on. This value is used as a buffer distance.

The Summary Statistics tool is used to calculate the sum area of all the polygons; the Get
Field Value tool is used to get the value from the summary statistics table.

The Calculate Value tool is used to calculate a Boolean true if the Sum Area value exceeds
40.

The Stop tool is set to stop model execution if the condition set in Calculate Value tool is
true. The model iterates for each value, and at the fourth iteration, in this example, the total
area of all polygons exceeds 40, making the condition true. The Stop tool exits the model at
this point.

© ESRI (UK) Ltd Page 106


Exercise 4: Performing some advanced
modelling techniques
Estimated Time: 35 minutes

In this exercise you will create a model which will extract all the feature classes from a
geodatabase which have a feature type of point or polyline and export them as shapefiles.

So how are you going to achieve this?

You will carry out the following:

• Create a folder called “Point”


• Use the Iterate Feature Classes tool to extract feature classes from the geodatabase.
• Use the If Feature Type Is logical tool to determine if a particular feature class is a
Point.
• Use the Copy Features tool to export the feature class to the Point folder.

The finished model should look like the one displayed below:

Step 1: Start ArcGIS Pro and create a project


In this quick step you will start ArcGIS Pro and create a new Project.

a. Start ArcGIS Pro and login using the credentials you were supplied with earlier.

b. Create a map based project called UtilityLogic and store it in the following location:

C:\EsriTraining\MBOP\UtilityTools

© ESRI (UK) Ltd Page 107


c. In the Catalog tab expand Toolboxes and create a new model in the UtilityLogic.atbx
toolbox.

d. Fill in the model properties as follows:

Name: ProcessFCs
Label: Process Feature Classes to Shps

e. Save the Model and the project.

The feature classes you are going to process are in the Aylesbury file geodatabase.

f. Add a folder connection to:

C:\EsriTraining\Database\Buckinghamshire

There are quite a few feature classes in the Aylesbury geodatabase contained in this folder.
You could export the feature classes individually or you could create a model which can be
re-used later.

g. Answer the following questions:

Question 1: How many point feature classes are in the Aylesbury geodatabase?

___________________________________________________________________________

___________________________________________________________________________

Question 2: How many polyline feature classes are in the Aylesbury geodatabase?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 108


Step 2: Add an iterator to the model.
You are going to use an iterator to process the point feature classes in the Aylesbury file
geodatabase, and ultimately copy the feature classes into a particular folder as shapefiles.

Before you do that you will add a tool which creates a folder. This folder is where ultimately
the exported feature classes will be stored.

a. In the Geoprocessing pane locate the Create Folder tool and drag it onto the canvas.

b. Right click the Create Folder tool and choose Create Variable > From Parameter >
Folder Location.

c. For the default value for the Folder Location variable enter
C:\EsriTraining\MBOP\UtilityTools

d. Double click the Create Folder tool and for Folder Name enter Points.

e. Save the model.

The model should look like the following:

You will now add the iterator. An iterator is available which allows you to process the feature
classes in a given geodatabase.

Question 3: What iterator should you choose to process the feature classes?

___________________________________________________________________________

___________________________________________________________________________

f. Add the Iterate Feature Classes tool to the model canvas and move it to the right of
the Points variable.

g. Create variables for Workspace or Feature Dataset (HINT: Right click the iterator >
Create Variable > From Parameter).

h. The default value for Workspace or Feature Dataset should be


C:\EsriTraining\Database\Buckinghamshire\Aylesbury.gdb

© ESRI (UK) Ltd Page 109


This is the location of the feature classes which you wish to process.

i. Make the Workspace or Feature Dataset a model Parameter and rename it


Geodatabase Location.

j. Connect the output of the Create Folder tool (Points) to the Iterate Feature Classes
tool and choose the Precondition.

This means that the Create Folder process will run before the Iterate Feature Classes tool.
The Iterate Feature Classes tool does not directly rely on the output of the Create Folder tool
for it to work.

So far the model should look like the following:

Question 4: What is stored in the actual Feature Class variable?

___________________________________________________________________________

___________________________________________________________________________

Question 5: What use could the Name variable be put to later on in the model?

___________________________________________________________________________

___________________________________________________________________________

k. Save the model.

Step 3: Add the Copy Features tool


The Copy Features tool will export a feature class from one geodatabase to another or to a
shapefile in a directory.

© ESRI (UK) Ltd Page 110


a. In the Geoprocessing pane search for the Copy Features tool and drag it onto the
model canvas to the right of the output of the iterator.

b. Connect the FeatureClass variable to the Copy Features tool and choose the relevant
connection parameter.

Question 6: Where is the location which the Copy Features tool writes out to?

___________________________________________________________________________

___________________________________________________________________________

As you can see the tool creates an output in the same location. This means that each feature
class created for each iteration will have the same name; each new feature class will
overwrites the previous feature class. You need to create a unique output for each iteration
of the model.

The Points variable contains the location of the new Points directory so this can be used for
the output location.

c. Move your cursor over the Points variable to see the output location for the
shapefiles.

Question 7: What is the location contained in the Points variable?

___________________________________________________________________________

___________________________________________________________________________

Question 8: What variable contains the string name of the currently processed feature
class?

___________________________________________________________________________

___________________________________________________________________________

The output for the Copy Features tool can be built by using in-line variable substitution based
upon the answers to questions 7 and 8 with .shp added at the end.

© ESRI (UK) Ltd Page 111


d. In the Copy Features dialog replace the Output Feature Class argument to use the
value in the Points variable and the Name variable with .shp added to the end.

 You will need to include a backslash \ between the Points and Name
variables.

The dialog should look like the following:

e. Press the OK button on the tool dialog.

The model should look like the following:

You will test to see what the model does so far.

f. Save the mode, validate it and then run it.

g. Open up File Explorer and navigate to C:\EsriTraining\MBOP\UtilityTools.

Notice the Points folder which was created by the Create Folder tool.

h. Open the Points folder.

You will see that all of the feature classes from the Aylesbury file geodatabase have been
exported as shapefiles to this folder.

© ESRI (UK) Ltd Page 112


You need to export just the point shapefiles.

You will do this in the next step.

i. In File Explorer delete the Points folder.

Step 4: Implement the If Feature Type Is logic tool


You will now use the If Feature Type Is logic tool. This tool will perform a test on the current
feature class that is being processed and determine its feature type, such as point,
annotation, polygon etc.

The tool implements Boolean logic; if the passed in feature class’s feature type matches the
feature type of the tool then that will evaluate to Boolean true, otherwise Boolean false will
be returned.

You will add it to the model so that it accepts the FeatureClass variable from the Iterate
Feature Classes tool and then based upon the logic test outcome it will then connect to the
Copy Features tool.

a. On the ModelBuilder ribbon, locate the Insert group and choose If Feature Type Is
from the Logical menu.

b. Position the tool near to the Copy Features tool.

© ESRI (UK) Ltd Page 113


You will now create a variable to indicate that the tool will test the Point feature type.

c. Right click the If Feature Type Is tool and create a variable from parameter based on
the Feature Type.

d. Double click the Feature Type variable and choose Point.

The If Feature Type Is tool needs a feature class as an input.

e. Connect the FeatureClass variable to the If Feature Type Is tool choosing the relevant
input parameter choice.

The tool is now in its “ready to run state”.

The tool has two outputs – true and false. The true branch will run when the feature class
being processed has the same feature type as the tool’s feature type. The false branch will
run when the feature classes feature type is not a point feature type.

Question 9: Which branch should the Copy Features tool be connected to?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 114


f. Connect the true strand of the If Feature Type Is tool to the Copy Features tool as a
precondition.

g. The model might look a little messy so use the Auto Layout button to rearrange the
components.

h. Rearrange the variables and tools so that it looks like the following:

You have finished building the model!

i. Save, validate and run the model.

Once the model has run you are ready to inspect the output.

j. Locate the C:\EsriTraining\MBOP\UtilityTools folder in File Explorer and notice that


the Point folder has been created.

k. Inspect the contents.

You will notice that it is comprised of many shapefiles; each one is a point shapefile.

The model has sifted through the Aylesbury geodatabase and copied the point feature
classes into the point folder as shapefiles. You have fulfilled your brief.

You may have noticed that the Iterate Feature Classes tool has a Feature Type argument.
You could have set that to a Point….. but where is the fun in that?

l. If you have time then perhaps have a go at Scenario A? Otherwise close ArcGIS Pro
down.

End of exercise

© ESRI (UK) Ltd Page 115


5 - Advanced Techniques in
ModelBuilder

Introduction
So far you have learned how to create some basic models and to that, you have added
greater complexity in the form of iterators, logic and utility tools.

In this final section you will have a look at how you can extend your models by embedding
an existing model inside of a model, running your model using ArcGIS Pro’s task scheduling
functionality. As well as those topics you will also have a look at how you can interactively
create features for input into a model and have a look at how model feedback can be used
for iterative processing too.

Learning objectives
After completing this lesson, you will be able to perform the following task:

• Interactively specifying features for input into your model.


• Build feedback into your model.
• Embed an existing model inside of a model.
• Run your model as a scheduled task from within ArcGIS Pro.

© ESRI (UK) Ltd Page 116


Interactive Feature Input
When a model is run on some input data types, such as a feature layer, you can specify a
selected feature as the input. All features can be used if there is no selection on the input
feature layer or if a feature class is chosen.

However, if one of your model parameters is a feature set, feature layer, or table view
datatype, you will be able to select existing map layers from the Contents pane, browse to
datasets, or interactively enter new features on the map.

Interactive Input tool


The Interactive Input tool is used to receive user input by capturing features on the active
map.

Clicking the interactive input tool displays a drop down box of points, lines, polygons and
multipatch. These are valid entries for the tool.

© ESRI (UK) Ltd Page 117


For example, on choosing a point two things happen; a temporary layer to hold the entered
point is added to the Contents pane and a template is added below the tool parameter.

When the input is chosen the template is displayed:

This is used to create the input feature or features.

Using a Feature Set datatype


A feature set allows for the interactive capture of features based upon the geometry (and
attributes) of a layer file.

In the example below the BristolBusStops layer file is added as a property of the feature set
which indicates that the only type of geometry, and symbology, which can be used for input
into the model will be a point.

© ESRI (UK) Ltd Page 118


Using Feedback in your model
In ModelBuilder, Feedback is where the output of a process can be used as the input to a
former process.

A feedback loop is made by connecting an output variable of one process to the input
variable of the same process. The model knows that when the output is connected to the
input it is a feedback loop and automatically creates a dotted blue feedback connector line.
Every time the tool iterates, the output variable will be used as input for the next iteration.

An example of feedback is shown below:

The model will produce one output per iteration. In-line variable substitution is then used as
part of the name for the output dataset if you do not want the output dataset to be
overwritten.

© ESRI (UK) Ltd Page 119


Embedding one model inside another
Model tools are fully integrated into the geoprocessing framework and can be used in the
same way all system or script tools can. This means that a model tool can be used
throughout the geoprocessing framework; it can be used as the resource from which a
geoprocessing service can be created; it can be called from within an ArcGIS Pro API based
application; or from a Python script; and a model can also be called from within an existing
model.

What are the reasons for doing this?


Firstly, you may wish to simplify a complex model. This makes it easier to understand and
also support.

The other reason is to accommodate multiple iterators in a workflow. Remember that only
one iterator per model is supported. Nesting models allows for workflows which require
multiple iterators to be present.

Some best practice for embedding a model within a model:

Only one iterator per model can be used.

The tools you want to run once should be placed in a separate model from those tools
which are to be run more than once. In this situation, all tools that need to run multiple
times should be placed in one model with a model iterator and used as a sub-model. The
tools that only need to be run once should be placed in the main model, which calls the
iterating sub-model.

Use in-line variable substitution for unique output of an iterator.

Provide default values to your sub model when you are testing.

To connect your model, make a variable in the sub-model a parameter.

© ESRI (UK) Ltd Page 120


Consider the following model:

The MainModel has an iterator called IterateWorkspaces and it processes a folder


containing any file geodatabases. The current workspace is passed into a nested model
called SubModel.

The SubModel contains another iterator, Iterate Feature Classes, which processes the point
feature classes based upon the passed in workspace. The currently processed feature class
is then buffered. Once that iteration has finished in the SubModel then flow returns back to
the next iteration in the Iterate Workspaces tool in the MainModel model.

© ESRI (UK) Ltd Page 121


Schedule a model to run
As you have seen throughout this course, ModelBuilder provides you with the ability to
perform (sometimes repetitive) batch-processing. It might be a requirement that this
processing occurs at certain times of the day or at night when the network and systems are
generally quiet. If this is the case, then it is possible to schedule your model to run at a
predefined time.

There are two choices for scheduling:

• Use MS-Windows Task Scheduler. For more information on how to do this then
please see Appendix 1.
• Use the scheduler available within ArcGIS Pro.
You can schedule geoprocessing tools to run within ArcGIS Pro. This relates to the System
tool, Python Script and Toolbox tools, and Model tools.

The process of scheduling a tool to run is summarised below:

1: Fill in tool 3: Specify


2: Run button > 4: Manage the
required frequency
Schedule scheduled tool
parameters options

To schedule a tool to run you should carry out the following:

• Fill in the tool’s parameters (required and optional parameters).


• On the Run button click the split menu and choose Schedule.

On the Schedule: dialog specify the Name, how often the tool will run (once, minutes, hours,
daily, weekly or monthly), and when the model will first run.

© ESRI (UK) Ltd Page 122


Manage the scheduled tool. The scheduled tool is added to the History tab underneath the
Geoprocessing > Scheduled Tools tab:

Every time the tool runs you have the option of overwriting the original output or creating a
new unique output based upon the date and time the scheduled tool ran. If you wish to
create new output then use the timestamp variable %t%. So If the tool ran at 15:35 on 22nd
April 2021 and it created a new PlanningApps feature class then the output would be of the
form:

© ESRI (UK) Ltd Page 123


Exercise 5: Working with multiple models
Estimated Time: 25 Minutes

In this final exercise you will investigate how to embed a model to an existing model and in
doing so you will bring together many of the techniques you have learned in this course.

You will create a model which will iterate over a number of file geodatabase workspaces.
This is the parent model.

You will also work with an existing model which processes each feature class in a workspace
and buffers the features accordingly. This will be the child model.

You could run both models independently of each other but it means that you would be
running the “buffer” sub-model many times once the first model has run which isn’t
particularly efficient, so you will embed the existing child “buffer” model into the parent
“iterator” model.

In this exercise, you will:

• Create the parent Iterate Workspace main model.

• Add an existing child buffer model into the main model.

• Connect both of them up to each other and test.

• Optional step: Run the model as an ArcGIS Pro scheduled tool

The final model will look like the following:

The Buffer Feature Classes using an Iterator process is the sub model which will be added to
the parent model.

© ESRI (UK) Ltd Page 124


Step 1: Create a basic model to iterate over workspaces
In this quick step you will create a simple model which will iterate over file geodatabases
that are in a directory. This will be the parent model.

a. Open ArcGIS Pro, create a new blank Catalog project called EmbedModel and store
it in the following location:

C:\EsriTraining\MBOP\AdvancedTechniques

b. Make a Folder Connection to C:\EsriTraining

c. Within Toolboxes > EmbedModel.atbx create a new model called IterateWorkspaces.

d. Add the Iterate Workspaces tool to the model.

e. For the Iterate Workspaces tool, add a Folder variable and set its value to:

C:\EsriTraining\Database\Buckinghamshire

f. For the Iterate Workspaces tool create a Workspace Type variable and set its value
to File Geodatabase.

The model might look like the one displayed below:

© ESRI (UK) Ltd Page 125


g. Save the model.

In this step you have created a basic model. In a future step a sub-model will be added to this
parent model.

Step 2: Investigate and add the existing buffer model


In this step you will investigate a pre-existing model that will be added to the parent model
you just created. The model has been pre-created for you and so you will spend a few
moments investigating what it does. This is the child model.

a. In the Catalog tab expand Folders > EsriTraining > MBOP > AdvancedTechniques.

b. Expand the ModelToAdd toolbox and edit the Buffer Feature Classes using an
Iterator model.

c. Spend a few moments examining the model and then answer the following
questions:

Question 1: What is the name of the iterator within the model?

___________________________________________________________________________

___________________________________________________________________________

Question 2: How is a unique output created from the Buffer tool created?

___________________________________________________________________________

___________________________________________________________________________

© ESRI (UK) Ltd Page 126


Question 3: What feature type will the iterator process?

___________________________________________________________________________

___________________________________________________________________________

Currently the model will buffer all point feature classes within the Bristol_Centre file
geodatabase. A unique output feature class is created and is stored in the
C:\EsriTraining\MBOP\AdvancedTechniques\OutputGDB.gdb and all output feature classes
have “Buff_” placed in front of them.

Now that you have an understanding of what this child model does you are ready to add it to
the parent model.

Step 3: Connect both models


Now you will bring the child Buffer Feature Classes…. model into the parent model.

a. Drag the Buffer Feature Classes… model into the Iterate Workspaces model.

The model is added and has the symbology of a tool.

You may have noticed that the Iterate Workspaces tool outputs to a workspace and that the
Iterate Feature Classes iterator has a workspace as an input.

To pass the current workspace, which is being processed in the parent model, into the Buffer
Feature Classes … child model you will need to connect the parent model’s output workspace
to the input workspace of the child Buffer Feature Classes… model.

b. Try to connect the Workspace output to the Buffer Feature Classes… process.

© ESRI (UK) Ltd Page 127


You would expect to see Workspace as the connector option. Instead you will notice the
precondition option is displayed instead.

For the model to communicate with the other one you need to connect to a workspace.

You will make a change in the Buffer Feature Classes… model to allow a useful connection to
be made.

c. If you have made a connection between the two items then delete it.

d. Delete the Buffer Feature Classes… tool in the Iterate Workspaces model.

e. In the Buffer Feature Classes… model locate the Workspace variable and make it a
parameter.

f. This allows for input to come from outside of the model.

g. Save the model.

h. Drag the Buffer Feature Classes… model back into the Iterate Workspaces model.

You will see that the model with its input parameter (Bristol_Centre)is added.

© ESRI (UK) Ltd Page 128


i. Delete just the input parameter (Bristol_Centre) to the Buffer Feature Classes… tool.

j. Connect the Workspace variable of the parent model to Buffer Feature Classes… tool
by choosing the Workspace option as the input parameter to the model.

The process is then coloured as you might expect.

k. Press Auto Layout and save the model.

© ESRI (UK) Ltd Page 129


The model is now ready to be run.

l. Validate and run the model.

It will take a couple of minutes for the model to complete.

m. Close the dialog once it has finished processing.

n. Inspect the geodatabases in the input Buckinghamshire folder.

As you can imagine the model is iterating over each file geodatabase in the Buckinghamshire
folder and buffering all the point feature classes in each file geodatabase.

The results are written out to the specified output workspace.

Question 4: How many feature classes are in the output geodatabase?

___________________________________________________________________________

___________________________________________________________________________

The output geodatabase contains the buffered point feature classes from the geodatabases.
Notice, though, that the point feature classes in the feature datasets are not processed - you
would need to use an Iterate Datasets tool to achieve that.

Optional Step: Run the model as a Scheduled Task


In this optional step you will run the model at pre-determined time using ArcGIS Pro’s built-in
scheduling functionality.

This is an ideal technique to use when you wish your model to run daily, weekly etc when you
may not be able to run the model during the working day, or because a workflow demands
that datasets are refreshed at certain times of the day.

Creating a scheduled task in ArcGIS Pro will also create a scheduled task in Windows Task
Schedular.

a. First of all, delete all of the feature classes in the OutputGDB.gdb.

© ESRI (UK) Ltd Page 130


The feature classes were created when you ran the model in this exercise.

You will also add the %t% timestamp to the name of the output feature classes the child
model creates to help identify when the scheduled task ran. This will also help provide
unique output should you ever wish to run the model again as a scheduled

b. Edit the Buffer Feature Classes using an Iterator model.

c. Double click the BufferedFC variable.

d. Add the following to the end of the BufferedFC output value: _%t%

The value should look like the following.

e. Press the OK button and save the model.

You are now ready to create the scheduled task.

f. In the Toolboxes > EmbedModel.atbx double click the Iterate Workspaces model
tool to display the tool dialog.

There are no parameters to fill in on the dialog as all of the required parameters for the tools
in the model have been filled in already.

g. On the Run button click the split option and choose Schedule.

© ESRI (UK) Ltd Page 131


The will display the Schedule dialog. You can specify the Task Name; how often the model
should run and when it should begin its run.

h. Set the Begins On value to one minute from now and press the OK button.

You model has now been scheduled!

i. To view the progress of scheduled tasks then open the History pane (HINT: Analysis
tab > Geoprocessing group).

j. Under the Geoprocessing tab click the Scheduled Tools tab.

This will display the results of your scheduled tools. You can view whether or not the process
ran without any errors, messages – all the things you would expect to be able to see when
you run a tool:

© ESRI (UK) Ltd Page 132


Inspecting the output geodatabase will display the feature classes with the time and date
stamp providing a unique output for the scheduled task. This was because you placed a %t%
timestamp to the output feature class variable in the child model.

That is the end of the exercise.

End of exercise

© ESRI (UK) Ltd Page 133


Glossary of ModelBuilder terms

Term Description
Connector Lines connecting variables to tools.
Data Type In a script \ model tool the Data Type refers to the expected
data passed in or passed out of a script or model.
Data Variable Stores an input or derived data.
Derived Data Data created from geoprocessing tool.
Derived Values Standard types created by tools, for example, the Calculate
Value tool.
Direction In a script \ model tool the Direction refers to whether data
exists (input) or is created (output).
Element A component part of your model. These can be geoprocessing
tools, types of variables and connector lines.
Feature Set A datatype that allows a user to intuitively add features to a
map and use them as inputs into a model.
Feedback Connector Output of one process which is used as the input into a previous
process
in_memory Legacy memory based workspace for use with ArcMap. Use the
memory workspace when working with ArcGIS Pro.
Input Data Normally pathways and datasets.
Input Values Basic data types of numbers, strings and Booleans.
Intermediate Dataset Data created by a tool which is then used as an input into a new
tool. Tends to be temporary in nature.
Iterator Allows batch processing of feature classes, rasters, workspaces
etc in a model
memory New memory based workspace for ArcGIS Pro to support
output feature classes, tables and raster datasets. Subtypes and
domains are supported.
Model A diagram containing a collection of tools, with their associated
variables, which replicates an organisation’s workflow.
Model Tool A model that resides and run from inside a toolbox
Parameter Allows user defined data stored inside a variable for use in a
model, such as an input feature class or the location of an
output workspace.

© ESRI (UK) Ltd Page 134


Precondition Connector Controls the order in which model processes are run.
Process A geoprocessing tool with its associated input(s) and output(s).
Script Tool A Python script that has been added to a custom toolbox and is
run as a geoprocessing tool.
Value Variables Stores standard data types such as numbers, strings and
Booleans.
Variable Stores a value

© ESRI (UK) Ltd Page 135


Appendix 1: Running a model via
Task Scheduler
As you have seen throughout this course, ModelBuilder provides you with the ability to
perform (sometimes repetitive) batch-processing. It might be a requirement that this
processing occurs at certain times of the day or at night when the network and systems are
generally quiet. If this is the case, then it is possible to run your model using MS-Windows
Task Scheduler, by implementing 5 simple steps.

Create a
simple Create a Task
Specify the Specify the Manage the
Python script in Windows
Task Action Task Trigger Task
to call the Scheduler
model

Step 1: Create a simple Python script to call your model


Your model will be run as a simple Python script as a Python (.py) file is recognised by the
Task Scheduler as a valid file type to run.

You will need to make sure that Python and the ArcPy site package are installed on the
machine running the Task Scheduler as well as providing the machine access to your model
and associated data.

The following is written inside of a Python file:

import arcpy

arcpy.ImportToolbox(r"C:\PathTo\myToolbox.atbx")

arcpy.myModelName(r"c:\pathToInput\inputFolder", r"C:\pathToGdb\output.gdb")

The model (myModelName) is part of the geoprocessing framework and is called directly
from the ArcPy site package. In the example above the model has two parameters which are
passed into the model.
© ESRI (UK) Ltd Page 136
Step 2: Create the Task in Task Scheduler
Windows Task Scheduler allows you to run the script (and in turn, the model) at a specified
time.

It is simple enough to create the Task and provide a name for it.

Step 3: Specify the Task Action


You need to determine the Python installation that will run the scheduled task (remember
that the task is running a Python file).

Set the pathway to the Python installation via the Program/script section in the Create Task
dialog box and point it towards the following location:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3

This is the default file path for the version of Python used in ArcGIS Pro and ensures that the
script is able to execute the ArcPy code.

In the Add arguments (optional) option in the New Action window, add the path to your
script file; it must be enclosed in quotation marks:

Step 4: Specify a Task Trigger


So how do you want your model to run? And how often?

This is achieved by setting a Task Trigger.

© ESRI (UK) Ltd Page 137


On the Triggers tab you can control at what time the task should execute and how often.

Once it has run it will be displayed in the Task library (you may need to refresh it)

Step 5: Manage the Task


The task can then be managed in the Task Scheduler Library.

That’s all you need to know….

© ESRI (UK) Ltd Page 138


Appendix 2 – Answers
Exercise 1
Question 1: What is the difference between Auto Layout and Fit To Window?

Answer: Auto Layout arranges the elements in your model in the most pleasing way possible
while Fit To Window will zoom to the full extent to fit all elements in the display.

Question 2: What is the purpose of the Insert group of UI elements?

Answer: The Insert group allows you to add elements on to the ModelBuilder canvas.

Question 3: What is the purpose of the Lock Element button?

Answer: The Lock Element button prevents elements from being included in the Auto
Layout operation.

Question 4: What use can the Group button be put to?

Answer: The Group button allows you to group together model processes, name the group
and hide (collapse) the elements in the group.

Question 5: How many types of label are there?

Answer: There are 3 types of label: A free standing label; label associated with a tool, a label
associated with data.

Question 6: How do you undo a mistake you have made?

Answer: You can use the Undo button on the Quick Access Toolbar.

© ESRI (UK) Ltd Page 139


Exercise 2

Question 1: What is the current value for ‘Allow geoprocessing tools to overwrite existing
datasets’?

Answer: The check box is ticked which means that any existing datasets can be
overwritten by geoprocessing processes.

Question 2: What does the model do?

Answer: The model buffers the Major Bristol Roads dataset and then uses the output of
the Buffer tool to clip the Planning Applications features.

Question 3: What is the distance to which the Bristol roads are being buffered to?

Answer: the buffer distance is 75 metres.

Question 4: On the Clip tool what is the name of the Input Features and what do they
represent?

Answer: The name of the Input Features is Planning Applications and they represent the
features to be clipped.

Question 5: What is the name of the clipped output dataset and which location is it written
to?

Answer: The output dataset is called ClippedPlanningApps and it is written to the


following location:

C:\EsriTraining\MBOP\ModelBuilderBasics\BufferAndClip\BufferAndClip.gdb\

Question 6: How many feature classes are in the geodatabase?

Answer: There are two feature classes in the geodatabase

© ESRI (UK) Ltd Page 140


Question 7: How was the st57_Road_Line_Buffer feature class created?

Answer: It was created by the Buffer tool. It is then used as an input into the Clip tool.

Question 8: How many feature classes are in the geodatabase?

Answer: There is only one feature class in the output geodatabase.

© ESRI (UK) Ltd Page 141


Activity 3
Activity: Answer the following six questions:

Question 1: How many model iterators are there?

Answer: There are 15 iterators for you to use

Question 2: How many iterators can be included in each model?

Answer: Only one iterator per model can be used. If you want to have more than one
iterator in a workflow then you will need to embed a model in an existing model.

Question 3: How might you provide a unique name to the output of a tool which is affected
by an iterator?

Answer: You would use in-line variable substitution.

Question 4: What iterator would you choose if you wanted to run a workflow a specific
number of times?

Answer: A FOR iterator allows you to run a model an explicit number of times

Question 5: How would you iterate over each row or feature in a table or feature class?

Answer: The Iterate Row Selection / Iterate Feature Selection iterators allow you to process
each row or feature.

Question 6: How do you add an iterator to your model?

Answer: From the ModelBuilder ribbon go to the Insert Group and choose Iterators.

© ESRI (UK) Ltd Page 142


Exercise 3

Question 1: What units is the raster measured in?

Answer: The units of the raster are metres.

Question 2: What is the resolution of the Elevation raster?

Answer: The resolution of the raster is 28.3 metres

Question 3: Why is the tool not “ready to run”?

Answer: Not all of the mandatory parameters have been filled in.

Question 4: What required parameter does the tool need to be populated with?

Answer: The Contour interval is the only required parameter which needs to be filled in.
Once a value has been entered then the model process will be in a ready to run state.

Question 5: What is the purpose of the For iterator’s Value variable?

Answer: The Value variable holds the current value which the For iterator is processing.

Question 6: What is the current Data Type?

Answer: The current Data Type is set to Variant. This indicates that the tool does not know
what the data type will be based upon its current information.

Question 7: Based upon the values you entered into the iterator, how many output datasets
would you expect to see?

Answer: You would expect to see five output contour datasets – one for each iteration
(30, 45, 60, 75, 90).

© ESRI (UK) Ltd Page 143


Activity 4
Activity: Investigate the logic tools

Now that you have an understanding as to what some of the logic tools do, see if you can
answer the following questions or identify a useful scenario in which to use the tools.

Question 1: Do the Stop and Merge Branch tools implement a precondition?

Answer: No – they do not implement a precondition.

Question 2: I am interested in identifying if a feature class is multipatch feature class. Which


logic tool would I choose to use?

Answer: I could use the If Feature Type tool.

Question 3: Which logic tool would I use if I want to identify if the input dataset is a raster?

Answer: The Is Data Type tool could be used to identify if an input dataset is a raster dataset
or not

Question 4: Write down a scenario in which you would use the If Dataset Exists logic tool.

Answer: You might want to see if a particular named dataset exists and perform a field
calculation on it. This is because the field calculation might be reliant on the existence of
some existing attribute fields that are found inside of the dataset.

Question 5: What tool should be added to the model to complete the logic flow?

Answer: The Merge Branch tool is the missing tool, as it brings both strands of the model
together.

© ESRI (UK) Ltd Page 144


© ESRI (UK) Ltd Page 145
Exercise 4

Question 1: How many point feature classes are in the Aylesbury geodatabase?

Answer: There are 7 point feature classes in the geodatabase.

Question 2: How many polyline feature classes are in the Aylesbury geodatabase?

Answer: There are 7 polyline feature classes in the geodatabase.

Question 3: What iterator should you choose to process the feature classes?

Answer: The Iterate Feature Classes tool should be used

Question 4: What is stored in the actual Feature Class variable?

Answer: The FeatureClass derived variable stores a reference to the actual feature class that
the iterator is currently processing.

Question 5: What use could the Name variable be put to later on in the model?

Answer: You can use the contents of the Name variable, which is a string (the name of the
feature class that is being processed) for in-line variable substitution.

Question 6: Where is the location which the Copy Features tool writes out to?

Answer: The location is C:\EsriTraining\MBOP\UtilityTools\UtilityLogic\UtilityLogic.gdb

Question 7: What is the location contained in the Points variable?

Answer: The location is C:\EsriTraining\MBOP\UtilityTools\Points

© ESRI (UK) Ltd Page 146


Question 8: What variable contains the string name of the currently processed feature
class?

Answer: The Name variable contains the string representation of the currently processed
feature class.

Question 9: Which branch should the Copy Features tool be connected to?

Answer: The Copy Features tool should be connected to the true strand as you only want to
copy the point feature classes to the Point folder as shapefiles.

© ESRI (UK) Ltd Page 147


Exercise 5

Question 1: What is the name of the iterator within the model?

Answer: The Iterator is Iterate Feature Classes.

Question 2: How is a unique output created from the Buffer tool created?

Answer: In-line variable substitution is used to first of all specify the location of the
destination file geodatabase, and then the unique name of the output feature class.

Question 3: What feature type will the iterator process?

Answer: It will process only point feature classes.

Question 4: How many feature classes are in the output geodatabase?

Answer: There are 14 feature classes in the output geodatabase

© ESRI (UK) Ltd Page 148

You might also like