3.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 us say that someone wants to know what each landuse area is used for. Using labels, you would get this:

../../../_images/bad_landuse_labels.png

Cela rend les étiquettes de la carte difficiles à lire car trop nombreuses si vous avez de nombreuses utilisation du territoires différentes à afficher.

Objectif de cette leçon : Apprendre comment classifier des données vectorielles efficacement.

3.3.1. basic Follow Along: Classification de données nominales

  1. Open the Layer Properties dialog for the landuse layer

  2. Go to the Symbology tab

  3. Cliquez sur le menu déroulant qui indique Symbole unique et changez-le en Categorisé:

    ../../../_images/categorised_styles.png
  4. In the new panel, change the Value to landuse and the Color ramp to Random colors

  5. Click the button labeled Classify

    ../../../_images/categorised_style_settings.png
  6. Cliquez sur OK

    Vous verrez quelque chose comme ça :

    ../../../_images/categorisation_result.png
  7. Click the arrow (or plus sign) next to landuse in the Layers panel, you’ll see the categories explained:

    ../../../_images/categories_explained.png

    Now our landuse polygons are colored and are classified so that areas with the same land use are the same color.

  8. If you wish to, you can change the symbol of each landuse area by double-clicking the relevant color block in the Layers panel or in the Layer Properties dialog:

    ../../../_images/change_layer_color.png

Notez qu’il y a une catégorie qui est vide :

../../../_images/empty_category.png

This empty category is used to color any objects which do not have a landuse value defined or which have a NULL value. It can be useful to keep this empty category so that areas with a NULL value are still represented on the map. You may like to change the color to more obviously represent a blank or NULL value.

Souvenez-vous de sauvegarder votre carte maintenant afin que vous ne perdiez pas toutes vos modifications durement gagnées !

3.3.2. basic Try Yourself Plus de classification

Use the knowledge you gained above to classify the buildings layer. Set the categorisation against the building field and use the Spectral color ramp.

Note

Rappelez-vous de zoomer sur une zone urbaine pour voir les résultats.

3.3.3. moderate Follow Along: Classification de ratio

Il y a quatre types de classification : nominale, ordinale, d’intervalle et de ratio.

In nominal classification, the categories that objects are classified into are name-based; they have no order. For example: town names, district codes, etc. Symbols that are used for nominal data should not imply any order or magnitude.

  • For points, we can use symbols of different shape.

  • For polygons, we can use different types of hatching or different colours (avoid mixing light and dark colours).

  • For lines, we can use different dash patterns, different colours (avoid mixing light and dark colours) and different symbols along the lines.

In ordinal classification, the categories are arranged in a certain order. For example, world cities are given a rank depending on their importance for world trade, travel, culture, etc. Symbols that are used for ordinal data should imply order, but not magnitude.

  • For points, we can use symbols with light to dark colours.

  • For polygons, we can use graduated colours (light to dark).

  • For lines, we can use graduated colours (light to dark).

In interval classification, the numbers are on a scale with positive, negative and zero values. For example: height above/below sea level, temperature in degrees Celsius. Symbols that are used for ratio data should imply order and magnitude.

  • For points, we can use symbols with varying size (small to big).

  • For polygons, we can use graduated colours (light to dark) or add diagrams of varying size.

  • For lines, we can use thickness (thin to thick).

In ratio classification, the numbers are on a scale with only positive and zero values. For example: temperature above absolute zero (0 degrees Kelvin), distance from a point, the average amount of traffic on a given street per month, etc. Symbols that are used for ratio data should imply order and magnitude.

  • For points, we can use symbols with varying size (small to big).

  • For polygons, we can use graduated colours (light to dark) or add diagrams of varying size.

  • For lines, we can use thickness (thin to thick).

In the example above, we used nominal classification to color each record in the landuse layer based on its landuse attribute. Now we will use ratio classification to classify the records by area.

We are going to reclassify the layer, so existing classes will be lost if not saved. To store the current classification:

  1. Open the layer’s properties dialog

  2. Click the Save Style … button in the Style drop-down menu.

  3. Select Rename Current…, enter land usage and press OK.

    The categories and their symbols are now saved in the layer’s properties.

  4. Click now on the Add… entry of the Style drop-down menu and create a new style named ratio. This will store the new classification.

  5. Close the Layer Properties dialog

We want to classify the landuse areas by size, but there is a problem: they don’t have a size field, so we’ll have to make one.

  1. Open the Attributes Table for the landuse layer.

  2. Enter edit mode by clicking the toggleEditing Toggle editing button

  3. Add a new column of decimal type, called AREA, using the newAttribute New field button:

    ../../../_images/add_area_column.png
  4. Cliquez sur OK

    The new field will be added (at the far right of the table; you may need to scroll horizontally to see it). However, at the moment it is not populated, it just has a lot of NULL values.

    To solve this problem, we will need to calculate the areas.

    1. Open the field calculator with the calculateField button.

      You will get this dialog:

      ../../../_images/calculate_field_dialog.png
    2. Check the checkbox Update existing fields

    3. Select AREA in the fields drop-down menu

      ../../../_images/field_calculator_top.png
    4. Under the Expression tab, expand the Geometry functions group in the list and find $area

    5. Double-click on it so that it appears in the Expression field

      ../../../_images/geometry_area_select.png
    6. Cliquez sur OK

    7. Scroll to the AREA field in the attribute table and you will notice that it is populated with values (you may need to click the column header to refresh the data).

    Note

    These areas respect the project’s area unit settings, so they may be in square meters or square degrees.

  5. Press saveEdits to save the edits and exit the edit mode with toggleEditing Toggle editing

  6. Close the attribute table

