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?
Solved! Go to Solution.
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] )
check on the advanced checkbox
Thanks Dan.
But what is the code that lets the labels appear vertically instead of horizontally?
def FindLabel ( [Male], [Female]):
return "{}, {}".format ( [Male], [Female])
"{},\n{}" plus the rest
\n is the newline in python
Thanks Dan.
The code is below:
[Male] + "\n" + [Female]
The code below is useful
"Female:" + Text($feature.Female, '#,###') + "\n" + "Male:" + Text($feature.male, '#,###')
[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.
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
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] )
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