[GIS] Dynamically change zoom level of overview map to fit with current extent in DDP

arcpydata-driven-pages

I am using DDP pages in a large mapset with pages ranging from 1:7500 to 1:130,000 and the overview map is zoomed out to far to see some of the smaller zones. Is it possible to set the overview map to zoom to say 10 times the current DDP page extent? so a 50k main sheet would have the overview at 500k.

Map overview scale @ 1:3,000,000 – meaningless as it is to full of info.
enter image description here

Map overview scale @ 1:500,000
enter image description here

So we can use the cartography–>ddp–>calculate adjacent fields to get the adjoining map sheets but this doesn't seem to help in changing the zoom levels of the map.

Till now my workaround has been to create multiple mxd's which have all the maps in an overview zone that makes sense but this causes issues when making edits to pages etc etc and it would be ideal to automate it into one mxd.

Also is it possible to get DDP to fill in the total number of maps -this should be map 14 of 38 but the 13 is carried over from a previous version as it's hard coded.


I also found another workaround. In the overview map data frame properties, go to Data Frame tab and choose options as per the screen capture below.

enter image description here

This seems to work fine as long as the extents don't change to much.

Best Answer

This code may help.

It does not use Data Driven Pages, but more or less emulates their functionality, while enabling you to have the flexibility to use the extent of each feature in your index layer to set the extent of both the Main Map and the Overview, before zooming out the Overview by a factor of 10.

I think DDP is great for creating "no code" map books, but those thus created do not give you anywhere near the control that taking charge of generating each page yourself with ArcPy can.

import arcpy

mxd = arcpy.mapping.MapDocument("C:\\Temp\\test.mxd")
dfMainMap = arcpy.mapping.ListDataFrames(mxd,"Main Map")[0]
dfOverview = arcpy.mapping.ListDataFrames(mxd,"Overview")[0]
indexLayer = arcpy.mapping.ListLayers(mxd, "countries", dfMainMap)[0]
pageFeatures = arcpy.SearchCursor(indexLayer)
count = 1
#Set file name and remove if it already exists
pdfFinal = "C:\\Temp\\AllCountries.pdf"
if arcpy.Exists(pdfFinal):
    arcpy.Delete_management(pdfFinal)

#Create the file and append pages
pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfFinal)

for pageFeature in pageFeatures:
    print pageFeature.CNTRY_NAME
    indexLayer.definitionQuery = "CNTRY_NAME = '" + pageFeature.CNTRY_NAME + "'"
    dfMainMap.extent = indexLayer.getSelectedExtent()
    dfOverview.extent = indexLayer.getSelectedExtent()
    dfOverview.scale = dfOverview.scale * 10
    arcpy.mapping.ExportToPDF(mxd, "C:\\Temp\\Page" + str(count) + ".pdf")
    pdfDoc.appendPages("C:\\Temp\\Page" + str(count) + ".pdf")
    count = count + 1

#Commit changes and delete variable reference
pdfDoc.saveAndClose()
del pdfDoc
del pageFeature,pageFeatures
del mxd
Related Question