Summary
Provides access to a spatial map series on a Layout in an ArcGIS Pro project.
Discussion
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.
Note:
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.
Properties
Property | Explanation | Data Type |
currentPageNumber (Read and Write) | Represents the active or current page for a layout that has map series enabled. Note:If the page number is set using a string defined field, currentPageNumber can be set to a string, for example, currentPageNumber = 'iv'. | Long |
enabled (Read and Write) | Represents the enabled state of the map series. Tip:You should check to see if enabled is set to True before changing map series properties. | Boolean |
indexLayer (Read Only) | Returns a reference to the index layer in a map series-enabled layout. | Layer |
mapFrame (Read Only) | Returns a reference to the map frame where the index layer resides. | MapFrame |
pageCount (Read Only) | 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 (Read Only) | Returns a field object that represents the field used in the index feature class when setting up a map series. | Field |
pageRow (Read Only) | 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 (Read Only) | Returns a Python list of sorted page numbers that represent selected index layer features in a map series-enabled layout. | List |
Method Overview
Method | Explanation |
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}, {pdf_accessibility}) | 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. |
Methods
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}, {pdf_accessibility})
Parameter | Explanation | Data Type |
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.
(The default value is 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.
(The default value is PDF_SINGLE_FILE) | String |
resolution | An integer that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
image_quality | A string that defines output image quality.
(The default value is 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. (The default value is True) | Boolean |
image_compression | A string that defines the compression scheme used to compress image or raster data in the output file.
(The default value is 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. (The default value is True) | Boolean |
layers_attributes | A string that controls the inclusion of PDF layers and PDF object data (attributes) in the export file.
(The default value is LAYERS_ONLY) | String |
georef_info | A Boolean that enables the export of coordinate system information for each map frame into the output PDF file. (The default value is 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. (The default value is 80) | Integer |
clip_to_elements | If set to True, the layout is clipped to the smallest bounding box that includes all layout elements. (The default value is False) | Boolean |
show_selection_symbology | A Boolean that controls whether the selection symbology should be displayed in the output. (The default value is 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. (The default value is False) | Boolean |
embed_color_profile | If set to True, color profile information is embedded in the image's metadata. (The default value is True) | Boolean |
pdf_accessibility | Output a tagged PDF file where text can be read by screen readers or other assistive technology. A tagged PDF file can include alt text—a text description of a graphic element that a screen reader uses to describe the element—for map frames, pictures, and chart frames. Alt text is added in the Element Pane for each element.
(The default value is False) | Boolean |
PDF files are designed to be consistently viewable and printable across various 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)
Parameter | Explanation | Data Type |
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.
Code sample
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.management.SelectLayerByAttribute(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'))