Label Expressions - anthonyblackham/GIS-Wiki GitHub Wiki

Label Expressions provide more control over how labels are presented.

For example I have a layer of 3 different points with 3 different colours. I want the label to match the colour of the symbology.

The two fields I'm interested in are comments and type. The different colours/symbology is defined by the type where the comments are what I want labeled. We are going to use an if then statement to set it up.

Function FindLabel ( [Comments], [Type] )
if ([Type] = "Access Point") then
  FindLabel ="<CLR red='255' green='255' blue='0'>" & [Comments] &"</CLR>"
elseif ([Type]="Culvert") then
  FindLabel ="<CLR red='0' green='0' blue='255'>" &[Comments]&"</CLR>"
elseif ([Type]="Gate") then
  FindLabel ="<CLR red='132' green='0' blue='168'>" &[Comments]&"</CLR>"
else
  FindLabel = "<CLR red='132' green='0' blue='168'>" &[Comments]&"</CLR>"
end if
End Function

Basically if the type is a certain field, we define the comments field for that type to be the same colour as defined in the symbology. You can set it for as many fields as you like. Then the last else should cover for anything else you don't define.

⚠️ **GitHub.com Fallback** ⚠️