ArcGIS Pro 2.5: How to label features based on two fields?

10340
12
Jump to solution
02-28-2020 10:50 AM
JamalNUMAN
Legendary Contributor

ArcGIS Pro 2.5: How to label features based on two fields?

 

For example, in ArcMap features can be labeled based on two fields such that labels can aligned vertically by using the expression below:

 

[Male]  & vbnewline & [Female]

 

How this can be performed in Pro?

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
1 Solution

Accepted Solutions
AhmadSALEH1
Occasional Contributor III

 Honestly, I was mixing the Labels expressions with Field calculator operations!

in the Field calculator, there is no VBScript option anymore! but in the label expressions, it's still there and you can use it as the following.

"Area A: "& [Area_A] & vbnewline & "Area B: "&[Area_B] & vbnewline & "Area C:"& [Area_C]

If you decided to use python here is how you can do it, but again I was under the assumption that the label expressions behave exactly as the field calculator;  this is why I suggested using "!" instead of []  which was wrong.

here is the correct way to do it:

def FindLabel ( [Area_A], [Area_B], [Area_C] ):
    mylabel="Area A:"+[Area_A]+"\n" +"Area B: "+[Area_B]+"\n"+"Area C: "+[Area_C]
    return mylabel

Or a more concise method by using .format to concatenate the string  as Dan mentioned in his post

def FindLabel ([Area_A], [Area_B], [Area_C] ):
    return "Area A:{}\n Area B:{}\n Area C:{}".format([Area_A], [Area_B], [Area_C] )

View solution in original post

12 Replies
DanPatterson_Retired
MVP Emeritus

check on the advanced checkbox

JamalNUMAN
Legendary Contributor

Thanks Dan.

 

But what is the code that lets the labels appear vertically instead of horizontally?

def FindLabel ( [Male], [Female]):
    
    
    return "{}, {}".format ( [Male], [Female])

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
DanPatterson_Retired
MVP Emeritus

"{},\n{}"  plus the rest

\n is the newline in python

JamalNUMAN
Legendary Contributor

Thanks Dan.

 

The code is below:

[Male] + "\n" + [Female]

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
JamalNUMAN
Legendary Contributor

The code below is useful

"Female:" + Text($feature.Female, '#,###') + "\n" + "Male:" + Text($feature.male, '#,###')

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
AhmadSALEH1
Occasional Contributor III

[Male] + "\n" + [Female] will not work becuase [] are vba expressions which is not used in Pro anymore.

if you are using python expressions use! instead of []

!Male! + "\n" + !Female! 

Although, it looks like Arcade has more potential in Pro.

JamalNUMAN
Legendary Contributor

Many thanks Ahmad for the elaboration

 

I would appreciate if you provide me with the code that labels my feature class with the format shown in the screenshot below. The feature class is attached

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
AhmadSALEH1
Occasional Contributor III

 Honestly, I was mixing the Labels expressions with Field calculator operations!

in the Field calculator, there is no VBScript option anymore! but in the label expressions, it's still there and you can use it as the following.

"Area A: "& [Area_A] & vbnewline & "Area B: "&[Area_B] & vbnewline & "Area C:"& [Area_C]

If you decided to use python here is how you can do it, but again I was under the assumption that the label expressions behave exactly as the field calculator;  this is why I suggested using "!" instead of []  which was wrong.

here is the correct way to do it:

def FindLabel ( [Area_A], [Area_B], [Area_C] ):
    mylabel="Area A:"+[Area_A]+"\n" +"Area B: "+[Area_B]+"\n"+"Area C: "+[Area_C]
    return mylabel

Or a more concise method by using .format to concatenate the string  as Dan mentioned in his post

def FindLabel ([Area_A], [Area_B], [Area_C] ):
    return "Area A:{}\n Area B:{}\n Area C:{}".format([Area_A], [Area_B], [Area_C] )

DanPatterson_Retired
MVP Emeritus

As shown in my post... https://community.esri.com/thread/249062-arcgis-pro-25-how-to-label-features-based-on-two-fields#com... 

which is another reason not to type what you think is the field formatter, but to select the fields from the list of available fields