You are on page 1of 97

Customizing

your ArcMap
Experience
UW Hydro Compu:ng Workshop
Liz Clark
David Wampler
3 Feb 2014
Intro to Model Builder
Model Builder Todays Topics

* Overview of Model Builder


* Adding Tools to Model Builder
* Advanced op:ons in Model Builder
* Model Builder combined with Python scrip:ng
Overview of Model Builder
* Provides a mechanism for construc:ng new
tools and processes in an easy, semi-automated
fashion
* Much more robust than batch
* Very useful for linking many tools together
* Also useful for itera:ng tools mul:ple :mes
* Synergizes with python scrip:ng
Its good conven:on to create a new toolbox
to place your custom models in, so that you
can keep track of them.

This icon creates a


new empty toolbox
Model proper:es gives some very useful
overviews of your model, and allows you to
specify model-specic Environments
You can also set Model-only Environments (such as processing extent!),
or set how o\en your model should iterate (although I prefer using
Iterators specically for that).
Ways in which Model Builder is useful
I use model builder in two ways
When I want to queue a bunch of tools to run
together, so I dont have to manually proceed
a\er each step (which o\en means I have to sit
there and wait for tools to end wasted :me!
Nice when you dont have to verify the results of each
step they are either unimportant, or youre condent
they will run correctly
When I want to create a new tool to run mul:ple
:mes, now or in the future (more on this later)
Running mul:ple tools at once
Our example recrea:ng the homework
(well, most of it) in Model Builder
Hopefully everyone is
familiar with the data
they are looking at
here! We have six
separate DEMs, and a
Polygon for our study
area.

Click this icon to quickly


open up Model Builder.
Click and drag tools, models, or scripts from
the ArcToolbox into the Model. You can also
drag layers from the Table of Contents, or
search results. Convenient!
You can now double-click on a tool you
added to your model to adjust the
parameters. You can see tools in Model
Builder usually look exactly like you are used
to.
Simply add the parameters as needed
And Model Builder will graphically display
what you have chosen!

Inputs here are


blue circles
Tools are yellow
boxes

Outputs are
green circles
Select this icon to
link tools together
Dene what role
the linked object
will have
Now Ive added the rest of the
tools we will need. The connector
tool does most of the rest, with
some personal oversight on extra
parameters (like the z-limit on the
Fill tool)
This is an op:onal
output it will
remain white as long
as we dont use it
Model Builder usually does a good
job showing progress through a
model run.
As you can see, layers
were created at each
step of our model. You
can add the Delete
tool to remove these
during the model run if
you dont want them.
Or, save junk les to a
specic folder to
delete later

If you decide to keep the


tool, name it something
memorable so you know
what it is.
Also
There is more you can do that we wont show
here. You can set Model Builder to
automa:cally add an output to the Table of
Contents, and you can even dene the exact
Symbology of your output layer (which can
some:mes be a huge :me saver).
Ways in which Model Builder is useful
I use model builder in two ways
When I want to queue a bunch of tools to run
together (just went over)

When I want to create a new tool to run mul:ple
:mes, now or in the future.
Either a useful simple tool that combines tools or
op:ons I use o\en
A tool that I intend to run repeatedly all at once, which
can save MANY hours of work
Lets look at a more advanced example now
Addi:onal Model Builder Func:ons
* Iterators
* Parameters
* Loops
* Sub-models
* Model-only tools
* Randomness
Iterators
Can only have one per model (sub-models allow for
nested iterators)
Very powerful
You can directly access the in_memory workspace in
Model Builder for much faster tool runs over small
data les. We wont cover that here though.
Careful about saved-le-explosions
Either set up your model to overwrite les you
wont need as it runs, or make sure you save them
in a loca:on you can easily nd a\erward to
delete.
Iterators are your friend!
You can iterate almost
anything using them!
G:\ReMos01 has over 10,000 rasters in it (eventually it will have over 20k).
Nobody (including myself) would be happy with me spending all my :me at
work running a tool by hand over 10,000 :mes. Itera:on solves that!

You can set the itera:on to be recursive, and only grab les with a dened
wildcard in them (ex: *DEM_30m*), or of only a specic raster type.
Iterators are
orange hexagons
Variables are light
blue ovals. You can
(and probably should)
rename these,
especially if you have
mul:ple variables in a
model
Variables can be iden:ed by
surrounding them with
percent signs (%). This will
prevent our new tool from
overwri:ng each output
raster with the next!
Click run and let the model
iterate over everything it (You can also
needs to allowing you do save the model
get other work done and and run it as a
save hours of :me tool like any
other outside
of Model
Builder)
Addi:onal Model Builder Func:ons
* Iterators
* Parameters
* Loops
* Sub-models
* Model-only tools
* Randomness
Parameters
Give your tool some variable elds that are
dened uniquely each :me the tool is run
Common parameters are input workspace,
input les, output workspace and name, etc.
Any :me you run a tool in ArcMap,
parameters are what you ll in
Can be required or op:onal, same as with
other tools
Right-click on the data you
want to be a variable dened
at the start of a tool run, and
select Model Parameter
The input directory is now a Model
Parameter. It is defaulted to
ReMos01 (because we set it to
ReMos01 before dening it as a
Model Parameter). Upon running
this tool from the Toolbox, the user
will have to dene what the input
directory is.
The output name is a
Model Parameter now
too. Risky to leave the
variable (%Name%) in
there but lets not
worry about xing that
now.
Now lets create another variable so
we can set the output cell size to be
a Model Parameter too! Right click
somewhere in the white space of
the model
We now have a
variable that is a
double, and it is
called Double. We
can point to it using
the typical variable
iden:ers (%Double
%)
And set it as a
Model Parameter
Our model can now be directly opened from the Toolbox!
The three parameters we set have to be entered for the
tool to run, but they have preset defaults (which you may
or may not want).

Ignore the red x my external hard drive disconnected
during this.
Addi:onal Model Builder Func:ons
* Iterators
* Parameters
* Loops
* Sub-models
* Model-only tools
* Randomness
Loops (Feedback Loops)
Useful for situa:ons where an output
becomes a new input for the tool
Necessary for any sort of cellular
automata (but useful in other ways too)
Must, of course, be careful to ensure
they actually stop
Sejng up a cellular automata (were gonna do this fast)
Running once is ne to test our
methodology here, but this tool is
only really useful if we can use the
output as the input for the same tool
and iterate through that process a se
number of :mes.
Using the connect tool to point the
output data back into the original
input data creates a Feedback
Loop. Careful! The way this is
wriken our original data will be
overwriken! Some:mes that might
be good, but lets say not here
Lets x that by
crea:ng a For
Loop. This will
prevent our tool
from running
forever AND No:ce we now
allow us to save have the Value
each output variable in our
without output name,
overwri:ng the so itll save
input uniquely each
run through.
Addi:onal Model Builder Func:ons
* Iterators
* Parameters
* Loops
* Sub-models
* Model-only tools
* Randomness
Sub-models
You can use your own models (or the models
of others) as parts of future models
Model Builder limits one iterator per model.
You can, however, add a model as a sub-
model in order to nest iterators
It will be helpful if you stay organized in your
custom models, so each has a dis:nct purpose
that lends well to combining with others (if
you ever plan to do so).
Addi:onal Model Builder Func:ons
* Iterators
* Parameters
* Loops
* Sub-models
* Model-only tools
* Randomness
These are tools that ll useful roles that are otherwise dicult to achieve
in Model Builder. These akempt to help re-create some of the
func:onality that Python scrip:ng has, and as such are not intended to be
used with Python scrip:ng. Calculate Value is especially powerful,
analogous to Raster Calculator.

Calculate Value can return a variable


based on any number of input
variables. Many calcula:ons can be
run on input values, including if/else
statements and anything from the
python math module (a lot!).
Random numbers can also be
included in these calcula:ons. It can
handle almost any data type ArcMap
knows about.
Addi:onal Model Builder Func:ons
* Iterators
* Parameters
* Loops
* Sub-models
* Model-only tools
* Randomness
Randomness
There are mul:ple ways you can include
randomness in your Model. One easy example
is to create a Random Number Generator
Variable.
Model Builder to Python scripts
You can convert your Models directly into
Python scripts
You can also import Python scripts into Model
Builder as addi:onal tools
Now to add our
script back into
ArcMap

Dont forget this makers if


you are moving les
between computers!
If your script has any parameters, you
need to dene them here
Model Builder to Python scripts
Anything you can do in Model Builder, you can
do in Python but Model Builder is an easy
way to make your life easier, especially when
you know ArcMap already has the capacity to
do what you need.
Intro to ArcPython
Benets of python scrip:ng
Can do any of your normal python func:ons
and call just a single or series of GIS func:ons
Makes it easy to repeat a series of func:on calls
(like from geoprocessing or ArcToolbox) on a new
data set or to keep track of what you did
Par:cularly useful if you need to do loops or
calculate value based on non-GIS data sets
A helpful overview
Tes:ng and wri:ng snippets in ArcMap
Python window and help box
Auto-comple:on
Environment sejngs:
Arcpy.env.workspace = c:/temp/my_directory/
Determines where les saved or wriken
Can also set area of interest, coordinate system
for output dataset, and cell size of new raster data
set.
Func:ons
ArcPy has func:ons in addi:on to the tools that
support geoprocessing
Examples:
List datasets
Retrieve dataset proper:es
arcpy.Describe(lename).spa:alReference
Spa:al Reference class descrip:ons
Check if data exists:
arcpy.Exists(lename)
Validate table name
Modules
arcpy.mapping automate map produc:on,
can build complete map books by crea:ng and
managing PDF documents, update metadata
on mxd document
arcpy.sa (spa:al analyst)
arcpy.ga (geosta:s:cal analyst)
Gejng the right syntax
Search func:on
Auto-help
Auto-comple:on
Example based on homework
Set workspace where you want to look for and save les
arcpy.env.workspace="C:/users/student/Downloads/SRTM_Sierra/
Allow les to overwrite
arcpy.env.overwriteOutput="True

Check spaAal reference of one of the data sets
inle1="srtm_12_04/srtm_12_04.:f"
sr=arcpy.Describe(inle1).spa:alReference
go to website
print sr
print sr.name
print sr.domain

Example con:nued
Mosaic the 6 Ales
look up mosaic to new raster in search (or toolbox) and drag to window
you can run command and copy python snippet
you can see the list of required input
import glob
lelist = glob.glob(arcpy.env.workspace + '/*/*.:f')
s = ';'.join(lelist)
arcpy.MosaicToNewRaster_management(s,ws,"srtm_mos","#","32_BIT_FLOAT","#","1","LAST",
"FIRST")

Check mosaic's coordinate system
print arcpy.Describe("srtm_mos").spa:alReference.name




Example con:nued
Project raster
use tool to get snippet or assign .prj le or projecAon from exisAng data set
If we wanted to project each input dem separately, we could loop over each DEM:
for dem in lelist:
demprj = dem.split(".")[0]+'_prj'
demhs = dem.split(".")[0]+'_hs'
arcpy.ProjectRaster_management(dem,demprj,....)
result=arcpy.sa.Hillshade(demprj)
arcpy.CopyRaster_management(result,demhs)
arcpy.CopyRaster_management("outrast",ws+"sierra_hs)

Calculate hillshade map
outrast=arcpy.sa.Hillshade("sierra_prj")
print outrast
arcpy.CopyRaster_management("outrast",ws+"sierra_hs")
Wri:ng code to execute outside of
ArcMap
Basically like any other Python script, you just
import the arcpy module
Par:cularly good idea to dene your
workspace
Requires the ArcGIS license, so you can only
run these on the PCs
Advice Regarding Figures
Advice Regarding Figures
Some:mes, you may need to make a gure that
you will show to others
Whether you are making gures for a paper, an
ar:cle, an email, or a future job, there are
conven:ons to follow
Informa:ve and concise gures may determine
how many people glance at your ar:cle, versus
how many actually read your work.

Advice Regarding Figures
In my experience the two most common
mistakes with gures:
Adding informa:on the reader does not need (or
want) to know.
Making informa:on the reader should know hard to
understand.
This is a problem with ArcMap there is o\en so
much informa:on you can add, it can be hard to
know when to stop!

Advice Regarding Figures
Other things to think about
Color choice contrast is good, make sure text is
readable above background, dont use color
schemes that are very dierent from what is
considered normal for your data.
Try to reduce white space in your gure usually
you can re-arrange items in your gure to save
space.
Is red for low
eleva:ons and blue White text hard
for high eleva:ons to see over
intui:ve? Probably white polygon
not. borders

What is GRID_CODE?
Unimportant to readers

No symbol for smallest


streams, should be
removed

Value is not needed. Is


Streamline Mosaic the
most descrip:ve name for
this DEM? What part of scale
does 25 point to?
Preky good job of
lling up white Black text and
space with extra white boundaries
informa:on works preky well

Labels on legend are


beker than last one
HUGE amount Green text hard
of wasted to see!
white space

Specic eleva:ons
dont seem important
on this map so a good
choice to label DEM
with High and Low
Some:mes it is worth considering what your gure will look like in greyscale, if
you expect it might be printed out o\en.
Not so good original colors were too light. Underlying DEM dierences
overwhelm color dierences on much of this map.
What about this one? Lets ignore the poor choice of leaving colors on the
bathymetry DEM which conict with the colors on the legend.
Thats beker probably as good as we can expect from turning a color gure
into greyscale!
Advice Regarding Figures
So given all of that
There is certainly a lot you could think about when
designing a gure!
Really just remember the most important thing to keep
in mind is what the purpose of your gure is. What do
you want the reader to understand from it? Make sure
that data is clearly marked and easy to nd.
Common map items are a :tle, a scale bar, a north
arrow, and a legend.
Everything else can usually be reduced or removed in a
gure.
You can always have other people look over your gure.
A fresh viewpoint can be a huge help!
Other GIS resources
hkp://gis.washington.edu/ -- links to GIS data repositories,
UW courses on GIS, lis:ng of drop-in computer labs on
campus and link to free ESRI Virtual Campus courses
For U.S. data: Na:onal Map: Data include: Eleva:on,
Orthoimagery, Hydrography, Geographic Names, Boundaries,
Transporta:on, Structures, and Land Cover, while products
include: US Topo and Historical Topo Maps.
SRTM DEM: hkp://srtm.usgs.gov/index.php
UMD Land cover data: hkp://glcf.umd.edu/data/
HydroSHEDs global ow networks, stream les, and basin
boundaries: hkp://hydrosheds.cr.usgs.gov/index.php