Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By : Eric Pimpler
Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By: Eric Pimpler

Overview of this book

The book kicks off with the fundamentals of starting to use Python with ArcGIS, followed by recipes on managing map documents and layers, including how to find and fix broken data links in these files. In the second part of the book, you will learn to create custom geoprocessing tools and how to use the Attribute and Location tools to select specific features. The third part of the book covers topics for advanced users including the REST API, and also teaches you how to use Python with ArcGIS Pro. The book finishes with appendices covering how to automate Python scripts, and the five things that should be at the back of every GIS programmer's mind.
Table of Contents (22 chapters)
Programming ArcGIS with Python Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a tool add-in


Tool add-ins are similar to buttons with the exception that tools require some type of interaction with the map. The zoom-in tool, for example, is a type of tool. Tools should be placed inside a toolbar or tool palette. The properties similar to those of a button. You'll also need to edit the Python script.

Getting ready

The Tool class has a number of properties, including cursor, enabled, and shape. The cursor property sets the cursor for the tool when it is clicked on, and is defined as an integer value corresponding to the cursor types, as follows:

By default, tools are enabled. This can be changed, though, by setting the enabled property to false. Finally, the shape property specifies the type of shape to be drawn and it can be a line, rectangle, or circle. These properties are typically set inside the constructor of the tool, which is defined by the __init__ method, as shown in the following code example. The self object refers to the current object (a tool in this...