../../../../_images/image710.png

Module 7: Labels and Classification

Objectifs d’apprentissage

  • Explore attribute data of an object and understand the uses of different types of data
  • Add labels to vector layers
  • Symbolise vector data using categories

Up to now, none of the changes we have made to the map have been influenced by the objects that are being shown. In other words, every type of vegetation looks alike, and all the roads look alike. When looking at the map, the viewers don’t know anything about the roads they are seeing; only that there is a road of a certain shape in a certain area.

But the whole strength of GIS is that all the objects that are visible on the map also have attributes. Maps in a GIS aren’t just pictures. They represent not only objects in locations, but also information about those objects. In this lesson we will explore the attribute data of an object and understand what the various data can be useful for.

If you would like to start with the examples used in this module, begin by opening the QGIS project sleman_2_6.qgs.

1. Attribute data

  1. Open the attribute table for the POI_Sleman_OSM layer by selecting it in the Layers panel and clicking the Open Attribute Table button (or right-click on the layer and select Open Attribute Table).
../../../../_images/image401.png
  1. Which field would be the most useful to use as a label?
../../../../_images/image1171.png

You now know how to use the attribute table to see what is actually in the data you’re using. A dataset will only be useful to you if it has the attributes that you care about. If you know which attributes you need, you can quickly decide if you’re able to use a given dataset, or if you need to look for another one that has the required attribute data.

Different attributes are useful for different purposes. Some of them can be represented directly as text for the map user to see. Next we’ll see how to use attributes as labels, so that users can see the text on your map.

2. Label tool

Labels can be added to a map to show any information about an object. Any vector layer can have labels associated with it. Labels rely on the attribute data of a layer for their content.

There are several ways to add labels in QGIS, but some are better than others. You may notice that when you open the Layer Properties window for a layer, there is a tab called “Labels.” While this tab is designed to put labels on your map, it is not nearly as good as the so-called “Label Tool,” which we will learn in this section. Before being able to access the Label tool, you will need to ensure that it has been activated.

  1. Go to the menu item View ‣ Toolbars.
  2. Ensure that the Label item has a checkmark next to it. If it doesn’t, click on the Label item, and it will be activated. The Label toolbar looks like this:
../../../../_images/image1181.png
  1. Click on the POI_Sleman_OSM layer in the Layers panel, so that it is highlighted.
  2. Click on the Layer Labeling Options button:
../../../../_images/image1191.png

This gives you the Layer labeling settings dialog.

  1. Check the box next to Label this layer with...
../../../../_images/image1201.png
  1. We must indicate which of the attribute fields we want to use for the labels. The NAME field is the mostly likely candidate for a label, so select NAME from the drop-down box:
../../../../_images/image1211.png
  1. Click OK. The map should now have labels like this:
../../../../_images/image1221.png

This is good, but as you can see, the labels are overlapping the points that they are associated with. That doesn’t look very nice. The text is also a bit larger than it needs to be. Let’s fix these problems!

  1. Open the Layer Labeling Options again by clicking on its button.
  2. Click on the Text tab to change the text properties:
../../../../_images/image1231.png
  1. A standard text change dialog appears, similar to those in many other programs. Change the font to Arial and size to 9.
  2. Now click on the Buffer tab to add a buffer space around the text. Check the box labelled Draw text buffer.
../../../../_images/image1241.png

Your labels will look like this:

../../../../_images/image1251.png

That’s the font problem solved! Now let’s look at the problem of the labels overlapping the points.

  1. In the Label window dialog, go to the Placement tab.
  2. Change the value of Distance to 2.
../../../../_images/image1261.png
  1. Click OK. The labels no longer hover over the icons, but are “buffered” a short distance away:
../../../../_images/image1271.png

Labelling lines

Now that you know how labelling works, there’s an additional problem. Points and polygons are easy to label, but what about lines? If you label them the same way as the points, they will look funny. Street name labels, for example, should be parallel to the street lines, not hovering horizontally above them. To make lines behave, we’ll need to edit some options.

  1. Hide the POI_Sleman_OSM layer so that it doesn’t distract you.
  2. Activate labels for the Jalan_Sleman_OSM layer as before. (Remember to use the Label tool on the toolbar, not the one in Label Properties!)
  3. Set the font size to 9 so that you can see more labels.
  4. Zoom in so that the scale is near 1:10000.
  5. On the Label window’s Placement tab, choose the following settings:
