0

I am using ArcMap 10.8.

I have 2 attributes: Toponym and Type.

  • Toponym gives the name
  • Type indicates if it is a city, town, church, etc.

In English, I would like if Type = town, then capitalize Toponym; if Type = church, then italicize Toponym; and so on. I don't know enough of python to be able to combine the functions, or if even VB script is better. I've found how to change font size and color if specifics are met but I couldn't quite make it work with what I need (changing font & color).

I got this far to capitalize all Toponyms:

def FindLabel ([Toponym]):
  S = [Toponym]
  S = S.upper ()
  return S

but am unable to combine:

def FindLabel ([Toponym], [Type]):
  S = [Toponym]
  if [Type] == 'Town'
    return S.upper()
1
  • Have you considered writing the label expression in Arcade? (developers.arcgis.com/arcade) I haven't used it, but my understanding is this kind of complex labeling is exactly what it is designed for. Although you may have to be using Pro instead of Desktop to have access to it. Commented Apr 27, 2021 at 14:05

2 Answers 2

2

While @Hornbydd's answer directly addresses your question, I wanted to point out that another approach to solving this would be to use Label Classes, which are the built-in solution for accomplishing exactly what what you are trying to do: label different features different ways depending on a specific set of criteria. A very very basic primer on label classes is at https://desktop.arcgis.com/en/arcmap/10.3/map/working-with-text/displaying-labels-using-label-classes-to-label-fea.htm. Essentially though, the idea is, you create a separate label class for each type of label you want and specify a SQL Query that indicates what features are included in each class. (There is an easy button if you want the label classes to match your symbology classes.) Then, for each label class, you would specify all the normal label settings separately, meaning the Town label class could be upper case, while the Church label class is italics, etc... Some of the advantages to this method are, you can individually turn label classes on and off as needed (so you can test how different labels look, or specify what is and isn't labeled for different map views), you can specify different placement settings (so towns could label above the town point while churches label to the right of the point), you can specify different range settings (so towns always label but churches only label upon zooming in), and you can set separate label weights and priority so if an area is too crowded to label everything you can specify which types of labels should be placed first.

I know label classes can be confusing, so feel free to ask if you need a bit more clarification.

1
  • 1
    I realize that I didn't thank you guys! Thank you all. I managed to combine your answers and it worked nicely :-)
    – Nautilaus
    Commented Sep 15, 2022 at 12:18
2

You are mixing languages (VB and python), that's why your code is not working. Make sure the parser is set to PYTHON and here is an example of either printing the label in upper case or in italics:

def FindLabel ( [TYPE] , [LABEL] ):
  if [TYPE] == "School":
    return [LABEL].upper()
  else:
    return "<ITA> " + [LABEL] + "</ITA>"

Note: you were missing the colon at the end of the if statement

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.