Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Overview of this book

Table of Contents (19 chapters)
ArcPy and ArcGIS – Geospatial Analysis with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Definition queries


An important property of Layer objects is the ability to dynamically set definition queries. A definition query is a SQL statement where clause that limits the data available for display, query, or other data operations (buffers, intersections, etc.) to only the rows that match the where clause. Definition queries could be set in an MXD by opening a layer's properties menu and using the Definition Query tab, but here we are concerned with how to add them programmatically. Following is an example of how to do this:

layersList = arcpy.mapping.ListLayers(mxdObject,"",dataFrame)
busStops = layersList[0]
busStops.definitionQuery = "NAME = '71 IB' AND BUS_SIGNAG = 'Ferry Plaza'"

This valuable property can be utilized to reformat the code from Chapter 8, Introduction to ArcPy.Mapping. Remember the complicated second portion of the Chapter8_6.py script, where each bus stop along the 71 Inbound line is selected and its geometry is written to another feature class? Instead, we can...