Request: Have Data Driven Pages actually produce a thematic map book.
As discussed in the Esri Desktop help:
From the Ersi ArcGIS Help 10.2, 10.2.1, and 10.2.2
Thematic map book
A thematic map book is similar to a reference series, except that the detail pages show unique thematic maps of a single location.
The ability to display different unique themes (layers) covering a single location would be invaluable to display the results of a multi phase analysis. I have many clients that are tired of making a separate mxd for each theme.
Following is the clever solution supplied by Esri Support for my initial specific request:
import arcpy, os
mxd = arcpy.mapping.MapDocument(r"C; file location ")
mxdDDP = mxd.dataDrivenPages
for i in arcpy.mapping.ListLayers(mxd):
if i in ["geology_geochem","glaciation","Precipitation Regime","geology_sed"]:
i.visible = False
arcpy.RefreshActiveView()
for i in range(mxdDDP.pageCount + 1):
mxdDDP.currentPageID = i
name = mxdDDP.pageRow.getValue(mxdDDP.pageNameField.name)
print name
if name == 'GEO':
for i in arcpy.mapping.ListLayers(mxd):
if i.name == "geology_geochem":
i.visible = True
arcpy.RefreshActiveView()
mxdDDP.exportToPDF(r"C:\temp\GEO.pdf", "CURRENT")
i.visible = False
arcpy.RefreshActiveView()
if name == 'GEO_sed':
for i in arcpy.mapping.ListLayers(mxd):
if i.name == "geology_sed":
i.visible = True
arcpy.RefreshActiveView()
mxdDDP.exportToPDF(r"C:\temp\GEO_sed.pdf", "CURRENT")
i.visible = False
arcpy.RefreshActiveView()
if name == 'GLA':
for i in arcpy.mapping.ListLayers(mxd):
if i.name == "glaciation":
i.visible = True
arcpy.RefreshActiveView()
mxdDDP.exportToPDF(r"C:\temp\GLA.pdf", "CURRENT")
i.visible = False
arcpy.RefreshActiveView()
if name == 'PRE':
for i in arcpy.mapping.ListLayers(mxd):
if i.name == "Precipitation Regime":
i.visible = True
arcpy.RefreshActiveView()
mxdDDP.exportToPDF(r"C:\temp\PRE.pdf", "CURRENT")
i.visible = False
arcpy.RefreshActiveView()
This solution is just a go-by as my actual need is to display 40 different themes over the same extent.
Data Driven Pages are great but they could be a whole lot better if a 'Layers' tab was added to the 'Set Up Data Driven Pages' dialogue which allowed configuration of layer visibility dependent on the page being displayed. The page would be selected by drop-down list, and layers turned on or off for that page via check boxes. Another check box could provide the ability top apply the layer display settings to all Data Driven Pages.
I guess something could be set up to do this based on fields in the layer attributes but that would probably be a bit too complicated for my liking.
Make sure you give this idea the thumbs up! 🙂
I have used the MPS Atlas tool for years creating multiple maps (100's at a time) using one geographic extent, like the United States, but showing different data (like population, income, language preferences, country of origin) on each map. I had the ability to create my map and place all the elements where they need to go, and then 'unlink' the maps so I could turn on/off the different features I would like to show, with all of the maps in one mxd. Data Driven Pages doesn't allow for this capability. To create the maps that I want to, using Data Driven Pages, I'll have to create hundreds of mxds, which is time/space consuming.
In ArcGIS Pro, we have it in our plans to build a thematic map series function as part of the application but in the meantime, it can really only be done using arcpy.mapping (in ArcMap) or arcpy.mp (in Pro). I got this question several times at UC2019 and just recently got it again from a customer using ArcGIS Pro. So below is a very simple example that demonstrates the basic arcpy.mp mechanics (similar to the code above, this same thing can be done in ArcMap with slight modification). In both cases, you do need to modify the paths below.
I hope you find this useful,
Jeff
### This script is a very simple example of how to use arcpy.mp to create a
### thematic map series. The basic concept is to 1) control layer visibility
### between each export and 2) append the results into a single multi-page PDF.
### Understand there are many ways to manager layer visibility. One way is to
### have a series of group layers with a collection of layers you want displayed.
### A more advanced method is to manage a dictionary or text file that controls
### the layer visibility for each export.
### The example below is very basic. It first toggles off all layers
### except for the basemap. Next it creates a final PDF to store the pages.
### Next it toggles each layer on, exports to PDF, appends the results to the
### final PDF, and then removes the temporary file. It does this for each
### layer. At the very end, it uses the OS to open the final result.
import arcpy, os
#Reference Project, Layout, MapFrame, and Map
p = arcpy.mp.ArcGISProject(r"C:\Temp\GreatLakes\GreatLakes.aprx")
lyt = p.listLayouts('Layout')[0]
mf = lyt.listElements('MAPFRAME_ELEMENT', 'Map Frame')[0]
m = mf.map
#Turn off all layers in the map frame's map except the basemap
for lyr in m.listLayers():
if not lyr.isBasemapLayer:
lyr.visible = False
#Create final PDF (and remove if it already exists)
pdfPath = r"C:\Temp\GreatLakes\ThematicMapSeries.pdf"
if os.path.exists(pdfPath):
os.remove(pdfPath)
pdf = arcpy.mp.PDFDocumentCreate(pdfPath)
#Toggle each layer on, export, append the results, remove temp page
for lyr in m.listLayers():
if not lyr.isBasemapLayer:
print(lyr.name)
lyr.visible = True #toggle on
tempFile = os.path.join(r"C:\Temp", lyr.name + ".pdf")
lyt.exportToPDF(tempFile)
pdf.appendPages(tempFile)
os.remove(tempFile)
lyr.visible = False #toggle off (before next page)
#Commit the PDF and open
pdf.saveAndClose()
os.startfile(r"C:\Temp\GreatLakes\ThematicMapSeries.pdf")
It looks like the dropdown menu for the Map Series tab in Layout Properties in Arc Pro is just dying for a Thematic option, just to keep Spatial company.
Hi Michael,
At 2.6 we will be introducing a Bookmark Map Series option. This will allow you to set the extents for each 'page' in the map series to a bookmark extent. Thematic map books are something we are strongly considering for a future release but for now arcpy.mp is really the only way to control the precise logic needed to generate each unique page in the series.
Jeff
Esri Layout and arcpy.mp teams.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.