Book Image

ArcGIS Blueprints

By : Donald Eric Pimpler, Eric Pimpler
Book Image

ArcGIS Blueprints

By: Donald Eric Pimpler, Eric Pimpler

Overview of this book

This book is an immersive guide to take your ArcGIS Desktop application development skills to the next level It starts off by providing detailed description and examples of how to create ArcGIS Desktop Python toolboxes that will serve as containers for many of the applications that you will build. We provide several practical projects that involve building a local area/community map and extracting wildfire data. You will then learn how to build tools that can access data from ArcGIS Server using the ArcGIS REST API. Furthermore, we deal with the integration of additional open source Python libraries into your applications, which will help you chart and graph advanced GUI development; read and write JSON, CSV, and XML format data sources; write outputs to Google Earth Pro, and more. Along the way, you will be introduced to advanced ArcPy Mapping and ArcPy Data Access module techniques and use data-driven Pages to automate the creation of map books. Finally, you will learn advanced techniques to work with video and social media feeds. By the end of the book, you will have your own desktop application without having spent too much time learning sophisticated theory.
Table of Contents (18 chapters)
ArcGIS Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Overview of the Arcpy data access module


The ArcPy data access module, known as arcpy.da, provides capabilities for working with tables and feature classes. Through the use of various cursor objects, you can select, insert, update, and delete records from tables and feature classes. The data is held as an in-memory copy of the data. This module also supports edit sessions, NumPy array conversions, and support for versions, domains, and subtypes.

ArcPy data access classes

The primary classes in this module deal with the various types of cursors that can be created. Cursor objects are the in-memory copy of data pulled from a table or feature class. The data access module includes three types of cursor objects including SearchCursor, InsertCursor, and UpdateCursor. Each has a corresponding constructor function that is used to create the object. There are some additional classes that support edit sessions, domains, versions, and replicas.

The SearchCursor class is used to create read-only access to tables and feature classes. The constructor function for this class provides parameters for defining the feature class or table associated with the object, a list of fields to return, and an optional WHERE clause to limit the records returned in this object.

The InsertCursor class is used for situations where new records need to be added to a table or feature class. The constructor function for this class provides parameters for defining the feature class or table associated with the object along with a list of field names to be returned. The only method on this class is insertRow(). This method inserts a new row into a table or feature class.

The UpdateCursor class is used to edit or delete records in a table or feature class. The constructor function for this class provides parameters to define the feature class or table associated with the object along with a list of field names to be returned and an optional where clause that can be used to limit the records returned. There are two primary methods on this class: deleteRow() and updateRow().

All cursors support the concept of geometry tokens that allow you to return a portion of the geometry for a feature class rather than the default of returning all geometry. In situations where you have highly detailed polygon or polyline datasets, this can increase the performance of cursors by limiting the amount of data returned when the object is created.

Another important object in the data access module is the Editor class. Through this class, you can enable edit sessions against tables and feature classes. The functionality provided through this class is the same as that provided through the Edit toolbar in ArcMap.

Several additional classes including Domain, Version, and Replica provide a limited set of read-only properties for these objects. For example, the Domain class has read-only properties that will return the coded values or range for a domain, name, split policy, merge policy, domain type, and description. There are read-only, so you can't make any changes to the Domain, Version, or Replica objects.

Arcpy data access functions

The data access functions can be grouped into categories that provide lists of data, NumPy array conversion capabilities, and a utility function to generate data names in a Catalog tree.

List functions

There are a handful of list functions that return a list of data. These include ListDomains(), ListFieldConflictFilters(), ListReplicas(), ListSubtypes(), and ListVersions(). Most are self-explanatory, but the ListFieldConflictFilters() requires some explanation. This function lists the fields in a versioned feature class or table that have field conflict filters applied.

NumPy Array conversion functions

Tables and feature classes can be converted to NumPy arrays through the TableToNumPyArray() and FeatureClassToNumPyArray() functions. Existing NumPy arrays can also be converted to tables and feature classes through the NumPyArrayToTable() and NumPyArrayToFeatureClass() functions. There is also an ExtendTable() function to join a NumPy array to another table based on a common attribute field.

The Walk() function generates data names in a Catalog tree and can navigate top-down or bottom-up. Each folder or workspace in the tree contains a Python tuple object consisting of the directory path, directory names, and filenames. This function is similar to the Python os.walk() function, but with the added capability of being able to investigate the contents of a geodatabase structure. The os.walk() function doesn't have this ability.