You can label objects with an expression. The Expression dialog is accessible from the Label Display tab on the Layer Properties dialog box and from the Label Content group on the LABELS tab on the ribbon.
Select Expression from the drop-down list in the Layer Properties dialog box or from the Label Using drop-down list on the Labels tab. Create the expression in the Expression dialog box. You can type the expression directly or use the drop-down lists to create it. For example, you want to label the countries of Africa with their name and population density on two lines. Your table contains the country names and population figures for each country. To figure the population density, divide population by each country's area. You can let MapInfo Pro calculate the area of each country using the Area function in the Expression dialog box. To create the expression, double-click the Africa layer in the Layers window and select the Label Display tab. Select Expression from the Label with drop-down list. The Expression dialog box displays. Using the drop-down lists, create the following expression:
Country + Chr$(13) + POPULATION / Area(Object, "sq mi")
The Chr$(13) function adds a carriage return to the first line. Using the Label tool, click a country. MapInfo Pro labels it with the result of the expression.
Creating Labels using Expressions
You can design your labels with just the right look and information you want for the object. You do this by writing an expression.
To create a label expression:
- In the Explorer window, in the Maps list double-click a layer (other than the Cosmetic Layer). Click the Label Display tab in the Layer Properties dialog box.
- Click Expression. The Expression dialog box opens.
- Type an expression to state what you want the label to include. Use the column, operator, and function lists to assist you.
- Verify the syntax of the expression with the Verify button.
- Click OK to close all of the dialogs and apply your changes.
The label expression applies both to automatic labels (which appear when you click the Label icon next to the layer name in the Layers window) and labels that you place by hand, by clicking with the Label tool.
Examples of Map Label Expressions
This example produces labels that tell MapInfo Pro to display with the county name in proper form (that is, first letter uppercase and the rest lowercase).
Proper$(County)
This example produces labels that specify the county name be all capital letters.
UCase$(County)
This example produces labels that have two columns in it, County and Population.
Proper$(County) + Chr$(13) + Population
Use the Str$ function to convert the population value into a character string so that the string concatenation operator ( ) can operate on it. "Chr$(13)" inserts a carriage return into the string, thus breaking it into two lines. The resulting label looks like this:
Cambria
47,934
This example produces labels that insert a colon into the label.
Proper$(County) + ":" + Chr$(13) + Population
The resulting label looks like:
Cambria:
47,934
This example produces labels that display the lowest address number and the highest address number, respectively, for street segments in a StreetPro table.
Minimum(FromLeft, FromRight)
Maximum(ToLeft, ToRight)
This example produces labels that contain the address range for a street segment. A space, a dash, and a space are inserted between the two numbers.
Minimum(FromLeft, FromRight) + " - " + Maximum(ToLeft, ToRight)
This example produces a two-line label with the street name on the first line and the address range on the second line.
Proper$(Street)+ ":" + Chr$(13) + Minimum(FromLeft, FromRight) + " - " +
Maximum(ToLeft, ToRight)
The resulting label looks like this:
Van Antwerp Av:
131 - 154