Select to view content in your preferred language

Spatial Map Series: index layer by symbology

244
3
07-05-2024 09:15 AM
Status: Open
Labels (1)
ShannonJ
New Contributor III

I would like to suggest some additional functionality to the Spatial Map Series: create spatial map series by current symbology or by field.

Context from my screenshots, I want to export a series of maps of a landscape layer by SUBAREA.  each map should show all landscape features within that subarea. right now my work around is to dissolve the layer by attribute and use that as my spatial extent. While this is not a huge pain, it does create extra steps that I think could be solved by having the option to choose the field to base the extents on. Maybe under layer there could be:

- create index by symbology

- create index by attribute

ShannonJ_0-1720195484728.png

When I saw the "group by" option I got excited thinking I had solved my own problem, but that simply groups the layouts. 

ShannonJ_1-1720195588940.png

This is a fairly common workflow for me so saving a few steps can make a big difference! 

 

thanks,

3 Comments
JeffBarrette

@ShannonJ would you be interested in an Python Map Automation (arcpy.mp) snippet.

What it would do is get a list of unique field values to iterate over, select all features with that value, set the extent of the map frame to the selected features, and export before moving onto the next unique value.  Individual pages could be generated or, if a PDF, optional, appended all into a single PDF.

Jeff - arcpy.mp and Layout teams

ShannonJ

Hi @JeffBarrette , thanks for you reply - I would be interested in the snippet, it sounds like it'll get me half way there. Ideally I'd be able to review the layouts before exporting as I label the features as well so there is always some refinement to do rather than an export and done. It sounds like what you're describing above does the export without being able to review first?

 

thanks! 

JeffBarrette

@ShannonJ Below is a snippet of code.  Keep in mind that there are number of different approaches and things to consider.  In the example below, I'm exporting a Layout, not a map series.  If you have dynamic text and other features managed by the map series, then you could need to update that using arcpy.

import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])

p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'MapSeriesExamples.aprx'))
m = p.listMaps('StatesWithRegions')[0]
l = m.listLayers('States_WithRegions')[0]

#unique values in layer
all_values = [row[0] for row in arcpy.da.SearchCursor(l, 'sub_region')]
unique_values = set(all_values)
print(unique_values)

#reference layout and map frame
lyt = p.listLayouts('BasedOnSelection')[0]
mf = lyt.listElements('MapFrame_Element', 'ZoomToRegion')[0]

#create
comboPDF = arcpy.mp.PDFDocumentCreate(os.path.join(relpath, 'Output', 'CombinedOutput.pdf'))

#iterate through the unique list of field values and:
# - create a selection
# - set the map frame extent to that selection
# - export to temp PDF, combine into combo pdf, then delete the temp pdf
# - clear the selection
for value in unique_values:
    query = f"SUB_REGION = '{value}'"
    arcpy.SelectLayerByAttribute_management(l, 'NEW_SELECTION', query)
    mf.camera.setExtent(mf.getLayerExtent(l, True, True))
    lyt.exportToPDF(os.path.join(relpath, 'Output', 'temp.pdf'))
    comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp.pdf'))
    os.remove(os.path.join(relpath, 'Output', 'Temp.pdf'))
    arcpy.SelectLayerByAttribute_management(l, 'CLEAR_SELECTION')

comboPDF.saveAndClose()
os.startfile(os.path.join(relpath, 'Output','CombinedOutput.pdf'))
print('Finished')

Capture.PNG

Jeff