0

I'm doing Maplex-Python labels for municipality polys with yields positive, zeroes and null values. I want to label all municipality polys by their municipality name, however I don't want to display yield labels for municipality polys with zero or null yield values. E.g. Bighorn and Ranchland have zero yield values and so yield values aren't labeled but their municipality name is labeled. However, my "else:" labels don't seem to plot municipality names - polys with "null" values - unnamed polys left to Bighorn and above Ranchland. What am I doing wrong?

def FindLabel ( [fcastyld.WH_D_L], [fcastyld.WH_D_H], [fcastyld.WH_D_A], [municipalities.NAME] ):
  if long([fcastyld.WH_D_A]) > 0:
    label = "L" + [fcastyld.WH_D_L] + "H" + [fcastyld.WH_D_H] + "A" + [fcastyld.WH_D_A] + "\n" + "<FNT name='Arial Narrow' size='5'><ITA><CLR red='104' green='104' blue='104'>" + [municipalities.NAME]  + "</CLR></ITA></FNT>"
  else:
    label = "<FNT name='Arial Narrow' size='5'><ITA><CLR red='104' green='104' blue='104'>" + [municipalities.NAME] + "</CLR></ITA></FNT>"
  return label

enter image description here

enter image description here

  • Can you paste your code as text and apply 'format code' to it please. I suspect you need a condition if [blah.blah] is None: branch first before if long([blah.blah]) > 0: to catch the Null values. – Michael Stimson Aug 21 '17 at 21:56
  • I've tried to add the formatted code. – Arun Govind Aug 21 '17 at 22:03
  • Are the values Null because there is no matching row in the join table or because the matching row has a Null value? – Michael Stimson Aug 21 '17 at 22:07
  • Yes values are null because there are no matching row in the join table. – Arun Govind Aug 21 '17 at 22:11
  • That can be difficult.. it's one of the many flavors of nothing but is hard to apply because the value is ethereal. Can you permanently join the attributes in the table using Join Field resources.arcgis.com/en/help/main/10.2/index.html#//… to make the Null value firm? – Michael Stimson Aug 21 '17 at 22:14
2

After a quick test:

def FindLabel (  [JoinTest.Grid]  ):
    if [JoinTest.Grid] == None:
        lab = 'No Match'
    else:
        lab = 'Matched'
    return lab

With a joined table I can say safely that join.field == None is a valid condition as at ArcGIS 10.2.1. To catch non-matched rows and label as if the value is 0 you can use this python code:

def FindLabel ( [fcastyld.WH_D_L], [fcastyld.WH_D_H], [fcastyld.WH_D_A], [municipalities.NAME] ):
    if [fcastyld.WH_D_A] == None:
        label = "<FNT name='Arial Narrow' size='5'><ITA><CLR red='104' green='104' blue='104'>" + \
                        [municipalities.NAME] + "</CLR></ITA></FNT>"
    elif long([fcastyld.WH_D_A]) > 0:
        label = "L" + [fcastyld.WH_D_L] + "H" \
                        + [fcastyld.WH_D_H] + "A" + [fcastyld.WH_D_A] + "\n" + \
                        "<FNT name='Arial Narrow' size='5'><ITA><CLR red='104' green='104' blue='104'>" + \
                        [municipalities.NAME]  + "</CLR></ITA></FNT>"
    else:
        label = "<FNT name='Arial Narrow' size='5'><ITA><CLR red='104' green='104' blue='104'>" + \
                        [municipalities.NAME] + "</CLR></ITA></FNT>"
    return label

The \ between lines are continuation characters to extend the string to the next line, for readability, they can be safely removed if they cause problems.

  • I've another issue Michael, can you please check our discussion board from yesterday? – Arun Govind Aug 22 '17 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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