MapSeries

Resumen

Provides access to a spatial map series on a Layout in an ArcGIS Pro project.

Debate

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.

Nota:

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.

Propiedades

PropiedadExplicaciónTipo de datos
currentPageNumber
(Lectura y escritura)

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

Nota:

If the page number is set using a string defined field, currentPageNumber can be set to a string, for example, currentPageNumber = 'iv'.

Long
enabled
(Lectura y escritura)

Represents the enabled state of the map series.

Sugerencia:

You should check to see if enabled is set to True before changing map series properties.

Boolean
indexLayer
(Sólo lectura)

Returns a reference to the index layer in a map series-enabled layout.

Layer
mapFrame
(Sólo lectura)

Returns a reference to the map frame where the index layer resides.

MapFrame
pageCount
(Sólo lectura)

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
(Sólo lectura)

Returns a field object that represents the field used in the index feature class when setting up a map series.

Field
pageRow
(Sólo lectura)

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
(Sólo lectura)

Returns a Python list of sorted page numbers that represent selected index layer features in a map series-enabled layout.

List

Descripción general del método

MétodoExplicación
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.

Métodos

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})
ParámetroExplicaciónTipo de datos
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 are exported.
  • SELECTEDSelected index layer features/pages are exported.

(El valor predeterminado es 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_MULTIPLE_FILES_PAGE_NAMEExport each map series page to an individual file and append the page name to the file name. For example, Output.PDF will become Output_LakeErie.PDF
  • PDF_MULTIPLE_FILES_PAGE_NUMBERExport each map series page to an individual file and append the page number to the file name. For example, Output.PDF will become Output_1.PDF
  • PDF_SINGLE_FILEExport into a multipage, single file document.

(El valor predeterminado es PDF_SINGLE_FILE)

String
resolution

An integer that defines the resolution of the export file in dots per inch (dpi).

(El valor predeterminado es 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

(El valor predeterminado es 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.

(El valor predeterminado es 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.

(El valor predeterminado es 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.

(El valor predeterminado es True)

Boolean
layers_attributes

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

(El valor predeterminado es LAYERS_ONLY)

String
georef_info

A Boolean that enables the export of coordinate system information for each map frame into the output PDF file.

(El valor predeterminado es 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.

(El valor predeterminado es 80)

Integer
clip_to_elements

If set to True, the layout is clipped to the smallest bounding box that includes all layout elements.

(El valor predeterminado es False)

Boolean
show_selection_symbology

A Boolean that controls whether the selection symbology should be displayed in the output.

(El valor predeterminado es 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.

(El valor predeterminado es False)

Boolean
embed_color_profile

If set to True, color profile information is embedded in the image's metadata.

(El valor predeterminado es 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)
ParámetroExplicaciónTipo de datos
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.

Muestra de código

MapSeries example 1

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")
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(os.path.join(relpath, "Output", f"Ex2_{ms.pageRow.STATE_NAME}.png"))
MapSeries example 3

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")
MapSeries example 4 (Bookmark Map Series)

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'))