Exercise 5 - Mapping
Exercise 5 - Mapping
Because the creation of sixteen individual map pages would be time consuming, use the ArcPy Mapping module and data driven pages functionality to create
this map book in PDF format.
In the ArcMap Python window, use the ArcPy Mapping replaceWorkspaces function to change the data source of the layers from the old shapefile directory to
the new geodatabase.
Use the replaceWorkspaces function of the map document object to correct the data source problem. Use the current map path to define the shapefile
directory and geodatabase path, both of which were stored relative to the map document (alternatively, just enter the actual paths to the shapefile
folder and the geodatabase).
Use the arcpy.RefreshTOC() function to refresh the table of contents to remove the broken data source icons.
Save the map document using the mxd.save() function
Export this title page to a PDF using the ExportToPDF function
Close ArcMap
To create a map book, a map document with data driven pages enabled is also needed. Data driven pages gives you the ability to generate multiple pages by
taking a single map layout and iterating over a set of map extents. Any feature layer, point, line or polygon can be used to define the extents. This layer is
referred to as the index layer and is the "data" that "drives the pages," thus the name. In this case, the grid that divides Atlanta into sixteen zones is the index
layer. A map document has already been created that has the desired layout for the individual sheets of the map book.
Click the Data Driven Page Setup… button on the Data Driven Pages toolbar
Use the exportToPDF function of the DataDrivenPages class to export all of the pages to a pdf
Now create a final copy of the map book that contains the title page and the map pages. First, create an empty PDF document using the
PDFDocumentCreate function.
6
Finally, append the title and map pages to the map book, then save and close the PDF.
Close ArcMap
Results
The ArcPy Mapping module provides an efficient way to automate map management and authoring tasks like fixing broken data sources in maps and creating
multiple page map books using data driven pages.
...