Map Typography – A Python Label Expression

Posted by in ArcMap, GIS, Labeling

Recently, I had to label parcels with APN & owner information. The parcel feature class has the APNs and the ownership table is joined based on the APNs. I’ve been commiting to using python in labeling expressions whenever possible and this was a good chance to use an advanced expression.

One problem was that the owner in the join table was all caps, which I planned to convert to title case in the expression. I also planned to add formatting tags. A lot of the owners include an & in the owner name. I used python to convert the & to & in order to display correctly with the use of formatting tags.

01

Based on the data in the table, I want the APN labeled, in a bold typeface and black. I want the Assessee on a new line, smaller, grey and in italics.

In the Label Expression window, set the parser to Python and check the Advanced checkbox.

02

Here’s the code:

1
2
3
4
5
6
7
8
9
def FindLabel ([Parcels_MontereyCounty2013.APN],[Parcel_data.Assessee]):
  apn = [Parcels_MontereyCounty2013.APN]
  own = [Parcel_data.Assessee]
  if own == None:
    L = apn +"\n"+"<fnt size='6'><ita><clr black='70'>"+"Unknown"+"</clr></ita></fnt>"
  elif own != None:
    ownT=own.title()
    L = apn +"\n"+"<fnt size='6'><ita><clr black='70'>"+ownT.replace("&","&amp;")+"</clr></ita></fnt>"
  return L

Here’s the resulting label:

03

The first line defines the fields being used in the label.

1
def FindLabel ([Parcels_MontereyCounty2013.APN],[Parcel_data.Assessee]):

The next two lines define the variables apn & own to the corresponding fields in the joined parcel dataset.

1
2
  apn = [Parcels_MontereyCounty2013.APN]
  own = [Parcel_data.Assessee]

The if statement catches any <null> assessee’s and defines the label (variable L) as the APN number, then a new line (“\n”) then the word “Unknown” in fnt size 6 at 70% black. Without this, any <null> assessee’s would not label at all.

1
2
  if own == None:
    L = apn +"\n"+"<fnt size='6'><ita><clr black='70'>"+"Unknown"+"</clr></ita></fnt>"

The elif statement defines the label (L) for the non-null assessees. The next line creates a new variable, a conversion of the assessee string to title case. Then L is defined as the APN number, then a new line, then the title case assessee with any & replaced with &amp; along with formatting tags to return a 6pt, italics, 70% grey assessee.

1
2
3
  elif own != None:
    ownT=own.title()
    L = apn +"\n"+"<fnt size='6'><ita><clr black='70'>"+ownT.replace("&","&amp;")+"</clr></ita></fnt>"

Finally the last line returns either version of L, the full label for each parcel.

1
  return L

Fancy labels with python. Labels formatted nicely without creating any new data.

Leave a Reply