Resumen
The MapSeries object provides access to properties and methods for managing a spatial map series.
Debate
An existing spatial map series can be referenced using the mapSeries property on a Layout object or using the createSpatialMapSeries method. You pass in a MapFrame object, an index_layer value, a name_field value, and other optional parameters to create the spatial map series.
Nota:
Arcpy.mp supports two types of map series: spatial and bookmark. The mapSeries class represents spatial map series. The mapSeries property on the Layout object will return a MapSeries object if a spatial map series is present, a BookmarkMapSeries object, or a NoneType value if a map series is not present.
The MapSeries class can be used to access individual pages in a spatial map series for customization. For example, if a text element's string information needs to be formatted using custom logic, the spatial map series can be referenced and arcpy.mp can handle the custom text element string requirements as each page is being processed, as the script controls how to iterate through the pages. Another example is exporting a spatial 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 spatial map series and export to a .png file.
The pages in a spatial map series can be exported to PDF using the exportToPDF method . When you export a spatial map series, all the dynamic elements associated with the spatial map series are supported. For example, dynamic text elements—such as page name, page number, attributes, 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. The output PDF can be appended or inserted into other PDFs using the PDFDocument class. See the PDFDocument topic for more information and code samples.
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.
Propiedades
Propiedad | Explicación | Tipo de datos |
clipToIndexFeature (Lectura y escritura) | 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 (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 (Lectura y escritura) | 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 (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étodo | Explicació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}, {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. |
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. |
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}, {pdf_accessibility}, {show_export_count}, {keep_layout_background}, {convert_markers}, {simulate_overprint})
Parámetro | Explicación | Tipo 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.
(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.
(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.
(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.
(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.
(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_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.
(El valor predeterminado es False) | Boolean |
show_export_count | If set to True, you will see the status of each page being exported displayed in the Python shell. (El valor predeterminado es False) | Boolean |
keep_layout_background | If set to True, the white background will be included in the export. (El valor predeterminado es 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. (El valor predeterminado es 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. (El valor predeterminado es 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.
getDefinition (cim_version)
Parámetro | Explicación | Tipo de datos |
cim_version | A string that represents the major version of the CIM that will be used.
| String |
Tipo de datos | Explicación |
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)
Parámetro | Explicación | Tipo 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.
setDefinition (definition_object)
Parámetro | Explicación | Tipo de datos |
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.
Muestra de código
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.
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
if isinstance(sms, arcpy._mp.MapSeries):
if sms.enabled:
sms.currentPageNumber = sms.getPageNumberFromName("Lake Superior")
sms.exportToPDF(os.path.join(relpath, 'Output', 'Ex1_LakeSuperior.pdf'),
'CURRENT', resolution=300)
sms.currentPageNumber = sms.getPageNumberFromName("Lake Huron")
sms.exportToPDF(os.path.join(relpath, 'Output', 'Ex1_LakeHuron.pdf'),
'CURRENT', resolution=300)
print("Finished")
The following script exports each page of a spatial 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(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
lyt = p.listLayouts('Layout_MS')[0]
sms = lyt.mapSeries
if ((type(sms).__name__ == 'MapSeries')):
sms = lyt.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("Exporting {0}".format(pageName))
lyt.exportToPNG(os.path.join(relpath,'Output', f'Ex2_{pageName}.png'))
print("Finished")
The following script selects index features, exports the selected pages to one multipage 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
if isinstance(sms, arcpy._mp.MapSeries):
if sms.enabled:
indexLyr = sms.indexLayer
arcpy.SelectLayerByAttribute_management(indexLyr, 'NEW_SELECTION',
'AREA > 10000')
sms.exportToPDF(os.path.join(relpath, 'Output',
'Ex3_QueriedLakes.pdf'), 'SELECTED')
arcpy.SelectLayerByAttribute_management(indexLyr, 'CLEAR_SELECTION')
print('Finished')
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.scaleRounding = 10000
sms.setDefinition(sms_cim)
#Export to PDF
sms.exportToPDF(os.path.join(relpath, 'Output', 'Ex4_NewSMS.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:
print(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
sms.exportToPDF(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
#Export bookmark map series
bms_lyt = p.listLayouts('Layout_BMS')[0]
bms = bms_lyt.mapSeries
if ((type(bms).__name__ == 'BookmarkMapSeries')):
if bms.enabled:
bms.exportToPDF(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
#Combine PDFs and remove temporary files
comboPDF = arcpy.mp.PDFDocumentCreate(os.path.join(relpath, 'Output',
'Ex4_Combo.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
os.remove(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
os.remove(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
comboPDF.saveAndClose()
os.startfile(os.path.join(relpath, 'Output','Ex4_Combo.pdf'))
print('Finished')