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

Using arcpy.mapping to control Layer objects


Arcpy.mapping Layer objects are used to control the properties of layers within map document data frames. Turning layer visibility on and off, adding new layers, and adjusting layer order can all be accomplished using Layer object properties.

Creating Layer objects involves passing parameters to the arcpy.mapping.ListLayers() method. As discussed in Chapter 8, Introduction to ArcPy.Mapping, when referencing an arcpy.mapping.MapDocument object, the layers within the map document can be accessed using zero-based indexing. This code will print the list of Layer objects contained within the data frame called Layers in an MXD:

import arcpy
mxdPath = r'C:\Projects\MXDs\Chapter9\MapDocument1.mxd'
mxdObject = arcpy.mapping.MapDocument(mxdPath)
dataFrame = arcpy.mapping.ListDataFrames(mxdObject, "Layers")[0]
layersList = arcpy.mapping.ListLayers(mxdObject,"",dataFrame)
print layersList

The layers within the data frame called Layers, have been assigned...