../../../../_images/image1291.png

The map will look somewhat like this, depending on scale:

../../../../_images/image1301.png

It’s good but still not ideal. For starters, some of the names appear more than once, and that’s not always necessary. To prevent that from happening:

  1. Enable the option Merge connected lines to avoid duplicate labels which is located on the Rendering tab.

Another useful function is to prevent labels being drawn for features too short to be of notice.

  1. Also on the Rendering tab, set the value of Suppress labeling of features smaller than ... to 5.0 mm. Observe the results after you click Apply.
../../../../_images/image130a.png
  1. Try out different settings on the Placement tab as well. As we mentioned before, the horizontal option is not a good idea for roads in this case, so let’s try the curved option instead!
../../../../_images/image130b.png
  1. Select Curved under Placement. Here’s the result:
../../../../_images/image1311.png

As you can see, this hides a lot of the labels that were previously visible, because of the difficulty of making some of them follow twisting street lines and still be legible. You can decide which of these options to use, depending on what you think seems more useful or what looks better.

Now that you know how attributes can make a visual difference for your map, how about using them to change the symbology of objects themselves? That’s the topic for the next section!

3. Classification

Labels are a good way to communicate information such as the names of individual places, but they can’t be used for everything. For example, let’s say that we want to show which district each feature in our vegetation layer is in. Using labels, it would look like this:

../../../../_images/image1321.png

Obviously this is not ideal, so we need another solution. That’s what this lesson is about! In this section, we will learn how to classify vector data effectively.

3.1 Classifying nominal data

  1. Open Layer Properties for the vegetasi layer.
  2. Go to the Style tab.
  3. Click on the drop-down box that says Single Symbol.
../../../../_images/image1331.png
  1. Change it to Categorized. The interface will change:
../../../../_images/image1341.png
  1. Change the Column field to guna_lahan and the Color ramp to Spectral:
../../../../_images/image1351.png
  1. Click the button labelled Classify:
../../../../_images/image1361.png
  1. Click OK. You’ll see something like this:
../../../../_images/image1371.png
  1. In the Layers panel, click the plus sign next to the vegetasi layer. This will show more information about the layer classification and styles.
../../../../_images/image1381.png

So, this is useful! But it hurts your eyes to look at it, so let’s see what we can do about that.

  1. Open Layer Properties and go to the Style tab again.
  2. Click the Change button next to Symbol.
../../../../_images/image1391.png
  1. Remove the outline as you did in the previous module (change the border style to “No Pen”).
  2. Click the Delete all button.
../../../../_images/image1401.png
  1. Now click Classify again, and new symbols will appear.
  2. Change the colour for each type of vegetation by double-clicking on the coloured block next to its name. You can change the colour for each type of vegetation to something that you think is more applicable.
../../../../_images/image1411.png
  1. Notice that the category on the bottom is empty. Select it, and click the Delete button.
  2. When we click OK our map looks like this:
../../../../_images/image142.png

If you feel confident in your new classification skills, try to classify the residential layer yourself. Use darker colours to distinguish it from vegetation.

3.2 Ratio classification

In the previous example, we classified the vegetasi layer by what is known as nominal classification. This type of classification is when categories are defined based on names. Next we will classify the pemukiman layer based on the size of each feature. Classifying with attributes that contain only positive numbers, such as land area, is known as ratio classification.

  1. Open the Attribute Table for the pemukiman layer. Notice the final column, luas_ha. This attribute contains the size of the land area contained within that feature polygon.
../../../../_images/image143.png
  1. Open the Layer Properties for pemukiman.
  2. Change the style type to Graduated and use luas_ha as the Column.
../../../../_images/image144.png
  1. Because we are categorising with numbers this time, a colour gradient will be useful for representing our categories. Click on Oranges next to Color ramp and then click Classify.
../../../../_images/image145.png

Now you’ll have something like this:

../../../../_images/image146.png

Go to next module –>