サマリー
Provides access to a spatial map series on a Layout in an ArcGIS Pro project.
説明
A map series must first be authored and enabled on a layout in an ArcGIS Pro project before it can be referenced with arcpy.mp.
注意:
You cannot use arcpy.mp to create a map series.
In addition to providing methods and properties for a map series on a layout, the MapSeries class can be used to access the individual pages in a map series. For example, you may have a scenario in which a text element's string information needs to be formatted using custom logic or needs to be constructed from multiple fields. In this case, the layout can be authored with a map series enabled, and arcpy.mp can handle the custom text element string requirements as each page is being processed.
The pages in a map series can be exported to PDF using the exportToPDF method . When you export a map series, all the dynamic elements associated with the map series are supported. For example, text elements, legends, table frames, chart frames, and so on. To create a complete map book, the output PDF files can be inserted into other PDF files (for example, a title page or report) using the PDFDocument class.
Sometimes it is necessary to export a map series to an output format other than PDF, such as PNG. See the second code sample below that demonstrates how to loop through each page in a map series and export to a .png file.
ArcGIS Pro supports two types of map series: spatial and bookmark. The MapSeries class only supports working with a spatial map series. If a bookmark map series is enabled for a layout, the mapSeries property will return a NoneType. To emulate bookmark map series behavior, see code example 4 below.
プロパティ
プロパティ | 説明 | データ タイプ |
currentPageNumber (読み書き) | Represents the active or current page for a layout that has map series enabled. 注意:If the page number is set using a string defined field, currentPageNumber can be set to a string, for example, currentPageNumber = 'iv'. | Long |
enabled (読み書き) | Represents the enabled state of the map series. ヒント:You should check to see if enabled is set to True before changing map series properties. | Boolean |
indexLayer (読み取り専用) | Returns a reference to the index layer in a map series-enabled layout. | Layer |
mapFrame (読み取り専用) | Returns a reference to the map frame where the index layer resides. | MapFrame |
pageCount (読み取り専用) | Returns the total page count for a layout that has map series enabled. This corresponds to the number of features in the index layer. | Long |
pageNameField (読み取り専用) | Returns a field object that represents the field used in the index feature class when setting up a map series. | Field |
pageRow (読み取り専用) | Returns a Row object that provides access to the attributes for the current index feature. To return an attribute value, enter a dot followed by the field name. For example, value = lyt.mapSeries.pageRow.FIELD_NAME. | Row |
selectedIndexFeatures (読み取り専用) | Returns a Python list of sorted page numbers that represent selected index layer features in a map series-enabled layout. | List |
方法の概要
方法 | 説明 |
exportToPDF (out_pdf, {page_range_type}, {page_range_string}, {multiple_files}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}, {show_selection_symbology}, {output_as_image}, {embed_color_profile}) | Exports a specified set of pages to a Portable Document Format (PDF) file for a layout that has map series enabled. |
getPageNumberFromName (page_name) | Returns a Map Series page number based on the name of the page. |
refresh () | Refreshes an existing map series. |
方法
exportToPDF (out_pdf, {page_range_type}, {page_range_string}, {multiple_files}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}, {show_selection_symbology}, {output_as_image}, {embed_color_profile})
パラメーター | 説明 | データ タイプ |
out_pdf | A string that represents the path and file name of the output export file. | String |
page_range_type | The string value that designates how the pages will be printed.
(デフォルト値は次のとおりです ALL) | String |
page_range_string | A string that identifies the pages to be exported if the RANGE option in the page_range_type parameter is used (for example, 1, 3, 5-12). If any other page_range_type value is used, the page_range_string value will be ignored. | String |
multiple_files | A string that controls how the output PDF file is created. By default, all pages are exported into a single, multipage document. The default is PDF_SINGLE_FILE.
(デフォルト値は次のとおりです PDF_SINGLE_FILE) | String |
resolution | An integer that defines the resolution of the export file in dots per inch (dpi). (デフォルト値は次のとおりです 96) | Integer |
image_quality | A string that defines output image quality.
(デフォルト値は次のとおりです BEST) | String |
compress_vector_graphics | A Boolean that controls the compression of vector and text portions of the output file. Image compression is defined separately. (デフォルト値は次のとおりです True) | Boolean |
image_compression | A string that defines the compression scheme used to compress image or raster data in the output file.
(デフォルト値は次のとおりです ADAPTIVE) | String |
embed_fonts | A Boolean that controls the embedding of fonts in an export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. (デフォルト値は次のとおりです True) | Boolean |
layers_attributes | A string that controls the inclusion of PDF layers and PDF object data (attributes) in the export file.
(デフォルト値は次のとおりです LAYERS_ONLY) | String |
georef_info | A Boolean that enables the export of coordinate system information for each map frame into the output PDF file. (デフォルト値は次のとおりです True) | Boolean |
jpeg_compression_quality | A number that controls the compression quality value when image_compression is set to ADAPTIVE or JPEG. The valid range is 1 through 100. A jpeg_compression_quality of 100 provides the best quality images but creates large export files. The recommended range is 70 through 90. (デフォルト値は次のとおりです 80) | Integer |
clip_to_elements | If set to True, the layout is clipped to the smallest bounding box that includes all layout elements. (デフォルト値は次のとおりです False) | Boolean |
show_selection_symbology | A Boolean that controls whether the selection symbology should be displayed in the output. (デフォルト値は次のとおりです False) | Boolean |
output_as_image | If set to True, vector content can be saved as an image. Selecting this option for maps or layouts that contain vector layers with a high density of vertices can reduce the output file size. When exporting to PDF and this option is set to True, you cannot view PDF layers in the output. (デフォルト値は次のとおりです False) | Boolean |
embed_color_profile | If set to True, color profile information is embedded in the image's metadata. (デフォルト値は次のとおりです True) | Boolean |
PDF files are designed to be consistently viewable and printable across different platforms. They are commonly used for distributing documents on the web and are a standard interchange format for content delivery. PDF files are editable in many graphics applications and retain annotation, labeling, and attribute data for map layers. PDF exports support embedding of fonts and can display symbology correctly even if the user does not have Esri fonts installed.
getPageNumberFromName (page_name)
パラメーター | 説明 | データ タイプ |
page_name | A page number in the index layer that corresponds to the Name field that was used to set up the Map Series. | String |
Many of the Map Series properties and methods use a page number value rather than the literal names of the pages used to create the index layer. The getPageNumberFromName method provides a mechanism to obtain a page number given a page name.
ms = layout.mapSeries
pageNumber = ms.getPageNumberFromName("HarborView")
ms.currentPageNumber = pageNumber
refresh ()
Use the refresh method if any of the following occurs:
- Features are added to or deleted from your index layer.
- Updates are made to the index field values.
- The map frame extent is changed due to zooming, panning, or change to map scale.
コードのサンプル
The following script checks for the presence of a map series and then exports two of its pages to PDF:
import arcpy
import os
import sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(relpath + "\\MapSeries\\US_States.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
ms.currentPageNumber = ms.getPageNumberFromName("Rhode Island")
ms.exportToPDF(relpath + "\\Output\\Ex1_RI.pdf", "CURRENT", resolution=300)
ms.currentPageNumber = ms.getPageNumberFromName("Washington")
ms.exportToPDF(relpath + "\\Output\\Ex1_WA.pdf", "CURRENT")
The following script exports each page of a map series to individual PNG files and uses the page name of the index feature as part of the output file name:
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(relpath + "\\MapSeries\\US_States.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum
print("Exporting {0}".format(ms.pageRow.STATE_NAME))
pageName = ms.pageRow.STATE_NAME
l.exportToPNG(os.path.join(relpath, "Output", f"Ex2_{ms.pageRow.STATE_NAME}.png"))
The following script exports only the selected pages to a single, multipage PDF file:
import arcpy
import os
import sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(relpath + "\\MapSeries\\US_States.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
ms = l.mapSeries
indexLyr = ms.indexLayer
arcpy.SelectLayerByAttribute_management(indexLyr, "NEW_SELECTION", "SUB_REGION = 'New England'")
ms.exportToPDF(relpath + "\\Output\\Ex3_SelectedFeatures.pdf", "SELECTED")
As stated previously, only spatial map series are supported in the MapSeries class. However, bookmark map series can be emulated without using the MapSeries class using the following code example. First, you need to reference a Map's bookmarks using the listBookmarks method. Second, you can set the MapFrame's camera information using the zoomToBookmark method. Finally, you would export the Layout using one of its many export functions. This process would be repeated for each page needed in the final output.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, "Bookmarks.aprx"))
m = p.listMaps('Great Lakes')[0]
lyt = p.listLayouts('GreatLakes')[0]
mf = lyt.listElements('MAPFRAME_ELEMENT')[0]
for bk in m.listBookmarks():
mf.zoomToBookmark(bk)
lyt.exportToPNG(os.path.join(relpath, f'{bk.name}.png'))