『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

ArcGIS教程:创建包含插图的地图册(二)

ArcGIS教程:创建包含插图的地图册(二)
创建范围指示器并记录脚本所需信息之后,设置地图文档,避免每一页上都显示范围指示器或插图。

为导出准备地图文档

    创建范围指示器并记录脚本所需信息之后,设置地图文档,避免每一页上都显示范围指示器或插图。

    步骤:

  • 将包含插图的数据框移出页面的可打印范围。
  • 将插图的范围更改为比主数据框的范围大很多,使得范围指示器不会出现在不想其出现的页面上。


  • 保存地图文档。

编写导出脚本

    下面显示一个示例脚本,该脚本将导出在第 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()

    总之,按照此工作流程操作,您可以使用单个地图文档创建仅在某些页面上显示插图或其他特殊要素的地图册。
      京ICP备2025132830号-1 京公网安备 号