I went ahead with not adding an additional field. I am not concerned with performance issues.
I arrived at the following at it does exactly what I wanted, thanks for everyone's input.
## The following label expression function is used to display labels for the main water lines.
Specifically, labeling water lines that have not been assigned Plan info, with “Plan ?”
Also, any water lines that are attributed as ABANDON will not display a label.
Lastly, all other water lines will be labeled/displayed as is.
Note: Displayed labels only if water main lines are greater than 50 feet.
lyrName = " Main Lines Plan Label"
shapeDict = {}
with arcpy.da.SearchCursor(lyrName, ("OID@","SHAPE@LENGTH")) as cursor:
for row in cursor:
shapeDict[row[0]] = row[1]
def FindLabel([OBJECTID],[PLAN], [AGENCY]):
oid = int([OBJECTID])
if [AGENCY] == "ABANDON":
return None
elif [PLAN] in (None, " ") and shapeDict[oid] > 50 :
return "Plan ?"
elif shapeDict[oid] > 50 :
return [PLAN]
I have the following as well but that last line is giving me problems. If I use else without the > 50 condition, it is fine.
## The following label expression function is used to display labels for the main water lines.
Any water lines that are attributed as ABANDON will not display a label.
Any water lines that are attributed as unknown(999) will be labeled as “Size ?”
Also, water lines that are attributed as NULL (None) will be labeled as “Size ?”
Lastly, all other water lines will be labeled/displayed as is.
Note: Displayed labels only if water main lines are greater than 50 feet.
Note: '\x22' Python syntax is used to allow for double quotes in the label expression to represent inches.
lyrName = "Main Lines Diameter & Material Label"
shapeDict = {}
with arcpy.da.SearchCursor(lyrName, ("OID@","SHAPE@LENGTH")) as cursor:
for row in cursor:
shapeDict[row[0]] = row[1]
def FindLabel ( [OBJECTID], [DIAMETER], [MATERIAL], [AGENCY] ):
oid = int([OBJECTID])
if [AGENCY] == "ABANDON":
return None
elif [DIAMETER] in "999" and shapeDict[oid] > 50:
return "Size ?" + '\x22' + " " + [MATERIAL]
elif [DIAMETER] in (None, " ") and shapeDict[oid] > 50:
return "Size ?" + '\x22' + " " + [MATERIAL]
elif shapeDict[oid] > 50:
return [DIAMETER] + '\x22' + " " + [MATERIAL]