1

I have a table of contents with multiple owner agencies that may or may not have an acreage value in the field and am trying to get a dynamic label expression to only write out the label for the fields that have values.

For example, if the fields were BLM, USFS, Private, and their values were 10.2, "Null", and 5.5 respectively, I would like the dynamic label to read

BLM: 10.2 acres
Private: 5.5 acres

where it skips USFS due to the "Null" value. So far, I have only been able to get this code that I know is incorrect. It returns only the first true value and then does not go to the next in the list.

Function FindLabel ( [BLM] , [BR] , [Private] , [SITLA] )
  if ( ( [BLM] ) > 0) then  
    FindLabel = "BLM: " + [BLM] + " acres"
  elseif  ( ( [BR] ) > 0) then  
    FindLabel = "BR: " + [BR] + " acres"
  elseif  ( ( [Private] ) > 0) then  
    FindLabel = "Private: " + [Private] + " acres"
  elseif  ( ( [SITLA] ) > 0) then  
    FindLabel = "SITLA: " + [SITLA] + " acres"
  end if 
End Function

Attribute table:

Attribute table

1
  • I saw multiple similar posts and the best advise: do not use advanced labelling at all. Simply apply "Define classes of features and label each class differently". This will save your a LOT of time and frustration
    – FelixIP
    Commented Jul 15, 2016 at 3:20

1 Answer 1

4

Using the Python Parser in the Label Expression window, check on the Advanced box and enter the following:

def FindLabel ( [BLM] , [BR] , [Private] , [SITLA] ):
    xBLM = xBR = xPrivate = xSITLA = ""
    if [BLM]:
        xBLM = "BLM: {} acres \n".format([BLM])
    if [BR]:
        xBR= "BR: {} acres \n".format([BR])
    if [Private]:
        xPrivate= "Private: {} acres \n".format([Private])
    if [SITLA]:
        xSITLA= "SITLA: {} acres \n".format([SITLA])

    return "{}{}{}{}".format(xBLM, xBR, xPrivate, xSITLA)

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.