可将地图脚本与数据驱动页面集成,以使用单个地图文档创建在不同的页面上包括自定义插图的地图册。可以引入自定义逻辑,不仅控制插图的可见性,而且控制插图的大小、位置和范围。

创建地图册
第一步是创建地图文档和设置数据驱动页面。您将要设计所有页面共享的基线布局。
将插图添加到布局
有了基本页面布局之后,还需要插入用作插图的数据框。
- 单击插入菜单并选择数据框。
- 为数据框指定唯一名称。此名称将用于在导出脚本中标识该数据框。
- 单击确定关闭数据框属性 对话框。
- 继续创建插图,根据需要添加并符号化所需图层。
为单个页面设置自定义插图
因为要在导出过程中为单个页面设置插图的范围、大小和位置,所以您需要提前知道这些值,以便在导出脚本中使用它们。这意味着,您首先需要决定哪些页面应该含有插图。接着需要导航到每个有插图的页面,按照您想要的在最终产品中的显示效果来设置布局,然后记录将在最终脚本中使用的相应设置。
以下步骤引导您完成手动记录地图系列中的一个页面需要的插图信息的过程。需要为包含插图的每个页面重复执行这些步骤。
- 导航到将包含插图的页面。记录该页面的索引值,方法是打开数据驱动页面 工具条并将显示更改为显示页面。 
- 确定插图数据框在页面上的位置和大小,然后设置范围。
- 记录插图的当前范围的“上”、“左”、“右”和“下”值。要获得这些信息,可打开插图的数据框属性 对话框,单击数据框选项卡,然后更改固定范围的范围以便出现相应坐标值。 
- 记录您所需要的信息,然后将范围更改回自动。如果范围未设置为自动,则不能在脚本中更改范围。其他范围类型是固定的,运行时会发成错误。
- 单击大小和位置选项卡,并记录 x 位置值和 y 位置值。请切记,这些值反映当前锚点,如果曾经更改锚点,则需要更新这些值。
- 也记录数据框的宽度值和高度值。
- 关闭数据框属性 对话框,小心不要应用任何不必要的更改。
添加范围指示器
可将范围指示器添加到主地图,以高亮显示插图中显示的范围。
- 打开主地图的数据框属性 对话框,然后单击范围指示器选项卡。
- 添加“插图”数据框。 
- 使用可用选项设置外观。
为导出准备地图文档
创建范围指示器并记录脚本所需信息之后,设置地图文档,避免每一页上都显示范围指示器或插图。
- 将包含插图的数据框移出页面的可打印范围。
- 将插图的范围更改为比主数据框的范围大很多,使得范围指示器不会出现在不想其出现的页面上。 
- 保存地图文档。
编写导出脚本
下面显示一个示例脚本,该脚本将导出在第 1 页和第 3 页上有插图的地图册。
下面的脚本将导出在第 1 页和第 3 页上有插图的地图册。
import arcpy, os
# Create an output directory variable
#
outDir = r"C:\Project\MapBook\final_output"  
# Create a new, empty pdf document in the specified output directory
# This will be your final product
finalpdf_filename = outDir + r"\FinalMapBook.pdf"
if os.path.exists(finalpdf_filename): # Check to see if file already exists, delete if it does
  os.remove(finalpdf_filename)
finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)
# Create a Data Driven Pages object from the mxd you wish to export
#
mxdPath = r"C:\Project\MapBook\zipCodePopulation.mxd"
tempMap = arcpy.mapping.MapDocument(mxdPath)
tempDDP = tempMap.dataDrivenPages
# Create objects for the layout elements that will be moving, e.g., inset data frame, scale text
dataFrame = arcpy.mapping.ListDataFrames(tempMap, "Inset Map")[0]  
  
# Instead of exporting all pages at once, you will need to use a loop to export one at a time  
# This allows you to check each index and execute code to add inset maps to the correct pages
#
for pgIndex in range(1, tempDDP.pageCount + 1, 1):
  
  # Create a name for the pdf file you will create for each page
  temp_filename = r"C:\Project\MapBook\temp_pdfs\MB_" + \
                            str(pgIndex) + ".pdf"
  if os.path.exists(temp_filename):
    os.remove(temp_filename)
  
  # The following if statements check the current page index against given values
  # If the current page index matches, it will execute code to set up that page
  # If not, the page remains as is
  # Note: If you created a text file containing this information, this is where
  # you would paste in that code
  
  # Code for setting up the inset map on the first page #
  if (pgIndex == 1):
    # Set position of inset map to place it on the page layout
    dataFrame.elementPositionX = 0.5
    dataFrame.elementPositionY = 0.6
    # Set the desired size of the inset map for this page
    dataFrame.elementHeight = 2.0
    dataFrame.elementWidth = 2.0
    # Set the desired extent for the inset map
    insetExtent_1 = arcpy.Extent(-88.306778229417176, 41.590293951894907, -87.609922645465474, 42.300975912784295)
    dataFrame.extent = insetExtent_1
  # Code for setting up the inset map on the third page #
  if (pgIndex == 3):
    # Set up inset map
    dataFrame.elementPositionX = 3.25
    dataFrame.elementPositionY = 7
    dataFrame.elementHeight = 2.45
    dataFrame.elementWidth = 3.0
    insetExtent_3 = arcpy.Extent(-83.889191535, 41.870516098, -82.875460656, 42.72572048)
    dataFrame.extent = insetExtent_3
  # Code to export current page and add it to mapbook
  tempDDP.exportToPDF(temp_filename, "RANGE", pgIndex)
  finalPdf.appendPages(temp_filename)
  
  # Clean up your page layout by moving the data frame and resetting its extent after exporting the page
  # This will reset the page to the basic layout before exporting the next page
  #
  
  dataFrame.elementPositionX = 10 # Move inset data frame off the page
  dataFrame.scale = 350000000 # Change scale so extent indicator no longer visible in main data frame
  arcpy.RefreshActiveView()
# Clean up
#
del tempMap
# Update the properties of the final pdf
#
finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS",
                             pdf_layout="SINGLE_PAGE")
# Save your result
#
finalPdf.saveAndClose()
总之,按照此工作流程操作,您可以使用单个地图文档创建仅在某些页面上显示插图或其他特殊要素的地图册。