Select to view content in your preferred language

Expression to define symbology

337
1
07-06-2023 06:12 AM
GIS_Ecologist
New Contributor III

Hello all,

 

I am working on a habitat mapping feature layer and need to write an expression to exclude null fields.

 

I have the layer setup with 5 fields utilising contingency selects (which is also not currently working on ArcGIS online but is on fieldmaps and pro). I need the symbology to select the field with a non empty cell to generate the appropriate symbology for that field.

 

I have build it as below with 5 levels of habitat characterisation of which I need it to be weighted to level 5, by which I need it to select the furthest right value which isn't null.

GIS_Ecologist_0-1688648840817.png

Any help on this would be much appreciated. I am fairly new to writing expressions and don't really know where to start.

 

Thanks and look forward to seeing your replies

0 Kudos
1 Reply
MicZatorsky_AEC
Occasional Contributor III

Add a field to store the value you want to use with Unique Values symbology e.g. "symbol_class"

Then populate that field -  if there is a Level5 value, use it, else look at the previous levels until you either have a class or there is none.  Since you may have nulls or spaces, or empty strings, handle those too.

The code for determining the class to use for symbology would be:

def getSymbolClass (Level1,Level2,Level3,Level4,Level5 ):
if Level5 is not None and str(Level5).strip() != "":
return Level5
if Level4 is not None and str(Level4).strip() != "":
return Level4
if Level3 is not None and str(Level3).strip() != "":
return Level3
if Level2 is not None and str(Level2).strip() != "":
return Level2
if Level1 is not None and str(Level1).strip() != "":
return Level1
else:
return "no class"

Used in the context of CalculateField:

arcpy.management.CalculateField("test", "symbol_class", "getSymbolClass(!Level1!,!Level2!,!Level3!,!Level4!,!Level5!)", "PYTHON3", """def getSymbolClass (Level1,Level2,Level3,Level4,Level5 ):
if Level5 is not None and str(Level5).strip() != "":
return Level5
if Level4 is not None and str(Level4).strip() != "":
return Level4
if Level3 is not None and str(Level3).strip() != "":
return Level3
if Level2 is not None and str(Level2).strip() != "":
return Level2
if Level1 is not None and str(Level1).strip() != "":
return Level1
else:
return "no class" """, "TEXT", "NO_ENFORCE_DOMAINS")

Repace "Test" with the name of your layer.