GEOG 485:
GIS Programming and Software Development

4.8 Limitations of Python scripting with ArcGIS


In this course, you've learned the basics of programming and have seen how Python can automate any GIS function that can be performed with the ArcGIS toolboxes. There's a lot of power available to you through scripting, and hopefully you're starting to get ideas about how you can apply that in your work outside this course.

To conclude this lesson, however, it's important to talk about what's not available through Python scripting in ArcGIS.

Limits with fine-grained access to the "guts" of ArcGIS

At ArcGIS, Python interaction with ArcGIS is mainly limited to reading and writing data, editing the properties of map documents, and running the tools that are included with ArcGIS. Although the ArcGIS tools are useful, they are somewhat black box, meaning you put things in and get things out without knowing or being concerned about what is happening inside. If you want a greater degree of control over how ArcGIS is manipulating your data, you need to work with ArcObjects.

ArcObjects can be thought of as "the building blocks" of ArcGIS. In fact, an analogy with the children's Lego building bricks works well to describe ArcObjects: Programming with ArcObjects is akin to having an enormous selection of Legos of all shapes and sizes, whereas Python scripting is like working with a kit containing some large prefabricated pieces that make it much easier to construct a particular final product.

Because of the sheer amount of functionality and objects available to you, ArcObjects is more challenging to learn than simple Python scripting. Usually, an equivalent task takes many more lines of code to write in ArcObjects than in a Python script. However, when you use ArcObjects, you have much greater control over what happens in your program. You can take a small piece of functionality and use it without the overhead of a tool or all the other parameters that come with a tool.

Limits with user interface customization prior to ArcGIS 10.1

In this course, we have done nothing with customizing ArcMap to add special buttons, toolbars, and so on that trigger our programs. Our foray into user interface design has been limited to making a script tool and toolbox. Although script tools are useful, there are times when you want to take the functionality out of the toolbox and put it directly into ArcMap as a button on a toolbar. You may want that button to launch a new window with text boxes, labels, and buttons that you design yourself.

In ArcGIS 10.x, if you want to put custom functionality or programs directly into ArcMap, you need to use Visual Basic for Applications (VBA), C ++, or a .NET language (VB.NET or C#) working with ArcObjects. The functionality may be as simple as putting some custom actions behind a button (zoom to a certain bookmark, for example), or you may open a full-blown program you develop with multiple forms, options, and menus. The aforementioned languages have IDEs in which you can design custom user interfaces with text boxes, labels, buttons, and so on.

New Python add-in functionality since ArcGIS 10.1

To allow a greater degree of interactivity between the ArcMap user interface and Python scripts, at ArcGIS 10.1 Esri introduced the concept of a Python add-in. Add-ins allow you to attach Python logic to a limited set of actions you perform in ArcMap, such as zooming the map, opening a new map document, or clicking a button on a custom toolbar. For example, you might create an add-in that automatically adds a particular set of layers any time someone pushes a certain button on your toolbar.

With Python add-ins, you get access to a number of user interface elements to use as a front end to your Python scripts, including toolbars, buttons, menus, combo boxes, and basic file browsing and Yes/No confirmation dialog boxes. There's also a set of common events that you can detect and respond to in your code, such as the map opening, the map extent changing, or the spatial reference changing. Although this is far from the full realm of ArcObjects and .NET customization possibilities, it gives a lot more possibilities than were available in previous versions of ArcGIS.

The nice thing about add-ins is that they are easily shareable. You download the Python Add-In Wizard from Esri, and it helps you prepare and package up your add-in into a .esriaddin file. Other people with ArcGIS can then install the add-in from the .esriaddin file.

Working with Python add-ins is currently not included in the scope of this course, but you can learn all about them in the help book ArcGIS Desktop Python add-ins. After reading this material and getting a basic understanding of what's required to create add-ins, you're welcome to incorporate them into your final project if you have ArcGIS 10.1 or later (and you all should :)) and you are confident that you can work somewhat independently to test and create the add-ins. If you have struggled in the course, I recommend that you wait until after completing Geog 485 to further explore add-ins, so that you can give them the necessary amount of time and testing.