Now that we have the data, let’s use them to render the landuse layer.

  1. Open the Layer properties dialog’s Symbology tab for the landuse layer

  2. Change the classification style from Categorized to Graduated

  3. Change the Value to AREA

  4. Under Color ramp, choose the option Create New Color Ramp…:

    ../../../_images/area_gradient_select.png
  5. Choose Gradient (if it’s not selected already) and click OK. You will see this:

    ../../../_images/gradient_color_select.png

    Vous utiliserez ceci pour désigner la zone, avec des petites zones comme Couleur 1 et des grandes zones comme Couleur 2.

  6. Choose appropriate colors

    Dans cet exemple, le résultat doit ressembler à cela :

    ../../../_images/gradient_color_example.png
  7. Cliquez sur OK

  8. You can save the colour ramp by selecting Save Color Ramp… under the Color ramp tab. Choose an appropriate name for the colour ramp and click Save. You will now be able to select the same colour ramp easily under All Color Ramps.

  9. Click Classify

    Now you will have something like this:

    ../../../_images/landuse_gradient_selected.png

    Laissez tout le reste tel quel.

  10. Click OK:

../../../_images/gradient_result_map.png

3.3.4. moderate Try Yourself Affiner la Classification

  • Modifiez les valeurs Mode et Classes jusqu’à obtention d’une classification qui ait du sens.

Vérifiez vos résultats

3.3.5. hard Follow Along: Classification basée sur des règles

Il est souvent utile de combiner plusieurs critères pour une classification, mais une classification normale ne prend malheureusement d’un seul attribut en compte. C’est là que la classification basée sur de règles est très pratique.

In this lesson, we will represent the landuse layer in a way to easily identify Swellendam city from the other residential area, and from the other types of landuse (based on their area).

  1. Open the Layer Properties dialog for the landuse layer

  2. Switch to the Symbology tab

  3. Switch the classification style to Rule-based

    QGIS will automatically show the rules that represent the current classification implemented for this layer. For example, after completing the exercise above, you may see something like this:

    ../../../_images/rule_based_classification.png
  4. Click and drag to select all the rules

  5. Use the signMinus Remove selected rules button to remove all of the existing rules

Let’s now add our custom rules.

  1. Click the signPlus Add rule button

  2. The Edit rule dialog then appears

  3. Enter Swellendam city as Label

  4. Click the expression button next to the Filter text area to open the Expression String Builder

  5. Enter the criterion "name" = 'Swellendam' and validate

    ../../../_images/query_builder_example.png
  6. Back to the Edit rule dalog, assign it a darker grey-blue color in order to indicate the town’s importance in the region and remove the border

    ../../../_images/rule_style_result.png
  7. Cliquez sur OK

  8. Repeat the steps above to add the following rules:

    1. Other residential label with the criterion "landuse" = 'residential' AND "name" <> 'Swellendam' (or "landuse" = 'residential' AND "name" != 'Swellendam'). Choose a pale blue-grey Fill color

    2. Big non residential areas label with the criterion "landuse" <> 'residential' AND "AREA" >= 605000. Choose a mid-green color.

      ../../../_images/criterion_refined_midway.png

      These filters are exclusive, in that they exclude areas on the map (non-residential areas which are smaller than 605000 (square meters) are not included in any of the rules).

    3. We will catch the remaining features using a new rule labeled Small non residential areas. Instead of a filter expression, Check the radioButtonOn Else. Give this category a suitable pale green color.

      ../../../_images/criterion_else.png

    Your rules should now look like this:

    ../../../_images/criterion_refined_list.png
  9. Apply this symbology

Votre carte ressemblera à quelque chose comme ça :

../../../_images/rule_based_map_result.png

Maintenant que vous avez une carte avec Swellendam, le quartier résidentiel le plus important et d’autres quartiers non résidentiels colorés en fonction de leur taille.

3.3.6. In Conclusion

La symbologie nous permet de représenter les attributs d’une couche d’une façon facile à lire. Cela nous permet aussi bien qu’au lecteur de carte de comprendre la signification de caractéristiques, en utilisant tout attribut pertinent que nous choisissons. En fonction des problèmes auxquels vous faites face, vous appliquerez différentes techniques de classification pour les résoudre.

3.3.7. What’s Next?

Nous avons maintenant une carte de belle apparence, mais comment allons-nous sortir de QGIS dans un format que nous pouvons imprimer, ou en faire une image ou un PDF ? C’est le sujet de la prochaine leçon !