300 likes | 333 Views
July 24, 2012. 3:15 pm - 4:30 pm. Branching and Iteration in ModelBuilder. Shitij Mehta. Questions for you. How many User Conferences have you been to? Geoprocessing experience? Little (rarely used) Some (know the basics) Advanced (build your own tools) Guru (anointed or legendary?)
E N D
July 24, 2012 3:15 pm - 4:30 pm Branching and Iteration in ModelBuilder Shitij Mehta
Questions for you • How many User Conferences have you been to? • Geoprocessing experience? • Little (rarely used) • Some (know the basics) • Advanced (build your own tools) • Guru (anointed or legendary?) • Platform? • 9.3 • 10.0
Outline - I apologize - there is a lot to cover • Branching – 30 minutes • Calculate Value • Demo 1 - Tool – Feature Type • Demo 2 – Shape Type • Demo 3 – Merge Branch • Demo 4 - Script tool example • Iteration – 30 minutes • Demo 1- Iterate Feature Classes • Demo 2 – Iterate For • Demo 3 – Iterate Feature Selection • Demo 4 – Iterate Multivalue • Demo 5 – 2 Level Nested Model • Demo 6- 3 Level Nested Model • Python Equivalent of Iterators in ModelBuilder
What is Branching? IF some condition is true, THEN perform an action; ELSE the condition is false, perform a different action. Iffile X exists Add a field File in Workspace Elseif file X does not exists Copy and then add a field Examples Ifhas X projection Do nothing Feature Class Else- Project
How to branch? • The condition - If-then-else 1 Calculate Value tool 2 Script tool OR • Where to find the tool • Python Code • Data types • Preconditions in a model • Inline Variable Substitution • Merge Branch tool • Creating a script tool • Python code • Setting script tool properties • Preconditions in a model • Merge Branch tool
Inline Variable Substitution The value of any variable can be used in the tool parameters by enclosing the name of the substituting variable between the percent signs (%). Substituting variables in this manner is called inline variable substitution.
Inline variable substitution • In SQL expressions - Name = ‘%Value%’ - “%Value%”.replace( “ ”, “”) • In Output name – C:\Scratch\Scratch.gdb\%Value% • If string put “quotes” around your inline variable substitution
Precondition Preconditions can be used to explicitly control the order of operations in a model. Any variable can be made a precondition to tool execution, and any tool can have more than one precondition.
Where to get help? Click Doc, Blogs Understanding which if troubles you If you are stuck at "if" – Part 1 – Branching using the Calculate Value tool If you are stuck at "if" – Part 2 – Example of using Script tool to create branches using if-else logic If you are stuck at "if" – Part 3 – Does Extension Exists model example If you are stuck at "if" – Part 4 – Does Selection Exists model example If you are stuck at "if" – Part 5- Does Projection Exist model example
What is iteration? Iteration = looping = repeat a process over and over Iteration in ModelBuilder = Run entire model or asingle tool or a set of tools repeatedly Tools to iterate in ModelBuilder = Iterators Example - Iterate over a list of feature classes and project each feature class. Iterator
Selected Features For Iterate Feature Selection While Continue Value Value Selected Rows Iterate Field Values Iterate Multivalue Iterate Row Selection Value Value Value Dataset Feature Class File Iterate Datasets Iterate Feature Classes Iterate Files Name Name Name Raster Table Workspace Iterate Rasters Iterate Tables Iterate Workspaces Name Name Name
Demo 5 Model within a Model Main Model Sub-Model
Demo 6 Model within a Model within a Model 3 Level Nested Models Model 1 Model 2 Model 3
Rules for a nested model/model within a model • Only one iterator can be used per model. • Add only the tools you want to run as many times as an iterator in the same model. • The script will not include the iteration logic if a model with an iterator is exported to a Python script. • The output of any tool connected to the iterator can have (if required) a unique name for each iteration to avoid being overwritten by • Using the system variable %n% • C:\Sctatch\scratch.gdb\output_%n% • Using the Name or Value output of the iterator • C:\Sctatch\scratch.gdb\output_%Name% C:\Sctatch\scratch.gdb\output_%Value% • Using any other variable in the model as an inline variable • C:\Scratch\scratch.gdb\output_%XYZ%
Rules for a nested model/model within a model • Give default values to your sub model for setting and testing it • Make model parameters in your sub-model that you want as variable in main model
Questions? Please fill out the evaluation form online at: http://www.esri.com/ucsessionsurveys Session ID - 1914