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

Inspecting and replacing layer sources


The first and most important arcpy.mapping module use is to identify and fix the broken links between layers in a map document and their data sources. Layer symbology and GIS data storage are separated, meaning that layer data sources are often moved. Arcpy.mapping offers a quick solution, though imperfect.

This solution depends on a number of methods included in the arcpy.mapping module. First, we will need to identify the broken links, and then we will fix them. To identify the broken links we will use the ListBrokenDataSources() method included in arcpy.mapping.

The ListBrokenDataSources() method requires an MXD path to be passed to the MapDocument() method of arcpy.mapping. Once the map document object has been created, it is passed to the ListBrokenDataSources() method, and a list will be generated containing layer objects, one for each layer with a broken link. The layer objects have a number of properties available to them. Using these properties...