You are on page 1of 10

Slide 1

The Geoprocessing Framework and Model Building
Programming ArcGIS Jerry Davis

We'll start our look at programming tools by exploring the geoprocessing framework, and learn what we can do with ModelBuilder, a tool for creating a flow chart of a process. Model Building is good for many geoprocessing tasks, and provides a visual way to design our geoprocessing tasks. For many tasks, this may be all we need. And after we explore scripting, we'll find that using ModelBuilder and Scripting together works better than either method on its own.

colleagues. The idea of a model isn't new with ModelBuilder. either done by yourself. or do the boring stuff by letting the computer run each step in succession. so perfect for automation ArcGIS includes several geoprocessing methods • • • • Map Algebra: functions are tools ArcToolbox: system tools. or published in a research journal.Slide 2 Modeling. So learning multistep geoprocessing methods lets us both do the interesting stuff using multiple scenarios. Data analysis and modeling is more interesting. scripts and models Command windows (two different kinds) Scripting Most of GIS work is data management. needed for: • Coding a model to predict a result • Running any series of data processing steps Like managing datasets … where we spend most of our time in GIS – necessary but tedious. and might involve a model developed by other studies. Geoprocessing and Automation “Geoprocessing” refers to using tools to process GIS data • And the methods used to automate these tools into multiple steps Automation lets us run multiple steps. Developing models is a major part of scientific research. . We have to do both. Coding a model is what we're doing here. where one might try to predict a phenomenon with collected data – often involving statistical probabilities.

where each statement might process an input into an output.Slide 3 AML Model Site suitability model coded in AML with map algebra • Very simple once you know map algebra • Run from the command prompt with “&run suitmodel Something like a site suitability model might involve application of a weighting scheme applied to input datasets and field values. such as with AML or Python. successive statements might take those previous outputs as inputs. and so on… . and lead to new outputs. This can be done in a script. in order to predict an output input data.

There is also a new command prompt. and models. I don't see its advantage. Many tools come with the software.Slide 4 ArcToolbox Access to system tools. each of which might contain toolsets. scripts. scripts and models • Each can be run by double-clicking • Each can be used as a step in a model • Models and Python scripts can be edited Right-click script… Edit Each tool can also be run as a command • Not the same as an Arc command • A new command window is used The ArcToolbox is organized by toolboxes. thus harder to remember. . but you can add your own toolboxes with scripts and models. The commands are longer in format. Includes system tools. I would tend to only use tools in python scripts or modelbuilder.

Buffer_analysis ("roads". 100) We'll explore geoprocessing tools in the next section. For now.client gp = win32com. .Slide 5 Geoprocessing tools in Python Can be run as steps in a script • if you’ve created a geoprocessor object with a bit of code at the top Environment settings and tools use geoprocessor • Set workspace • Get usage of ArcToolbox tools in script syntax import win32com.workspace = "d:/workspace/raster/HMBarea" gp. just note that geoprocessing tools can also be accessed here. "Buff100".Dispatch("esriGeoprocessing.GpDispatch.1") gp.client.

that part will have shadows underneath the elements. If from ArcMap. The little "P" indicate model parameters we've selected to use as model inputs and outputs. output datasets (green ellipses – they can also be used as inputs). ModelBuilder is very easy to understand in that it is visual. connectors with arrows showing what goes where. models or script tools). Shadows: After you've successively run part of the model.Slide 6 ModelBuilder Runs from ArcMap or ArcCatalog. nothing has been run yet. because some tools can be tricky to use – especially the reclassify and weighted overlay shown here. The various elements of a model are input datasets (blue ellipses). Models are created and stored with ArcToolbox. In this figure. Coloring: If your model elements are not colored in. input variables (light blue ellipses). . layers from the map can be used as input. labels. they aren't ready to run. processes (yellow rectangles that might be system tools. You do need to be careful in using it.

Slide 7 Selecting inputs for a process Dataset Inputs • Layers (yellow polygons) • Model Elements (blue) Note the elements that are shadowed. but you can't control which parameter you're providing with it. shown as cyan ellipses Note that the same dataset may be both an ArcMap layer and a model element. Variables • Numbers. Some tools only have one input.. and should make sense for your use of the model. . Using the connector line is another option. Choosing which one depends on how you want to use it. so I would check its result by opening the process anyway. etc. meaning they've already been run. so you can probably get away with it there.

Optionally add a layer so it becomes a model element 3. . If you don't run a previous step first before you try to reclassify the results. and have completed the entire model. Submodels should also be run before they are use. you need to use File/Validate Entire Model to re-initialize it. like the reclassify tool and the weighted overlay tool. the reclassify tool won't know what it's trying to classify. Before creating the next step. require this in order to develop a sensible classification. To re-run the model. Open the tool to provide its inputs • You can also use a connector.Slide 8 Process of creating a model 1. 4. Once you've gotten all of your processes run. You'll see this especially if you're trying to use weighted overlay with text fields. Re-running a model with new inputs – allowing you to test the effect of variations in those inputs – is an important part of modeling. which includes a kind of classification itself. Add a tool. derived by a previous reclassification. you can change any of the inputs and run the whole thing again. It doesn't know what that field is or its value until a previous step has been run. 2. but opening the tool is more reliable. This is important not only for reclassifying. run the previous tool • Some tools. but also for the weighted overlay.

If models are used inside other models. and other models. then export the model to a script. script tools.Slide 9 Scripts as tools in Model Builder Scripts can be used as tools in ModelBuilder • In this example. sun angle and azimuth variables are defined for input to hillshade tool Models can also be used as tools in a model • Allows for creating complex models Models can also be exported as Python scripts ModelBuilder can work with system tools (hammer icon). . input and output parameters are going to be important to define. We'll learn how to create script tools later. One way of learning how to use geoprocessing tools in python is to create a simple model that uses them.

Slide 10 Model Parameters For processes in ModelBuilder. One of the things we'll need to define in the script. we'll learn how to write scripts in Python. • Think of a model as a filter. you can define inputs and outputs as Model Parameters. with inputs and outputs. just as a system tool creates a result. which might have an output model parameter that becomes the result of the model. In the next section of the class. Then we'll learn how to make these scripts work as script tools. so we can run them from either ArcToolbox or ModelBuilder. • Purpose is to allow a model to have inputs and outputs • Especially useful for submodels. then in the script tool. are input and output parameters. . Model parameters are especially important when using models inside other models.