Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Programming ArcGIS with Python Cookbook, Second Edition

You're reading from   Programming ArcGIS with Python Cookbook, Second Edition Over 85 hands-on recipes to teach you how to automate your ArcGIS for Desktop geoprocessing tasks using Python

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781785282898
Length 366 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Eric Pimpler Eric Pimpler
Author Profile Icon Eric Pimpler
Eric Pimpler
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Fundamentals of the Python Language for ArcGIS 2. Managing Map Documents and Layers FREE CHAPTER 3. Finding and Fixing Broken Data Links 4. Automating Map Production and Printing 5. Executing Geoprocessing Tools from Scripts 6. Creating Custom Geoprocessing Tools 7. Querying and Selecting Data 8. Using the ArcPy Data Access Module with Feature Classes and Tables 9. Listing and Describing GIS Data 10. Customizing the ArcGIS Interface with Add-ins 11. Error Handling and Troubleshooting 12. Using Python for Advanced ArcGIS 13. Using Python with ArcGIS Pro A. Automating Python Scripts B. Five Python Recipes Every GIS Programmer Should Know Index

Using the ArcGIS Python window

In this recipe, you'll learn how to use the ArcGIS Python window. In the last section, you learned how to use the IDLE development environment for Python, so this section will give you an alternative to write your geoprocessing scripts. Either development environment can be used, but it is common for people to start writing scripts with the ArcGIS for Desktop Python window and then move on to IDLE or another development environment when scripts become more complex.

The ArcGIS Python window

The ArcGIS Python window is an embedded, interactive Python window in ArcGIS for Desktop 10.x. It is newer and ideal for testing small blocks of code, learning Python basics, building quick and easy workflows, and executing geoprocessing tools. For new programmers, the ArcGIS Python window is a great place to start!

The ArcGIS Python window has a number of capabilities in addition to being the location to write your code. You can save the content of the window to a Python script file on a disk or load an existing Python script into the window. The window can be either pinned or floating. While floating, the window can be expanded or contracted as you wish. The window can also be pinned to various parts of the ArcGIS display. You can also format the font and text colors displayed in the window by right-clicking on the window and selecting Format.

Displaying the ArcGIS Python window

The Python window can be opened by clicking on the Python window button on the Standard ArcGIS for Desktop toolbar, as seen in the screenshot. This is a floating window, so you can resize as needed and also dock it at various places on the ArcMap interface:

Displaying the ArcGIS Python window

The Python window is essentially a shell window that allows you to type in statements one line at a time, just after the >>> line input characters. On the right-hand side of the divider, you will find a help window.

You can load an existing script by right-clicking inside the Python window and selecting Load… from the menu. You can also format the font and text colors displayed in the window by right-clicking on the window and selecting Format. You will be provided with White and Black themes; you can select fonts and colors individually:

Displaying the ArcGIS Python window

Click on the Set Black Theme button to see an example. If you spend a lot of time writing code, you may find that darker themes are easier on your eyes:

Displaying the ArcGIS Python window

The ArcGIS Python window also provides code-completion functionalities that make your life as a programmer much easier. You can try this functionality by opening the ArcGIS Python Window and typing arcpy followed by a dot on the first line. ArcPy is a module-oriented package, which means that you access the properties and methods of an object using a dot notation. Notice that a drop-down list of available items is provided. These are the tools, functions, classes, and extensions that are available for this particular object. All objects have their own associated items, so the list of items presented will differ depending on the object that you have currently selected:

Displaying the ArcGIS Python window

This is an auto-filtering list, so as you begin typing the name of the tool, function, class, or extension, the list will be filtered according to what you have typed:

Displaying the ArcGIS Python window

You can choose to have the Python window auto-complete the text for you by selecting an item from the list using your mouse or by using the arrow keys to highlight your choice, and then using the Tab key to enter the command. This autocompletion feature makes you a faster, more efficient programmer. Not only is it easy to use, but it also dramatically cuts down the number of typos in your code.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime