ArcGIS教程:将支持页面插入地图册

来源:互联网 发布:如何看spring源码 编辑:程序博客网 时间:2024/06/05 20:55

  ArcGIS 提供了创建地图册(打印或 Adobe PDF 格式)所需的所有工具。地图册是统一打印或导出的一组页面。其中许多页面都包含地图,而其他页面可包含文本、表格信息、内容列表或标题页及其他内容。

  

  许多地图册都包括辅助文档(或支持文档)。这些文档可以是报告文本、表、索引和其他支持数据。可以通过ArcMap“数据驱动页面”和 arcpy.mapping Python 脚本的结合来创建这些类型的地图册。

  以上示例显示了密歇根州阿勒纳克县的地形图册。此地图册包含若干个支持页面,这些支持页面提供了文本信息、图表和表格数据的支持页面。可使用“数据驱动页面”和arcpy.mapping Python 脚本创建此文档。

  此示例基于以下前提假设:

  •   现有地图文档包含“数据驱动页面”。此代码示例适用于使用 ArcGIS 构建地图册中呈现的简单参考系列地图册示例。
  •   具有包含报告和图表的 PDF 文件。
  •   已具有地图册标题页 PDF 文件。
  •   已具有包含鹰眼图页的 PDF 文件。

  由于地图册显示了页码,因此应确保页码“数据驱动页面”已将要插入地图册的支持页面考虑在内。例如,以下是“数据驱动页面”索引图层表的视图。格网创建完毕以后,将通过格网索引要素地理处理工具创建和填充 PageNumber 字段。由于要在地图页面之间插入其他页面,因此这些页码将不再正确。需要为页码创建一个新的字段,字段值也必须正确填充。下方创建的是新字段 New PageNum,并且填充的值将要插入的页面也考虑在内。

  

  请确保在创建“数据驱动页面”之前为页码字段选择了正确的字段。

  

  同样,如果要显示页码还要确保使用正确的文本元素。不要使用带页数的数据驱动页面,因为该页数只是“数据驱动页面”的总数。不包括将加入最终地图册中的其他页面(例如,标题页或报告页)。您应该改为使用数据驱动页面页码并将此动态文本同显示页面总数的静态文本结合,例如,Page of 26。

  如果已准备好地图文档和 PDF 文件,便可运行以下代码创建最终地图册 PDF。Python 窗口或独立 Python 应用程序中都可以运行此代码。

  虽然本主题中的特定代码仅适用于上述示例地图册,但您可以将此处介绍的过程和技巧应用到自己的地图册中。

  将支持页面插入地图册 PDF。

  import arcpy, os

  # Create an output location variable

  outDir = r"C:\temp\MBExample\final_output"

  # Create a new, empty pdf document in the specified output location folder

  finalpdf_filename = outDir + r"\ArenacMB.pdf"

  if os.path.exists(finalpdf_filename):

  os.remove(finalpdf_filename)

  finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)

  # Add the title page to the pdf

  finalPdf.appendPages(r"C:\temp\MBExample\ancillary_pages\TitlePage.pdf")

  # Add the overview map to the pdf

  finalPdf.appendPages(r"C:\temp\MBExample\maps\IndexMap.pdf")

  # Export the Data Driven Pages to a temporary pdf and then add it to the

  # final pdf. Alternately, if your Data Driven Pages have already been

  # exported, simply append that document to the final pdf.

  #

  mxdPath = r"C:\temp\MBExample\maps\ArenacDDP Reports.mxd"

  tempMap = arcpy.mapping.MapDocument(mxdPath)

  tempDDP = tempMap.dataDrivenPages

  temp_filename = r"C:\temp\MBExample\temp_pdfs\tempDDP.pdf"

  if os.path.exists(temp_filename):

  os.remove(temp_filename)

  tempDDP.exportToPDF(temp_filename, "ALL")

  finalPdf.appendPages(temp_filename)

  # Insert the pdf pages containing the reports and graphs into the final pdf

  #

  finalPdf.insertPages(r"C:\temp\MBExample\ancillary_pages\Report_pg4.pdf", 4)

  finalPdf.insertPages(r"C:\temp\MBExample\ancillary_pages\Report_pg5.pdf", 5)

  finalPdf.insertPages(r"C:\temp\MBExample\ancillary_pages\Report_pg7.pdf", 7)

  # Update the properties of the final pdf

  finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS",

  pdf_layout="SINGLE_PAGE")

  # Save your result

  finalPdf.saveAndClose()

  # Delete variables

  del finalPdf

  最开始几行代码表示,导入所需模块;创建保存最终地图册 PDF 的输出位置变量;在指定的输出位置文件夹中创建新的空 PDF 文档。该 PDF 即是该脚本的最终输出。

  接下来几行代码表示将标题页和总览图页添加到最终 PDF。本示例的前提假设是存在可用作标题页和总览图页的现有PDF 文档。

  下一步是添加地图页面。这个步骤需要已经启用“数据驱动页面”的地图文档。在此例中,该地图文档为 ArenacDDP报告。

  接下来将包含报告和图表的 PDF 页面插入最终 PDF 文档。

  最后的代码表示对属性进行更新,然后保存和关闭最终 PDF。

0 0