Select to view content in your preferred language

Export Map Series Pages

6792
22
06-23-2017 06:42 AM
mpboyle
Regular Contributor

I'm considering moving some of my map production projects to ArcGIS Pro, but most of them rely on data driven pages and python scripts to automatically iterate over the pages and export out PDFs.

I have looked through the arcpy.mp module and don't see any method, class, or function for accessing map series properties...maybe I'm missing it...?

Without having the ability to script and export a map series, I'm kind of wondering why this is even a part of ArcGIS Pro...?

Is there going to be future development in ArcGIS Pro that will provide the capability of iterating over map series pages and use the already existing exportToPDF, exportToJPEG, exportToPNG, etc...?

Tags (1)
0 Kudos
22 Replies
JeffBarrette
Esri Regular Contributor

You should be able to do what you need.  Here is a list of the 2.1 MapSeries Class methods and properties:

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})
  • getPageNumberFromName(page_name)
  • refresh()
  • Properties
    • currentPageNumber—Read/Write; Long
    • enabled—Read/Write; Boolean
    • indexLayer—Read-only; Layer object
    • MapFrame—Read-only; MapFrame object
    • pageCount—Read-only; Long
    • pageNameField—Read-only; GP Field object
    • selectedIndexFeatures—Read-only; Python list of corresponding page numbers
deleted-user-uXtLD1BYscf0
New Contributor III

Jeff Barnett‌ - is it safe to assume that getPageNumberFromName(page_name) method will allow us to reference the page number based on some wildcard string? i.e. If PageName = "SouthWest", then return page number = 2. 
I want to be able to exportToPDF one page.
Any chance you could share a snippet to share more info on this one (sorry not sure how this whole 'soon t be released' stuff goes. I have applied for the beta version of 2.1. 
thanks for the replies!

0 Kudos
JeffBarrette
Esri Regular Contributor

Unfortunately getPageNumberFromName does NOT take a wildcard, it must be a fully qualified name.  That would be a good enhancement.

Here are some snippets of code.  NOTE - this is from the 2.1 help.  Arcpy.mp map series are not supported prior to 2.1

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", resolution=300)

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 page {0} of {1}".format(str(ms.currentPageNumber), str(ms.pageCount)))
      l.exportToPNG(relpath + "\\Output\\Ex2_{0}".format(str(ms.currentPageNumber) + ".png"))

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

0 Kudos
TheodoreF
Occasional Contributor II

How can I export each PDF using the page name in the output filename? SO far it seems I can only do it for page number...

0 Kudos
deleted-user-uXtLD1BYscf0
New Contributor III

Good question. I haven't got Pro 2.1 installed yet to test this out yet but it's not clear from the examples above how you would do this? 

This is what you used in Desktop: pageName = mxd.dataDrivenPages.pageRow.ZIP_CODE source: technical-article

0 Kudos
JeffBarrette
Esri Regular Contributor

We had various issues with implementing pageRow in time for the 2.1 release and unfortunately didn't think of this very basic request.  For 2.2 we will revisit implementing pageRow but should at least have an alternative solution like "CurrentPageName".

The only way I can think of solving this now is if you actually had a PageNumber field that map series worked from.  Then you could use cursors to return the row based on page number and then you could return the page name from the index layer.

Thank you for reporting this!

Jeff

0 Kudos
TheodoreF
Occasional Contributor II

Hi Jeff,

I and I'm sure many others, would like the ability to export Map Series using page name. We had it with ArcMap!

Regarding your cursor suggestion, it'd be great if you could post a python example code for this?

Thanks!

AnnHowland
New Contributor III

I'm having a similar issue...

I used the Map Series - ArcPy  page (https://pro.arcgis.com/en/pro-app/arcpy/mapping/mapseries-class.htm) to create a script to export all my maps in a map series.  I made the following code, using the examples (all the maps to .pdfs).  However, I still get an error I can't solve.  Here is the script I wrote and the error.  Any help would be appreciated.  How can it no recognize a page number when it's using the PageCount to go through the map series?

aprx = arcpy.mp.ArcGISProject(r"\\jc-gis\files\GisData\Atlases\Johnson City Atlas\Johnson City Atlas.aprx")
arcpy.env.overwriteOutput = True
outpath = (r"\\jc-gis\files\GisData\PrintShopMaps\PDFs\Atlas_Plain\\")
lytlist = aprx.listLayouts()[0]
if not lytlist.mapSeries is None:
mseries = lytlist.mapSeries
if mseries.enabled:
for pageNum in range(1, mseries.pageCount + 1):
mseries.currentPageNumber = pageNum
print("Exporting page {0}".format(mseries.pageRow.PAGENAME))
mappageName = mseries.pageRow.PAGENAME
lytlist.exporttoPDF(outpath + "JCAtlas" + mappageName + ".pdf", resolution=150, image_quality = "BEST")

Error:

Traceback (most recent call last):
File "Z:\GisData\Atlases\updatePDFMaps_ArcPro.py", line 23, in <module>
mseries.currentPageNumber = pageNum
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 109, in _set
return setattr(self._arc_object, attr_name, cval(val))
ValueError: Invalid page number '1'.

0 Kudos
JeffBarrette
Esri Regular Contributor

Hello Ann,

The reason you might be getting the error is because you may be using a field in your index feature class to drive page numbers.  Confirm this by looking at your map series optional settings.  There is an optional field called PageNumber.  If you are using a field driven page number and page number "1" does NOT exist in that field, you will get the error.  I just tried it and could easily reproduce your error message.

The script you current have works fine if a PageNumber field is not defined.

Rather than trying to iterate through the page numbers and export one page at a time, why not simply export the map series using the separate pages option using page name.

You could replace your code with:

if mseries.enabled:
    mseris.exportToPDF(outpath + "JCAtlas", multiple_files='PDF_MULTIPLE_FILES_PAGE_NAME', resolution=150, image_quality = "BEST")

Jeff

0 Kudos
AnnHowland
New Contributor III

Thanks for the tip. I also tried using a search cursor to go through each map page number and received the same error.

You are correct in assuming that I have fields called PAGENAME and PAGENUMBER. My first PAGENUMBER is 4, 5, 6, 11, …etc.. and is not sequential.

Thanks!

howlanda@johnsoncitytn.org

601 E Main St

Johnson City, TN 37601

Check out our online maps and information:

Map Gallery<http://www.johnsoncitytn.org/services/maps_and_data/map_gallery.php>

Ann Howland, GISP

Geospatial Analyst, IT Department

City of Johnson City, Tennessee

423.434.6188 / www.johnsoncitytn.org<http://www.johnsoncitytn.org/>

0 Kudos