Model Builderand Pythonv 5
Model Builderand Pythonv 5
and Python v5
License
http://creativecommons.org/licenses/by-sa/4.0/
Topics Covered
• ArcToolbox
• Geoprocessing
• Models
• Iterators
• Model Only Tools
• Exporting to Python and ArcPy
• Modeling and Scripting with Python
Why Build Models
• Automate repeated processes
• Flowchart Analysis Process
• Provide documentation for process
• Provide tools others can use to perform analysis
• Standardize workflows
Introduction to Model Builder
• ArcToolbox is made up of
tools, scripts, and models.
• Can be shared
Explore ArcToolbox
15 to 20 minutes
Introduction to Model Builder
and Python
● Foreground
● Focus is on Processing
● Background
● Process is "forked off" and runs by itself
at once
● More Flexible
Results Window
● When you run a Geoprocessing tool your data is saved in the
results window
● Data location
● Time run
● Variables
● Saved in MXD
● Found under
Geoprocessing Menu
● Check messages if
something happened
Results Window
Four Levels
●
Application
●
Tool
●
Model
●
Model process
Environments
●
Workspace
●
Output Coordinates
●
Processing extent
●
XY Resolution &
Tolerance
●
M Values
●
Z Values
●
Geodatabase
●
More…
Application Level
● Create a Toolbox
● 15 to 20 minutes
Exercise
The data for this project comes
from a Project with the
Conasauga River Alliance.
1. You should have a C:\modelbuilder directory. If not please create one. Under that you
should be a data directory. Add all the shapefiles to your display and symbolize
appropriately.
4. Double check and make sure you have the following directories: mxd, output, and toolbox
7. Close ArcCatalog
8. Open ArcToolbox. Explore the tools and scripts that are contained
under the toolbox application.
Exercise
Chapter 3: Modelbuilder
3. Models
● Personal-based
● SDE
Toolboxes and Models
13. Go to your Toolbox, Right-click and select Paste. You have now
saved a copy of the Clip Tool to your Toolbox. If you have a
project where the user only needs certain tools they can be
placed here.
o output
o Distance
o Units
o Side Type
o End type
o Dissolve
o Dissolve Fields
Parameters exposed
Parameter
• Double-clicking the Parameter will allow you to set it.
Parameters can be exposed as variables in
Model Builder
Why expose a Parameter?
Make it a Variable
• Renaming
Parameters
renames them in
the GUI
• 20 Minutes
Exercise
Connection Tool
Connect
Connection
Connect
Preconditions
Preconditions make
sure one element runs
before the other.
Setting a Precondition
• Clip will not run until buffer runs
Precondition
Indicator
Exercise 5
• Connect two tools together using different methods
• 20 Minutes
Exercise
1. Open your MXD from the previous exercise
if you closed it.
8. Click Autoarrange.
10. How many Structures are within 100 Feet of the Streams?
Exercise
13. Double-click the Select by Location. Set the selecting features to be the Output of the
Buffer command
16. Create a New empty Model. A Model doesn't have to contain connected tools. It can
contain just a series of tools that need to be run at the end of a project. Copy the Calculate
Field Tool and the Delete Management tool into your model (using the Search for tools).
20. You don't have to save this model. Just close it.
Introduction to Model Builder
and Python
● Iterators
● Looping
● Calculate Values
● Parse Data
Before Iterators
import arcpy
from arcpy import env
import os
env.workspace = "D:/St_Johns/data.gdb"
fcs = arcpy.ListFeatureClasses("G*")
After Iterators
Iterators
7. Click OK.
Exercise
8. Search and add the Select (analysis) tool.
Bonus:
Take each feature in the Watershed shapefile
and use it to clip out the streams.
Introduction to Model Builder
and Python
● extensive standard libraries and third party modules for virtually every task
Open Source:
QGIS, PostGIS, OSGeo, GDAL, gispython.org
Closed Source:
ArcGIS is probably the biggest
Install of ArcGIS
Python 2.7
● IDLE
● PythonWin
For editing I
prefer notepad or
VIM
Features of Python
• Control Flow
If, For, Else, While
Declare Variables
Work with Integers
Capture Errors
Build modules to import that do specific things
ARCPY is the one you will be most concerned with
Resource Sites
http://www.python.org
http://www.codeacademy.com
http://www.swaroopch.com
http://www.oreilly.com
ArcGIS Help Documentation
ArcPy
#import arcpy;
Interface(s)
Interface(s)
So for ArcUsers.......
● Census = arcpy.GetParameterAsText(1)
If you build a script and want to pass data into it, you
would use: arcpy.GetParameterAsText()
ArcPy
Make mistakes
arcpy.Buffer_analysis("Streams",
"C:\modelbuilder\data\streamstest.sh
p", 200, "FULL", "ROUND", "ALL")
arcpy.Buffer_analysis("Streams",
"C:\modelbuilder\data\streamstest.sh
p", 200, "FULL", "ROUND", "ALL")
DOCUMENT IT
Item description
• Go To Item Description
6. Click Edit.