Model Builder: Difference between revisions
Brian Wilson (talk | contribs) |
Brian Wilson (talk | contribs) mNo edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category: GIS]] | |||
[[Category: Python]] | |||
== Intro == | |||
ESRI ArcGIS 9 has a new tool called the "Model Builder". It lets you build scripts in the form of flow charts and then execute them. | ESRI ArcGIS 9 has a new tool called the "Model Builder". It lets you build scripts in the form of flow charts and then execute them. | ||
The idea is to make programming more accessible for non-programmers. | The idea is to make programming more accessible for non-programmers. | ||
Line 18: | Line 23: | ||
Still, there is a lot you can do within the existing framework. | Still, there is a lot you can do within the existing framework. | ||
== Clumsy programming (with Python) == | |||
One of the remarkable things about ESRI release 9.something is that it now supports code blocks in Python in the Model Builder "Calculate Field" tool. | One of the remarkable things about ESRI release 9.something is that it now supports code blocks in Python in the Model Builder "Calculate Field" tool. | ||
Line 28: | Line 33: | ||
[[Image:Screenshot_CalcField.jpg]] | [[Image:Screenshot_CalcField.jpg]] | ||
All I am doing is taking the data from a field and checking to see if there is anything in it. If there is not I return an empty string. If there is I return the data. This means that when an empty string is read the ESRI tool won't kvetch about it. | |||
Input field names have to be wrapped with (| and !) so my function call is | |||
getNumbr( (!FIELD_NAME!) ) | |||
== Real Programming (with Python) == | |||
As a programmer, the Model Builder felt like a straitjacket the first time I tried it. As a programming medium, it is extremely limited. | As a programmer, the Model Builder felt like a straitjacket the first time I tried it. As a programming medium, it is extremely limited. | ||
Line 36: | Line 46: | ||
The resultant program will perform all the same steps as your "model" version, so all the hooks to the ArcMap/ArcCatalog interfaces are there, and the calls to the various ArcToolbox tools are there in proper order and set up with the right data. | The resultant program will perform all the same steps as your "model" version, so all the hooks to the ArcMap/ArcCatalog interfaces are there, and the calls to the various ArcToolbox tools are there in proper order and set up with the right data. | ||
== | == Open Source Model Builder? == | ||
As much as | As much as I love ESRI, I'd like to be able to do more with Model Builder. | ||
You are not limited to using only ESRI tools in your Models. | You are not limited to using only ESRI tools in your Models. If you can write a Python wrapper around a program you can add it to toolboxes in ESRI ArcGIS. | ||
If you can write a Python wrapper around a program you can add it to toolboxes in ESRI ArcGIS. | |||
But I'd like a 100% Python model builder. | But I'd like a 100% Python model builder. | ||
=== Diagrammers === | |||
Starting point would be an existing diagramming tool. | |||
dia http://live.gnome.org/Dia | dia http://live.gnome.org/Dia | ||
Line 51: | Line 62: | ||
Plugins for dia can be written in Python! http://live.gnome.org/Dia/Python | Plugins for dia can be written in Python! http://live.gnome.org/Dia/Python | ||
pyut http://pyut.sourceforge.net/index.html | pyut http://pyut.sourceforge.net/index.html PyUt is a little UML1.3 diagram editor (class diagram, use-case) with plugins support. (PyUt is working but no longer maintained (except for exceptions).) | ||
gaphor http://gaphor.devjavu.com/ | gaphor http://gaphor.devjavu.com/ | ||
Next would be a toolbox full of open source and ESRI tools. | |||
Latest revision as of 18:07, 12 August 2009
Intro
ESRI ArcGIS 9 has a new tool called the "Model Builder". It lets you build scripts in the form of flow charts and then execute them. The idea is to make programming more accessible for non-programmers.
All flow charts for procedural programs can be simplified to this:
A procedural program starts at the top (at the left in this case) and flows from one box to the next until it completes. Model Builder is a tool for building procedural programs. Indeed, the diagram above was built with Model Builder. Ellipses represent data such as feature classes and rectangles are processes; either spatial like transformations or data processes like simple calculations.
Another way to think of procedural programs is to think of an early computer system. It had a card reader, a central processing unit (CPU), and a printer. Input, processing, output. Put a stack of shape objects into "the card reader", the Geoprocessor CPU performs an operation on them, and then it pushes them out into the "printer" (an output feature class).
With Model Builder, that's really all there is to it. You just build on this model by chaining things together in stages.
You can chain many tools together, and you can use "preconditions" as a simple form of decision-making (branching) but you can't use any advanced iterations or branches. (I suspect that more advanced features are coming down the road.)
Still, there is a lot you can do within the existing framework.
Clumsy programming (with Python)
One of the remarkable things about ESRI release 9.something is that it now supports code blocks in Python in the Model Builder "Calculate Field" tool.
See http://www.esri.com/news/arcuser/0507/files/pythonscript.pdf
You can add scraps of Python or VB (ha!) wherever you need them. For example.
All I am doing is taking the data from a field and checking to see if there is anything in it. If there is not I return an empty string. If there is I return the data. This means that when an empty string is read the ESRI tool won't kvetch about it.
Input field names have to be wrapped with (| and !) so my function call is getNumbr( (!FIELD_NAME!) )
Real Programming (with Python)
As a programmer, the Model Builder felt like a straitjacket the first time I tried it. As a programming medium, it is extremely limited.
But Model Builder has one big advantage for learning to program in the ESRI domain. Once you have a "model" built and working, you can generate the equivalent Python code as output. (Model->Export->To Script->Python). This gives you a starting point for writing your own Python Geoprocessing scripts for use as components in Model Builder, or as standalone tools.
The resultant program will perform all the same steps as your "model" version, so all the hooks to the ArcMap/ArcCatalog interfaces are there, and the calls to the various ArcToolbox tools are there in proper order and set up with the right data.
Open Source Model Builder?
As much as I love ESRI, I'd like to be able to do more with Model Builder.
You are not limited to using only ESRI tools in your Models. If you can write a Python wrapper around a program you can add it to toolboxes in ESRI ArcGIS.
But I'd like a 100% Python model builder.
Diagrammers
Starting point would be an existing diagramming tool.
dia http://live.gnome.org/Dia and dia2code http://dia2code.sourceforge.net/ Plugins for dia can be written in Python! http://live.gnome.org/Dia/Python
pyut http://pyut.sourceforge.net/index.html PyUt is a little UML1.3 diagram editor (class diagram, use-case) with plugins support. (PyUt is working but no longer maintained (except for exceptions).)
gaphor http://gaphor.devjavu.com/
Next would be a toolbox full of open source and ESRI tools.