Skip To Content

MapSeries

Summary

Provides access to methods and properties for managing the individual pages in a layout that has map series enabled.

Discussion

A map series can be created without any Python scripting using the Map Series command on the Layout tab. The reverse is also true: a map series can be completely scripted using arcpy.mp without using the Map Series user interface in ArcGIS Pro, but there are good reasons for combining both techniques. The ArcGIS Pro Map Series dialog box may not provide enough options for creating exactly what you need. However, the inherent behavior of a map series-enabled layout can save many lines of code because the page extents, scales, dynamic text, and so forth, are all managed automatically in the layout so that code does not need to be written. An example of this is a scenario where a text element's string information needs to be formatted using custom logic or needs to be constructed from multiple fields. It isn't necessary to use arcpy.mp for everything for such a simple, custom requirement. In this case, the layout can be authored with a map series enabled, and arcpy.mp can handle the custom text element string requirements.

A map series must first be authored and enabled in a layout before it can be referenced with arcpy.mp. A layout can contain a single MapSeries object. If the Layout mapSeries property returns None, a map series is not created in the layout. You should also check whether MapSeries is enabled before attempting to manipulate its properties.

The MapSeries class only has a single exportToPDF method, but that does not mean other export file formats can't be generated. See the second code sample below that demonstrates how to loop through each page in a map series and export to a file format other than PDF.

Properties

PropertyExplanationData Type
currentPageNumber
(Read and Write)

Represents the active or current page for a layout that has map series enabled.

Long
enabled
(Read and Write)

Represents the enabled state of the map series. You should check to see if it is 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

MethodExplanation
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})

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})
ParameterExplanationData 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.

  • ALLAll pages are exported.
  • CURRENTThe active or current page is exported.
  • RANGEOnly pages listed in the page_range_string parameter will be exported.
  • SELECTEDSelected index layer features/pages are exported.

(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

An option to control how the output PDF file is created. By default, all pages are exported into a single, multi-page document. Currently the only option available is PDF_SINGLE_FILE.

  • PDF_SINGLE_FILEExport into a multi-page document.

(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.

  • BESTAn output image quality resample ratio of 1
  • BETTERAn output image quality resample ratio of 2
  • NORMALAn output image quality resample ratio of 3
  • FASTERAn output image quality resample ratio of 4
  • FASTESTAn output image quality resample ratio of 5

(The default value is BEST)

String
compress_vector_graphics

A Boolean that controls 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.

  • ADAPTIVEAutomatically selects the best compression type for each image on the page. JPEG will be used for large images with many unique colors. DEFLATE will be used for all other images.
  • JPEGA lossy data compression.
  • DEFLATEA lossless data compression
  • LZWLempel-Ziv-Welch, a lossless data compression
  • NONECompression is not applied
  • RLERun-length encoded compression

(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 inclusion of PDF layers and PDF object data (attributes) in the export file.

  • LAYERS_ONLYExport PDF layers only.
  • LAYERS_AND_ATTRIBUTESExport PDF layers and feature attributes.
  • NONENo setting is applied.

(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 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

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)
ParameterExplanationData 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.
The map series will retain the original settings in these cases until the refresh method is executed, or the project is saved and reopened.

Code sample

MapSeries example 1

The following script checks for the presence of a map series and then exports two of its pages out to PDF.

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:
    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")
MapSeries example 2

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(relpath + "\\Output\\Ex2_{0}".format(ms.pageRow.STATE_NAME + ".png"))
MapSeries example 3

The following script exports only the selected pages to a single, multipage PDF.

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:
    ms = l.mapSeries
    indexLyr = ms.indexLayer
    arcpy.SelectLayerByAttribute_management(indexLyr, 'NEW_SELECTION', "SUB_REGION = 'New England'")
    ms.exportToPDF(relpath + "\\Output\\Ex3_SelectedFeatures.pdf", 'SELECTED')