Summary
The MapSeries object provides access to properties and methods for managing a spatial map series.
Discussion
The arcpy.mp module supports two types of map series: spatial and bookmark. The mapSeries property on the Layout object will return a MapSeries object if a spatial map series is present, a BookmarkMapSeries object if a bookmark map series is present, or a NoneType value if a map series is not present or enabled. The MapSeries class can be used to customize individual map series pages during export. One example is with facing pages where even pages are shifted differently than odd pages to accommodate for binding space.
A new spatial map series can be created with the createSpatialMapSeries method by passing in a MapFrame object, an index_layer value, a name_field value, and other optional parameters.
The features that are displayed in a spatial map series can be further filtered using page queries where the values in the layer's specified field are matched against the current map series page name. The filter is only applied when a map series is enabled. The Layer class provides access to the pageQuery property and setPageQuery method.
Similar to the application, the map series can be exported to JPEG, PDF, PNG and TIFF file formats using the export method. These formats can also be further configured using the MapSeriesExportOptions object if non-default values are needed. When exporting a map series, all the dynamic elements associated with the map series are supported. For example, dynamic text elements—such as page name, page number, bookmark name, and more—will automatically update. If map surrounds such as legends, table frames, and chart frames are set up to use the map series constraint, those elements will also dynamically update.
Note:
A map series export may be limited to the formats listed above and can be further configured using MapSeriesExportOptions, but that doesn't mean you can't simulate map series export to a different format. The procedure is to update the layout with the current map series page and export the layout instead of the map series. The second code example below demonstrates how to do this.
The getDefinition and setDefinition methods provide access to CIM properties that are not exposed to the MapSeries object. For more information and code samples, see the Python CIM access help topic.
Properties
Property | Explanation | Data Type |
clipToIndexFeature (Read and Write) | If set to True, Map clipLayers settings are applied to the current index feature. In order to modify or clear clipLayers on a map, clipToIndexFeature must be set to False. | Boolean |
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 and Write) | A reference to the MapFrame that contains the index layer used to drive the map series. If you change the map frame, you might also need to reset the index layer and you should also call the refresh method | 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 |
export (export_format, {mapseries_export_options}, {display_options}) |
The export method exports a MapSeries using a specified export_format and optionally different mapseries_export_options or display_options. |
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}, {show_export_count}, {keep_layout_background}, {convert_markers}, {simulate_overprint}) | Exports a specified set of pages to a Portable Document Format (PDF) file for a layout that has map series enabled. Legacy:This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method. |
getDefinition (cim_version) | Returns a spatial map series' CIM definition. |
getPageNumberFromName (page_name) | Returns a Map Series page number based on the name of the page. |
refresh () | Refreshes an existing map series. |
setDefinition (definition_object) | Sets a spatial map series' CIM definition. |
Methods
export (export_format, {mapseries_export_options}, {display_options})
Parameter | Explanation | Data Type |
export_format | The supported export format objects are: JPEGFormat, PDFFormat, PNGFormat, and TIFFFormat. | Object |
mapseries_export_options | The MapSeriesExportOptions object that includes changes to default property values. | Object |
display_options | The DisplayOptions object that includes changes to the default antialiasing property values. | Object |
Refer to the MapSeriesExportOptions and DisplayExportOptions help topics to learn more details and get code samples.
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}, {show_export_count}, {keep_layout_background}, {convert_markers}, {simulate_overprint})
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 |
show_export_count | If set to True, you will see the status of each page being exported displayed in the Python shell. (The default value is False) | Boolean |
keep_layout_background | If set to True, the white background will be included in the export. (The default value is True) | Boolean |
convert_markers | A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. (The default value is False) | Boolean |
simulate_overprint | Sometimes called soft proofing, simulating overprinting shows a representation of how overlapping areas of ink will appear when printed on a page. You set up overprinting on symbol layers. (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.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
getDefinition (cim_version)
Parameter | Explanation | Data Type |
cim_version | A string that represents the major version of the CIM that will be used.
| String |
Data Type | Explanation |
Object | Returns the CIM definition for a MapSeries. |
For more information about working with the CIM and code samples, see Python CIM access.
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.
setDefinition (definition_object)
Parameter | Explanation | Data Type |
definition_object | A modified CIM definition object originally retrieved using getDefinition. | Object |
For more information about working with the CIM and samples, see Python CIM Access.
Code sample
The following script checks for the presence of a spatial map series and exports two individual pages to PDF base on the names of the pages. Because it exports one PDF at a time, the MapSeriesExportOptions class is configured to export the CURRENT page. The PDFFormat object only needs to be created once because the filePath property is changed between exports.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
lyt = p.listLayouts('Layout_MS')[0]
sms = lyt.mapSeries
#Create a new PDF format and change the resolution from its default value of 96
pdf = arcpy.mp.CreateExportFormat('PDF')
pdf.resolution = 300
#Modify the map series export options to export only the current page
msOpt = arcpy.mp.CreateExportOptions('MAPSERIES')
msOpt.setExportPages('CURRENT')
if isinstance(sms, arcpy._mp.MapSeries):
if sms.enabled:
sms.currentPageNumber = sms.getPageNumberFromName("Lake Superior")
pdf.filePath = os.path.join(relpath, 'Output', 'Ex1_LakeSuperior.pdf')
sms.export(pdf, msOpt)
sms.currentPageNumber = sms.getPageNumberFromName("Lake Huron")
pdf.filePath = os.path.join(relpath, 'Output', 'Ex1_LakeHuron.pdf')
sms.export(pdf, msOpt)
The following script exports each page of a spatial map series to individual .bmp 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(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
lyt = p.listLayouts('Layout_MS')[0]
sms = lyt.mapSeries
#Create a new PNG format that uses only defaults
bmp = arcpy.mp.CreateExportFormat('BMP')
if ((type(sms).__name__ == 'MapSeries')):
if sms.enabled:
for pageNum in range(1, sms.pageCount + 1): #All pages, zero based index
sms.currentPageNumber = pageNum
pageName = sms.pageRow.NAME #NAME = field name in index layer
print(f"Exporting {pageName}")
bmp.filePath =os.path.join(relpath,'Output', f'Ex2_{pageName}.bmp')
lyt.export(bmp)
The following script selects index features, exports the selected pages to one multi-page PDF, and clears the selection when complete.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
lyt = p.listLayouts('Layout_MS')[0]
sms = lyt.mapSeries
#Create a new PDF format using defaults
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Ex3_QueriedLakes.pdf'))
#Set up optional mapseries settings to export only the current page
msOpt = arcpy.mp.CreateExportOptions('MAPSERIES')
msOpt.setExportPages('SELECTED')
if isinstance(sms, arcpy._mp.MapSeries):
if sms.enabled:
indexLyr = sms.indexLayer
arcpy.SelectLayerByAttribute_management(indexLyr, 'NEW_SELECTION','AREA > 10000')
sms.export(pdf, msOpt))
arcpy.SelectLayerByAttribute_management(indexLyr, 'CLEAR_SELECTION')
The following script creates a Map object, a Layout object, and a MapFrame object. Next, it creates a spatial map series and enables map clipping by setting clipMapToIndexFeature to True. It uses Python CIM access to modify some CIM properties that are not exposed to the MapSeries object. Examples are setting the starting page number, scale rounding, and clipping the data to the map index feature. Finally, it exports the map series to a single PDF.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
#Function used to create a rectangle where the anchor point is lower left corner
def MakeRec_LL(llx, lly, w, h):
xyRecList = [[llx, lly], [llx, lly+h], [llx+w,lly+h], [llx+w,lly], [llx,lly]]
array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])
rec = arcpy.Polygon(array)
return rec
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
#Create a new map and add index layer
m = p.createMap('New Map', 'MAP')
lyrFile = arcpy.mp.LayerFile(os.path.join(relpath, 'GreatLakes', 'GreatLakes.lyrx'))
lyr = m.addLayer(lyrFile)[0]
#Create a layout and map frame
lyt = p.createLayout(8.5, 11, 'INCH')
mf = lyt.createMapFrame(MakeRec_LL(0.5,5.5,7.5,5), m, "New Map Frame")
#Create and export a spatial map series
sms = lyt.createSpatialMapSeries(mf, lyr, 'NAME')
sms.clipToIndexFeature = true
#Modify CIM properties
sms_cim = sms.getDefinition('V3')
sms_cim.startingPageNumber = 2
sms_cim.scaleRounding = 10000
sms.setDefinition(sms_cim)
#Export to PDF
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Ex4_NewSMS.pdf'))
sms.export(pdf)
The following script exports all the pages from a spatial map series to a single PDF, exports all pages from a bookmark map series to another PDF, and combines the two resulting PDFs into a single, newly created PDF.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
arcpy.env.overwriteOutput = True
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
#Export spatial map series
sms_lyt = p.listLayouts('Layout_MS')[0]
sms = sms_lyt.mapSeries
if ((type(sms).__name__ == 'MapSeries')):
if sms.enabled:
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
sms.export(pdf)
#Export bookmark map series
bms_lyt = p.listLayouts('Layout_BMS')[0]
bms = bms_lyt.mapSeries
if ((type(bms).__name__ == 'BookmarkMapSeries')):
if bms.enabled:
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
bms.export(pdf)
#Combine PDFs and remove temporary files
comboPDF = arcpy.mp.PDFDocumentCreate(os.path.join(relpath, 'Output', 'Ex5_Combo.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
comboPDF.saveAndClose()
os.remove(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
os.remove(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))