GIS AH C4

GIS FOR ANIMAL HEALTH : CHAPTER 4

Module: Classifying Vector Data

Classifying vector data allows you to assign different symbols to features (different objects in the same layer), depending on their attributes. This allows someone who uses the map to easily see the attributes of various features.

4.1 Lesson: Attribute Data

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, all the farms look 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.

The goal of this lesson: To explore the attribute data of an object and understand what the various data can be useful for.

4.1.1 [[Image:]]Follow along: Attribute data

Open the attribute table for the places layer (refer back to the section 'Working with Vector Data if necessary). Which field would be the most useful to represent in label form, and why?

Check your results

4.1.2 In conclusion

You now know how to use the attribute table to see what is actually in the data you're using. Any 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.


4.1.3 What's next?

Different attributes are useful for different purposes. Some of them can be represented directly as text for the map user to see. You'll learn how to do this in the next lesson.

4.2 Lesson: The 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. These labels rely on the attribute data of a layer for their content.

Note: The Layer Properties dialogue does have a Labels tab, but for this example we will not be using it. It has too few options and may be difficult to work with, which is why it will probably be taken out of new versions of QGIS (after 1.8). Instead, for this lesson we'll use the separate Label tool, which has more options and is more user-friendly.

The goal for this lesson: To apply useful and good-looking labels to a layer.

4.2.1 [[Image:]] Follow along: Using labels

Before being able to access the Label tool, you will need to ensure that it has been activated.

  • Go to the menu item View - Toolbars.
  • Ensure that the Label item has a check mark next to it. If it doesn't, click on the Label item, and it will be activated.
  • Click on the places layer in the Layers list, so that it is highlighted.
  • Click on the following toolbar button:

[[Image:]]

This gives you the Layer labeling settings dialogue.

  • Check the box next to Label this layer with....

[[Image:]] [[Image:]]


You'll need to choose which field in the attributes will be used for the labels. In the previous lesson, you decided that the NAME field was the most suitable one for

this purpose.
  • Click OK.

The map should now have labels like this:

[[Image:]]


4.2.2 [[Image:]] Follow along: Changing label options

What we have so far 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!

  • Open the Label tool again by clicking on its button as before.
  • Click on the ellipsis (...) button to change the text properties:

[[Image:]]

A standard text change dialogue appears, similar to those in many other programs. Change the font to Arial size 9. Your labels will now look like this:

[[Image:]]


This solves the font problem, and now let's look at the problem of the labels overlapping the points, but before we do that, let's take a look at the Buffer option.

  • Open the Label tool dialogue.* Deactivate the label buffer by clicking on the checkbox next to the text that says Buffer. * Click Apply.

Note the effects in the map:

[[Image:]]


Now you can see why we usually need label buffers!

  • Reactivate the buffers by clicking in the same checkbox as before, and then clicking Apply.

Back to the problem of the labels that overlap points.

  • In the Label tool dialogue, go to the Advanced tab.
  • Change the value of Label distance to 2.

[[Image:]]

  • Click Apply.

This is the result:

[[Image:]] [[Image:]]


4.2.3 [[Image:]] Follow along: Using labels instead of layer symbology

In many cases, the location of a point doesn't need to be very specific. For example, when they refer to entire towns or suburbs, and the specific point associated with such features is not that specific on a large scale. In fact, giving a point that is too specific is often confusing for someone reading a map.

To name an example: on a map of the world, the point given for the European Union may be somewhere in Poland, for instance. To someone reading the map, seeing a point labeled European Union in Poland, it may seem that the capital of the European Union is therefore in Poland.

So, to prevent this kind of misunderstanding, it's often useful to deactivate the point symbols and replace them completely with labels.

In QGIS, you can do this by changing the position of the labels to be rendered directly over the points they refer to.

  • Open the Layer labeling settings dialogue for the places layer.
  • Go to the Advanced tab.
  • Click on the over point button.


[[Image:]]

  • Hide the point symbols by editing the layer style as usual, and setting the size of points to 0:

[[Image:]]


  • Click OK and you'll see this result:

[[Image:]]

As you can see, some of the labels are now missing to prevent overlap (at this scale). Sometimes this is what you want when dealing with datasets that have many points, but at other times you will lose useful information this way. There is another possibility for handling cases like this, which we'll cover in a later exercise in this lesson.

4.2.4 [[Image:]]Try yourself... Customize the labels

  • Return the label and symbol settings to the way they were before.

Check your results

  • Set the map to the scale 1:20000. You can do this by typing it into the Scale box in the Status Bar.
  • Modify your labels to be suitable for viewing at this scale.

Check your results

4.2.5 [[Image:]]Follow along: Labeling lines

Now that you know how labeling 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, your results would look like this:


[[Image:]] [[Image:]]


This is not very useful! To make lines behave, we'll need to edit some options.

  • Hide the places layer so that it doesn't distract you.
  • Zoom in on the town area.
  • Activate labels for the streets layer as before. (Remember to use the Label tool on the toolbar, not the one in Label Properties!)
  • Set the font Size to 9 so that you can see more labels.
  • In the Label tool dialogue's Advanced tab, choose the following settings:

[[Image:]] [[Image:]]


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

[[Image:]]

[[Image:]]


It's better than before, 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:

  • Enable the option Merge connected lines to avoid duplicate labels (also under the Advanced tab - you may need to scroll down to see it).

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

  • Set the value of Suppress labeling of features smaller than ... to 5mm and note the results when you click Apply.

Try out different Placement settings as well (also under the Advanced tab). As we've seen before, the horizontal option is not a good idea in this case, so let's try the curved option instead!

  • Select the curved option under the Advanced tab of the Layer labeling settings dialogue.

Here's the result:

[[Image:]] [[Image:]]


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.

4.2.6 [[Image:]]Follow along: Data defined settings

  • Deactivate labeling for the streets layer.
  • Reactivate labeling for the places layer.
  • Open the attribute table for places.

It has two fields that are of interest to us now: AMENITY and RESTAURANT. AMENITY is what type of place it is. RESTAURANT is derived from it, and tells you whether or not that feature is a restaurant (1 if it is, 0 if not). We can use this data to influence the label styles.

  • Navigate to the Data defined settings tab.
  • In the Italic dropdown, select RESTAURANT and click Apply.

Notice its effects:

[[Image:]][[Image:]]


4.2.7 [[Image:]]Try yourself... Using data defined settings

Note: We're jumping ahead a bit here to demonstrate some advanced labeling settings. At the advanced level, it's assumed that you'll know what the following means. If you don't, feel free

to leave out this section and come back later when you've covered the requisite materials.

  • Open the attribute table for places.
  • Enter edit mode by clicking this button (at the lower edge of the attribute table):

[[Image:]]

  • Add a new column:

[[Image:]]

  • Configure it like this:

[[Image:]]


  • Use this to set custom font sizes for each different type of amenity (i.e., each key in the AMENITY field).

Check your results

4.2.8 [[Image:]]Further possibilities with labeling

We can't cover every option in this course, but be aware that the Label tool has many other useful functions. You can set scale-based rendering, alter the rendering priority for labels in a layer, and set every label option using layer attributes. You can even set the rotation, XY position, and other properties of a label (if you have attribute fields allocated for the purpose), then edit these properties using the tools adjacent to the main Label tool:

[[Image:]]

(These tools will be active if the required attribute fields exist and you are in edit mode.)

Feel free to explore more possibilities of the labeling system.

4.2.9 In conclusion

You've learned how to use layer attributes to create dynamic labels. This can make your map a lot more informative and stylish!


4.2.10 What's next?

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 lesson!

4.3 Lesson: 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 someone wants to know what types of land cover are in the Bandung districts area. Using labels, you'd get this:

[[Image:]]

Obviously this is not ideal, so we need another solution. That's what this lesson is about! The goal for this lesson: To learn how to classify vector data effectively.

4.3.1 [[Image:]]Follow along: Classifying nominal data

  • Open Layer Properties for bandung_districts
  • Go to the Style tab.
  • Click on the dropdown that says Single Symbol:


[[Image:]] [[Image:]]


  • Change it to Categorized and the interface will change:

[[Image:]]

  • Change the Column to LANDCOVER and the colour ramp to random:

[[Image:]]


  • Click the button labeled Classify and then click OK.

You'll see something like this:


[[Image:]]


  • Click the arrow (or plus sign) next to bandung_districts in the Layer list, you'll see the categories explained:

[[Image:]]

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

  • Open Layer Properties and go to the Style tab again.
  • Change the symbol:


[[Image:]]


  • Get rid of the outline the same way you did before, and click OK. (If you need to, go back to the lesson where we covered this to remember how it's done.)
  • Click the Delete all button:


[[Image:]]


This gets rid of the ugly classes so you can try again.

  • Choose a new option from the colour ramp

'* Click Classify again, and the new symbols will appear.

You'll notice they don't have outlines. This is because you just removed the outlines.

  • Change the colour for Water bodies
by double-clicking on the coloured block representing its symbol:

[[Image:]]

Use your own colours, so that the resulting map isn't as ugly as the old one. In the example, we'll use these colours, with our water bodies coloured blue:

[[Image:]]

This gives us a nice map:

[[Image:]]

There is one category that is empty:

[[Image:]]


  • Select the empty category.
  • Click the Delete button.

This only gets rid of the symbol, not the data, so don't worry about messing up; you're not actually deleting anything that you can't recover.

Remember to save your map now so that you don't lose all your hard-earned changes!

4.3.2 [[Image:]]Try yourself... More classification

If you're only following the basic-level content, use the knowledge you gained above to classify the urban areas. Use darker colours to set them apart from the farms.


4.3.6 In conclusion

Symbology allows us to represent the attributes of a layer in an easy-to-read way. It allows us as well as the map reader to understand the significance of features, using any relevat attributes that we choose. Depending on the problems you face, you'll apply different classification techniques to solve them.

4.3.7 What's next?

Now we have a nice-looking map, but how are we going to get it out of QGIS and into a format we can print out, or make into an image or PDF? That's the topic of the next lesson!