1 / 29

Branching and Iteration in ModelBuilder

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?)

johnvargas
Download Presentation

Branching and Iteration in ModelBuilder

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. July 24, 2012 3:15 pm - 4:30 pm Branching and Iteration in ModelBuilder Shitij Mehta

  2. 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

  3. 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

  4. All presentations will be available online!!!!!!!

  5. 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

  6. 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

  7. 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.

  8. 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

  9. 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.

  10. Demo 1 Branching using the Calculate Value tool

  11. Demo 2 Branching using a Script tool

  12. 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

  13. Iteration

  14. 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

  15. 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

  16. Accessing the iterators in ModelBuilder

  17. Demo 1 Iterating Feature Classes

  18. Demo 2 Iterating For

  19. Demo 3 Iterating Feature Selection

  20. Demo 4 Iterating Multivalue

  21. Demo 5 Model within a Model Main Model Sub-Model

  22. Demo 6 Model within a Model within a Model 3 Level Nested Models Model 1 Model 2 Model 3

  23. 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%

  24. 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

  25. Python Equivalent of Iterators in ModelBuilder

  26. Where to get help? Click Doc, Tutorials,Book

  27. Questions? Please fill out the evaluation form online at: http://www.esri.com/ucsessionsurveys Session ID - 1914

  28. Thank You!!!!

More Related