0

I'm on ArcGIS Pro (self-taught) and I am trying to make a batch of layouts for different species occurrence records over the same extent. I have all the XY to Point data as a layer and have been using the display filter to limit which species is shown, then manually exporting the layout, and changing the species again. All other factors are the same, save the species. I want to automate this since I have 80 or so to do (and do this often).

Ideally, I want to create a layout for each species, with the same extent, layers, etc, but with a different species selected from the XY to Point layer. I then want to export the layout with the name of the species selected.

This is the code I have so far, and it all seems to work (i.e. it exports a pdf for each, with the layers I can see looking good, and runs without errors) but it has an odd extent, off to the right of the continental U.S., and a North arrow that is not in the layout I am calling. I got the extent values from the extent on the formatted layout/mapframe by looking in properties and copying the values there.

import arcpy, os

#Project path
aprx = arcpy.mp.ArcGISProject(
    r"pathtoproject.aprx")

# Set the name of the XY to Point table
table_name = "ScioSpecies"

# Set the name of the field that contains the class names
class_field = "Species"

#Set a reference to the map view in my project
map_view = aprx.listMaps()[0]


# Get a reference to the layout
layout = aprx.listLayouts()[0]

#Setting up layout/mapframe
map_frame = layout.listElements("MAPFRAME_ELEMENT")[0]
extent = arcpy.Extent(5331425.860609497, -12839586.820429197, -12017230.660916878, 4267200.242417085)
map_frame.camera.setExtent(extent)

class_list = []
with arcpy.da.SearchCursor(table_name, class_field) as cursor:
    for row in cursor:
        if row[0] not in class_list:
            class_list.append(row[0])
#Verify all species are present
print(class_list)

for species in class_list:
    arcpy.SelectLayerByAttribute_management(table_name, "NEW_SELECTION", "Species = '{}'".format(species))
    layout.exportToJPEG(
        r"pathtosavefile{}.jpg".format(species),
        resolution=800)

7
  • You can use data driven pages for it. Dissolve points to 80 multipoints, minimum bounding geometry are DDP.. Use definition query to display single species at page.
    – FelixIP
    Feb 17, 2023 at 19:51
  • I'm on ArcGIS Pro- I've done a map series, but the extent is always dependent on the points, and since some species are clustered in specific regions, I end up with each map with a different extent. Does DDP on ArcMap allow for extent to stay exactly the same? Feb 20, 2023 at 23:42
  • Yes,of course. Just create 80 identical large rectangles, add field species and populate it accordingly. Just create 1 rectangle, clone it on your map and repeat few appends.
    – FelixIP
    Feb 21, 2023 at 4:33
  • Thank you! Making a rectangle was a great idea, and I was able to get it working, see edit above Feb 23, 2023 at 21:56
  • Please cut/paste your self-answer from the area reserved for your question into the area reserved for answers.
    – PolyGeo
    Feb 23, 2023 at 22:01

1 Answer 1

0

UPDATE: I was able to make my series of maps have the same extent by creating a rectangle and using it to define the extent.

Here's the code if anyone else needs it.

#Project path
aprx = arcpy.mp.ArcGISProject(
    r"projectpath.aprx")


# Set the name of the field that contains the class names
class_field = "Species"

# Set Map View and Layout and Map Frame
map_view = aprx.listMaps("Map")[0]
layout = aprx.listLayouts("Layout2")[0]
map_frame = layout.listElements("MAPFRAME_ELEMENT")[0]

# Set species layer
species_lyr = map_view.listLayers("ScioSpecies")[0]

# Set shapefile polygon to custom extent
customextent = map_view.listLayers("customextent")[0]

# Set output
output_folder = output path

#clear out all the existing definitionqueries
species_lyr.updateDefinitionQueries([])


# Grab each species, and make sure all are present
class_list = []
with arcpy.da.SearchCursor(species_lyr, class_field) as cursor:
    for row in cursor:
        if row[0] not in class_list:
            class_list.append(row[0])

print(class_list)


#set the extent based on the species layer 
map_frame.camera.setExtent(map_frame.getLayerExtent(customextent, False, True))

#you can have a text box in your layout with a name, and change it to #species name
#species_txt = None
#for txt in layout.listElements("TEXT_ELEMENT"):
#    if txt.name == "SpeciesName":
#        species_txt = txt
#        break

#Loop for each species
for species in class_list:
    species_lyr.definitionQuery = "{0} = '{1}'".format(class_field,species)
    outfile = "{0}\\{1}.pdf".format(output_folder,species)
    layout.exportToJPEG(
        exportfolder".format(species),
        resolution=900)
    print("Successful export of ", species)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.