Iteration - s3.amazonaws.com

Download Report

Transcript Iteration - s3.amazonaws.com

Esri International User Conference
San Diego, California
Technical Workshops | 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
All presentations will be available online!!!!!!!
What is Branching?
IF some condition is true, THEN
perform an action;
ELSE
the condition is false,
perform a different action.
If file X exists Add a field
File in
Workspace
Else if file X does not exists
Copy and then add a field
Examples
If has 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.
Demo 1
Branching using the
Calculate Value tool
Demo 2
Branching using a Script tool
Where to get help? Click Doc, Blogs
1. Understanding which if troubles you
2. If you are stuck at "if" – Part 1 – Branching using the Calculate Value tool
3. If you are stuck at "if" – Part 2 – Example of using Script tool to create
branches using if-else logic
4. If you are stuck at "if" – Part 3 – Does Extension Exists model example
5. If you are stuck at "if" – Part 4 – Does Selection Exists model example
6. If you are stuck at "if" – Part 5- Does Projection Exist model example
Iteration
What is iteration?
Iteration = looping = repeat a process over and over
Iteration in ModelBuilder = Run entire model or a
single tool or a set of tools
repeatedly
Tools to iterate in ModelBuilder = Iterators
Iterator
Example - Iterate over a list of feature classes and
project each feature class.
For
Value
Iterates over a starting and
ending value by a given value.
Iterate
Row
Selection
Selected
Rows
Dataset
Name
Iterates over datasets in a
Workspace or Feature Dataset.
Iterate
Rasters
Continue
Iterates "while" a
condition is true or false.
Iterate
Field
Values
Value
Selected
Features
Value
Iterates over features in a
feature class.
Iterate
Multivalue
Value
Value
Iterates over rows in a table.
Iterate
Datasets
While
Iterate
Feature
Selection
Raster
Name
Iterates over rasters in a
Workspace or a Raster Catalog.
Iterates over each value in
a field.
Iterate
Feature
Classes
Feature
Class
Iterates over a list of values.
Iterate
Files
Name
Name
Iterates over feature
classes in a Workspace or
Feature Dataset.
Iterate
Tables
Table
Name
Iterates over tables in a
workspace.
File
Iterates over files in a folder.
Iterate
Workspaces
Workspace
Name
Iterates over workspaces in
a folder.
Accessing the iterators in ModelBuilder
Demo 1
Iterating Feature Classes
Demo 2
Iterating For
Demo 3
Iterating Feature Selection
Demo 4
Iterating Multivalue
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
Python Equivalent of Iterators in ModelBuilder
Where to get help? Click
Doc, Tutorials, Book
Questions?
Please fill out the evaluation form online at:
http://www.esri.com/ucsessionsurveys
Session ID - 1914
24th July - Tuesday
1:30PM
2:45PM
Technical Workshop
Analysis and Geoprocessing
ModelBuilder - Getting Started
Ball06 B
3:15PM
4:30PM
Technical Workshop
Analysis and Geoprocessing
Iteration and Branching in
ModelBuilder
Ball06 B
25th July - Wednesday
8:30AM
9:45AM
Technical Workshop
Analysis and Geoprocessing
Geoprocessing with ArcGIS for Server 04
8:30AM
9:45AM
Technical Workshop
Analysis and Geoprocessing
Network Analyst—Automating
Workflows with Geoprocessing
10
10:15AM
11:30AM
Technical Workshop
Analysis and Geoprocessing
Building Tools with ModelBuilder
Ball06 D
1:30PM
2:45PM
Technical Workshop
Analysis and Geoprocessing
Building Tools with Python
28 E
1:30PM
2:45PM
Technical Workshop
Analysis and Geoprocessing
ModelBuilder - Getting Started
Ball06 B
Analysis and Geoprocessing
ModelBuilder Tips and Tricks
Demo Theater Analysis and
Geoprocessing
Exhibit Hall B
2:00PM
3:00PM
Demo Theater
Presentation
26th July - Thursday
8:30AM
9:45AM
Technical Workshop
Analysis and Geoprocessing
Geoprocessing with ArcGIS for Server 09
10:15AM
11:30AM
Technical Workshop
Analysis and Geoprocessing
Building Tools with Python
09
1:30PM
2:45PM
Moderated Paper
Session
Analysis and Geoprocessing
Building Applications Using
ModelBuilder and Python Scripting
27 A
3:15PM
4:30PM
Technical Workshop
Analysis and Geoprocessing
Building Tools with ModelBuilder
Ball06 D
Thank You!!!!