Creating conditional labeling using MapInfo Pro

Products Affected: MapInfo Pro 11.x and above
What is a Conditional Label?

A conditional label is a way of displaying label based on the certain value(s) of fields. One typical use case would be if you want to label only certain features in your layer (point, line or polygon). For example, conditional label can be used to highlight a polygon with an area greater than a certain defined value, a line feature to represent roads with tolls or a point feature to represent cities with population greater than a threshold defined. If conditions are not applied, all features get labelled.

How to Create a Conditional Label using MapInfo Pro

There is a way to create conditional label without creating a query. The trick here is to use a label expression that incorporates a condition within the Int() function. The expression will yield a result of zero or one and this result will control whether or not a label will appear for any given item in the map.

In Mapinfo 17 64-bit the expression is set in the Label Using dropdown on the Layer Tools > Labels tab.

User-added image

Given a field containing numeric values, the following expression will avoid creating label for any value that is zero:

Left$(Str$(COLUMN_NAME), Int(COLUMN_NAME > 0) * Len(Str$(COLUMN_NAME)))

The technique mentioned above can be used in different ways. The following are two more examples:

The following expression will label any value above 50,000.

Left$(Str$(COLUMN_NAME), Int(COLUMN_NAME > 50000) * Len(Str$(COLUMN_NAME)))

Given a character column containing classified data ("type" data), you could avoid the labelling of one of the types. Let's say a set of points represents different types of medical practices. The types are GPs, paediatricians, cardiologists, neurologists, etc. The following expression will label all of the different types except for GPs.

Left$(Str$(COLUMN_NAME), Int(COLUMN_NAME <> "GP") * Len(Str$(COLUMN_NAME)))

Finally, to label only the GPs, just change the <> expression to =

Left$(Str$(COLUMN_NAME), Int(COLUMN_NAME = "GP") * Len(Str$(COLUMN_NAME)))


Conditional Label Map

This example will show the value of the DateTime in the location_date_time column where the time is later than 15:00:00.

Left$(Str$(location_date_time), Int(GetTime(location_date_time)>StringToTime("15:00:00"))*Len(Str$(location_date_time)))
UPDATED:  August 16, 2019