I am working on a script/geoprocessing tool where, once a month, my users can export the feature classes they need from an Enterprise Geodatabase to a File Geodatabase. So they can essentially do their analysis without impacting the source data.
I aim to create a tool that extracts the feature classes and adds them to the map I did. Then, I want to symbolize the feature class, which I've also gotten working on. However, now I am trying to label the features for them, and I can get it to work, but I was trying to do more with it.
Each protected area polygon has a NAME and a GRADEID. I want to concatenate those two fields so it reads "Protected Area Name: GRADEID #". The code I have so far will turn on the labels for either the Protected area name or the Grade ID, but it doesn't return anything when I try to return both.
Here is a sample of the table with the names and grades.
Here is what my map currently looks like.
Just the GradIDs
Finally here is my code so far.
import arcpy
import arcpy.mp as map
arcpy.env.overwriteOutput = True
arcpy.env.workspace = arcpy.GetParameterAsText(0)
arcpy.conversion.FeatureClassToGeodatabase(
Input_Features=r"C:\PPCAnalysis\PPCAnalyis\ISRB_DATA.sde\DBO.FireStations;C:\PPCAnalysis\PPCAnalyis\ISRB_DATA.sde\DBO.Hydrants;C:\PPCAnalysis\PPCAnalyis\ISRB_DATA.sde\DBO.Idaho;C:\PPCAnalysis\PPCAnalyis\ISRB_DATA.sde\DBO.ProtectedAreas",
Output_Geodatabase=r"C:\PPCAnalysis\PPCAnalyis\PPC_AnalyisisData.gdb"
)
arcpy.env.workspace = r"C:\PPCAnalysis\PPCAnalyis\PPC_AnalyisisData.gdb"
aprx = map.ArcGISProject("CURRENT")
for m in aprx.listMaps("PPCAnalyisData"):
m.addDataFromPath(r"C:\PPCAnalysis\PPCAnalyis\PPC_AnalyisisData.gdb\FireStations")
m.addDataFromPath(r"C:\PPCAnalysis\PPCAnalyis\PPC_AnalyisisData.gdb\Hydrants")
m.addDataFromPath(r"C:\PPCAnalysis\PPCAnalyis\PPC_AnalyisisData.gdb\Idaho")
m.addDataFromPath(r"C:\PPCAnalysis\PPCAnalyis\PPC_AnalyisisData.gdb\ProtectedAreas")
for m in aprx.listMaps("PPCAnalyisData"):
for lyr in m.listLayers("ProtectedAreas"):
if lyr.isFeatureLayer:
lyr.transparency = 50
sym = lyr.symbology
sym.updateRenderer('UniqueValueRenderer')
sym.renderer.fields = ["NAME"]
lyr.symbology = sym
updatedProtectedAreas = "ProtectedAreas"
m = aprx.listMaps("PPCAnalyisData")[0]
for m in aprx.listMaps("PPCAnalyisData"):
for lyr in m.listLayers("ProtectedAreas"):
lblClass = lyr.listLabelClasses()[0]
print(lblClass.name)
lblClass.expression = "$feature.GRADID"
lyr.showLabels = True
Any suggestions on how I can get the names and the grades to print together would be great. Thank you.
Solved! Go to Solution.
lblClass.expression = '$feature.Area_Name +": " +$feature.GRADEID'
should be something like this, I think?
lblClass.expression = '$feature.Area_Name +": " +$feature.GRADEID'
should be something like this, I think?
I tried that, and nothing happened.
Whoops I typed in a field name wrong, it's working now😁
Lol glad it worked.