Tuesday, November 12, 2019

Python and ArcGIS

Although the menu-driven user interface of ArcGIS for Desktop allows for very complicated operations and sophisticated spatial analysis, at some point users will run into tasks that require something more. That’s where Python scripting comes in.

In a nutshell, Python scripting allows you to automate tasks in ArcGIS that would be quite cumbersome using the regular menu-driven interface. For example, consider having to convert 1,000 shapefiles into feature classes in a geodatabase. You could run the appropriate tool 1,000 times, but surely there must be a more efficient and robust way to do this. That’s what Python scripting will do, and you need only a handful of lines of code to carry out this task.

There is no ArcGIS-specific version of the Python language. The FOSS nature of Python makes it possible for Esri to distribute Python with ArcGIS software.. Python is supported on different platforms, including Windows, Mac, Linux, and many others. Python programs can work on any of these platforms with minimal change or sometimes no change at all. Since the ArcGIS for Desktop application runs only on Windows, this may not seem like a big advantage, but the user community for Python is large, in part due to its cross-platform nature. ArcGIS is designed to work with object-oriented languages, and Python qualifies in this respect.

Python scripting has become a fundamental tool for geographic information systems ( GIS ) professionals to extend the functionality of ArcGIS and automate workflows. Several years ago, probably the most widely used approach was to use the built-in VBA (Visual Basic for Applications)
programming tools. Since then, however, Python has emerged as a robust complement and alternative to VBA programming. Starting with ArcGIS 10, the VBA development environment is no longer installed by default, and Esri is actively discouraging the continued use of VBA. Although application development will continue to employ languages such as C++ and .NET, Python has a number of advantages, especially for GIS professionals who are not full-time programmers.

Python is not the only scripting language that can be used with ArcGIS, but it has certainly become the most widely used. This is largely because Python has the ease of use of a scripting language, as well as the programming capability of a complete developer language. Python is included in a typical ArcGIS for Desktop installation. Python has also been directly embedded in many tools in ArcGIS for Desktop. The Spatial Statistics toolbox, for example, consists almost entirely of Python scripts — even though the casual user does not necessarily notice ( or need to ). ArcGIS 10 has seen further integration of Python within the ArcGIS interface, and Esri has officially embraced Python as the preferred scripting tool for working with ArcGIS. Additional enhancements have been introduced in ArcGIS 10.1.

The Python version that is recommended for use with ArcGIS 10.1 is Python 2.7. Although you can download and install any version of Python for free, the installation of ArcGIS 10.1 comes with Python 2.7.2. Although version 2.x still works fine and continues to be widely used, a major new
version of Python was deemed necessary to remove a number of small problems that accumulated over the years and make the language even cleaner.

Although there are a number of differences between versions 2.7 and 3.x, the basic structure of the language has not changed. Despite the availability of version 3.x, ArcGIS 10.1 currently works with version 2.7. If and when version 3.x is adopted as the preferred version for use with ArcGIS, various
utilities are available to convert code between the two versions. It should be noted that although the installation of ArcGIS comes with Python, Esri did not develop Python. Esri relies on the FOSS nature of Python to distribute it with ArcGIS as the recommended scripting language.

In addition, Esri has created functionality in ArcGIS to make it easy to work with Python. However, Python is widely used for tasks other than writing scripts to work with ArcGIS. The added benefit is that as you start learning more about Python you will be able to start using it for both ArcGIS and other tasks as well.
Share:

0 comments:

Post a Comment