Tuesday, December 13, 2016

QGIS - Labeling a shapefile layer using two or more attributes information

Hello there,
There may be a situation whereby you want to display more than one attribute information or label of the shapefile map canvas you are working on. If this sounds like you, then you are reading the right tutorial.

In this post, I will discussed how to: Label a shapefile layer using two or more attributes information in QGIS.

Labeling a Shapefile Layer Using Multiple Attributes Information

Now, I assumed you already now how to label your shapefile map canvas by using a single attribute's information. This is fairly simple and it is what you will be taught in your first GIS training class.
What you probally don't know is that you can make use of more than on attribute information to label your map features in QGIS. This is made possible by the use of "QGIS label expression" command.
That is what QGIS expression in the label expression is used for.


The shapefile am going to use for this demonstration as seen above, has five (5) columns/fields of attributes which are: FID, State_Name, Area, Capital and Population. Now, lets label the map with as single attribute field then with multiple attribute fields.


Labeling using one attribute field


To label your map as usual using a single attribute field, proceed thus:-
1) Open the layers "Properties"
2) Select "Labels" tab and choose show "show label for this layer".
3) Under "Label with", select the field name you wish to use for the label



4) Click on "OK".



Labeling using multiple attribute fields

Here we want more labels on the map, let say we want the state names and their populations to be labels on the map. Here is how to go about it:-
1) Open the layers "Properties"
2) Click on the "Expression Dialog" button just beside the "Label with" box


3) In the "Expression Dialog" that opened, enter the expression as seen below;-
There are different flavors of doing this as seen below. The import thing to note here is the special character "||" which joins the fields together and separator (newline, tab, space, dash etc) characters that comes between the "||".

Flavor 1: Separated on Next Line
"State_Name" || '\n' || "Population"

"State_Name" || '
' || "Population"



Flavor 2: Separated with Space
"State_Name" || ' ' || "Population"



Flavor 3: Separated with any Character
"State_Name" || ' - ' || "Population"

4) Type the expression for any of the flavors you want and press "OK" to apply the labeling.






Thank you for following.

No comments:

Post a Comment