Select to view content in your preferred language

Print a different map based on a value in a featrure layer

714
4
Jump to solution
10-11-2023 08:25 AM
Labels (2)
MartijnvanOene
Emerging Contributor

Hello,

I'm using ArcGIS pro. I have a feature layer with the distribution of a lot of animals at my location. I need a pdf-map for each animal. I would like to automate this process. It seems that there is no standard function in ArcGIS for this. I looked for some Python scripts, but I don't have a lot of experience with this. Is there a simple way to automate this proces?

The result should  be about a hunderd pdf-files.

Thx,

Martijn

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
MartijnvanOene
Emerging Contributor

Thanks again Jesse, 

It seems like I need to delve into Python a bit more to really automate my process properly. After searching the internet for some code, I combined a bunch of snippets. Ultimately this gave me a script that does what I want. It's probably not that efficient yet, but I'll work on that later 🙂

Thank you fot taking the time to answer my question

import arcpy

docPath = r"C:\test\export"

aprx = arcpy.mp.ArcGISProject("CURRENT")

def unique_values(table, field):  ##uses list comprehension
    with arcpy.da.SearchCursor(table, [field]) as cursor:
        return sorted({row[0] for row in cursor})

#feauture layer with animals distribution
list_animals = unique_values("testSerie5","animals")

#Verwijzing naar de te gebruiken map
m = aprx.listMaps("Map")[0]

for animal in list_animals:
    print(animal)
    for lyr in m.listLayers("testSerie5"):
        print(lyr.definitionQuery)
        lyr.definitionQuery = "animals = '" + animal + "'"
        print(lyr.definitionQuery)
       
        lLayout = aprx.listLayouts()
        for l in lLayout:

            l.listElements("TEXT_ELEMENT")[0].text = animal
            print(l.listElements("TEXT_ELEMENT")[0].text)
            
            #You could add an if statement to print ONLY a specific layout
            l.exportToJPEG(docPath+"\\"+animal)

print(list_animals)

lyr.definitionQuery = ""

print("Process Completed")

 

 

 

View solution in original post

0 Kudos
4 Replies
JesseWickizer
Esri Contributor

Create a spatial Map Series where each page is the extent of each animal. If the animal distributions are unique polygons for each animal, that feature layer would be the index layer for your map series.

If the animal distributions contain multiple polygons, lines, or points for each animal then use the Dissolve tool to combine the animal distributions into single features per animal. Use the dissolved layer as the index layer for the map series. 

Then you can add a page query to the original feature class to only draw the animals from the feature class that are the focus of each page.

JesseWickizer_0-1697056266892.png 

JesseWickizer_1-1697056289450.png

 

 

0 Kudos
MartijnvanOene
Emerging Contributor

Hi Jesse,

Thx for your response. It's a creative way of thinking. The only problem in my case is that the extend for each map should always be my project area. Not the extend of the distribution of the animal.

 

But I will keep this workflow in mind, cause I think it will help me in other cases 🙂

Best regards,

Martijn

0 Kudos
JesseWickizer
Esri Contributor

Using a spatial map series would allow you to use page queries that would change the data that's drawn even though the extents would be the same for each map. 

If you want the extent to be the same project area, you could create an index layer that is the same extent or same point duplicated 100 times and assigned different names for each animal. Once the index features are duplicated you could quickly assign the unique names by joining to a table with the unique animal names by objectid and populating the index layer names from that.  

 

0 Kudos
MartijnvanOene
Emerging Contributor

Thanks again Jesse, 

It seems like I need to delve into Python a bit more to really automate my process properly. After searching the internet for some code, I combined a bunch of snippets. Ultimately this gave me a script that does what I want. It's probably not that efficient yet, but I'll work on that later 🙂

Thank you fot taking the time to answer my question

import arcpy

docPath = r"C:\test\export"

aprx = arcpy.mp.ArcGISProject("CURRENT")

def unique_values(table, field):  ##uses list comprehension
    with arcpy.da.SearchCursor(table, [field]) as cursor:
        return sorted({row[0] for row in cursor})

#feauture layer with animals distribution
list_animals = unique_values("testSerie5","animals")

#Verwijzing naar de te gebruiken map
m = aprx.listMaps("Map")[0]

for animal in list_animals:
    print(animal)
    for lyr in m.listLayers("testSerie5"):
        print(lyr.definitionQuery)
        lyr.definitionQuery = "animals = '" + animal + "'"
        print(lyr.definitionQuery)
       
        lLayout = aprx.listLayouts()
        for l in lLayout:

            l.listElements("TEXT_ELEMENT")[0].text = animal
            print(l.listElements("TEXT_ELEMENT")[0].text)
            
            #You could add an if statement to print ONLY a specific layout
            l.exportToJPEG(docPath+"\\"+animal)

print(list_animals)

lyr.definitionQuery = ""

print("Process Completed")

 

 

 

0 Kudos