Hello everyone,
I'm fairly new to this and when trying to google my way towards a solution, I've gotten stuck - so I'd appreciate any and all constructive feedback and guidance you could give me.
ArcGIS Pro version: 2.7.1
The situation: I have a shapefile which contains distribution data (points) for many species. From it I need to get distribution maps (.jpg), in a way that there's one species shown on each map. The points need to be represented with the same symbol, but different colour (based on the value in a specific field in the attribute table, the values being "published" and "unpublished"). The extent, scale bar, north arrow and legend are all the same, with the name of the species for which the map is being written either in the legend, or in a dynamic text field.
I know I can do that manually, by setting up an SQL definition query, varying the species name and exporting each map manually, but I have hundreds of species in the shapefile and that would take a lot of time... so I'm looking for a smarter, automated, solution.
What I tried: At first I tried using Map Series, but that returns one map per data point (thousands of maps), all with different extents. It didn't matter if I set the species' name in the Group By field, I got the same result. I'm hoping that there's a way to get what I need through Python. To that extent, I tried cobbling up a script and got this far:
Spoiler# import arcpy module:
import arcpy
# overwrite output:
arcpy.env.workspace = "CURRENT"
arcpy.env.overwriteOutput = True
# Output path:
OutPath = r'G:\01_Fast_DATA\ArcGisPro\Kristian_diplomski\Kristian_diplomski.gdb'
# Use this if you need to check the exact spelling of the field name:
for field in fields:
print("{0} is a type of {1} with a length of {2}"
.format(field.name, field.type, field.length))
# Get list of unique values that will be used for iteration:
fc = r"G:\01_Fast_DATA\ArcGisPro\Kristian_diplomski\Kristian_diplomski.gdb\extract_KM_20210211_bezRegija"
field = 'CrossVal_samo_vrsta'
values = [row[0] for row in arcpy.da.SearchCursor(fc, field)]
uniqueValues = set(values) # uniqueValues is now the list of unique values -> that's the variable that needs to be called
# print(uniqueValues) # this is not necessary, but may be useful in some other cases
# iterate definition query for each unique value in uniqueValue and export the map using a specific map layout:
# error trapping:
try:
for uniqueValue:
# Make a layer from the feature class
layer = arcpy.management.MakeFeatureLayer('extract_KM_20210211_bezRegija',"CrossVal_samo_vrsta" = uniqueValues)
except:
print(arcpy.GetMessages())
Where I think I'm stuck: I'm not sure how to proceed with the for loop in the script. I know(?) I need to write something like "for every unique species name in the uniqueValue list make a selection using the first name from the list, with the layout set the way it has to be and the species' name spelled out somewhere on the map... then export that as a .jpg at a specified location... then make a new selection, using the next name on the list, repeat the other steps... and then keep looping until it's been done for the last species on the list", but how to get that into Python - that's where I'm at a loss.
Any help would be much appreciated.
Thanks,
M