Travailler avec les attributs

Une information géographique a deux parties : objets et attributs. Les attributs sont des données structurées caractérisant chaque objet. Ce tutoriel montre comment voir les attributs et y effectuer des requêtes basiques depuis QGIS.

Description

Le lot de données pour ce tutoriel contient des informations sur des lieux populaires dans le monde. Il s’agit de requêter et de trouver toutes les capitales du monde dont la population dépasse 1 000 000 habitants.

Autres compétences que vous allez développer

  • Select features from a layer using expressions.
  • Deselect features from a layer using the Attributes toolbar.
  • Using Query Builder to show a subset of features from a layer.

Obtenir les données

“Natural Earth” propose des données intéressantes sur les espaces peuplés. http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-populated-places Téléchargez la version simplifiée (elles comportent moins de colonnes) de ces données au lien suivant: http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places_simple.zip

For convenience, you may directly download a copy of datasets from the link below:

ne_10m_populated_places_simple.zip

Source [NATURALEARTH]

Procédure

  1. Once you have downloaded the data, open QGIS. Go to Layer ‣ Add Layer ‣ Add Vector Layer.
../_images/1140.png
  1. Cliquer sur Browse et naviguer jusqu’au dossier où les données ont été téléchargées.

../_images/298.png
  1. Localiser le fichier zip téléchargé ne_10m_populated_places_simple.zip. Nul besoin de le décompresser : QGIS a la possibilité de lire directement les fichiers zip. Sélectionner le fichier et cliquer sur Open.

../_images/348.png
  1. Le calque sélectionné sera chargé dans QGIS et vous verrez de nombreux points représentant les lieux habités dans le monde.

../_images/435.png
  1. Right-click the layer and select Open Attribute Table.
../_images/536.png
  1. Explorer les différents attributs et leurs valeurs.

../_images/634.png
  1. Nous nous intéressons à la population de chaque objet, pop_max est donc le champ que nous recherchons. Vous pouvez cliquer deux fois sur l’entête du champ pour classer la colonne en ordre décroissant.

../_images/733.png
  1. Now we are ready to perform our query on these attributes. QGIS uses SQL-like expressions to perform queries. Click Select features using an expression.
../_images/832.png
  1. In the Select By Expression window, expand the Fields and Values section and double-click the pop_max label. You will notice that it is added to the expression section at the bottom. If you aren’t sure about the field values, you can click the Load all unique values to see what the attribute values are present in the dataset. For this exercise, we are looking to find all features that have a population greater than 1,000,000. So complete the expression as below and click Select.
"pop_max" > 1000000
../_images/930.png
  1. Click on Close and return to the main QGIS window. You will notice that a subset of points is now rendered in yellow. This is the result of our query and you are seeing all places from the dataset that have the pop_max attribute value greater than 1,000,000.
../_images/1031.png
  1. The goal for this exercise is to find the places that are country capitals. The field containing this data is adm0cap. The value 1 indicates that the place is a capital. We can add this criteria to our previous expression using the and operator. Let’s refine our query to select only those places which are capitals. Click on the Select feature using an expression button in the attribute table and enter the expression as below and click Select and then Close.
"pop_max" > 1000000 and "adm0cap" = 1
../_images/1141.png
  1. Return to the main QGIS window. Now you will see a smaller subset of the points selected. This is the result of the second query and shows all places from the dataset that are country capitals as well as have population greater than 1,000,000. If we wanted to do some further analysis on this subset of data, we can make this selection persistent. Right-click the ne_10m_populated_places_simple layer and select Properties.
../_images/1231.png
  1. In the General tab, scroll down to the Feature subset section. Click Query Builder.
../_images/1328.png
  1. Enter the same expression you had entered earlier and click OK.
"pop_max" > 1000000 and "adm0cap" = 1
../_images/1427.png
  1. Back in the main QGIS window, you will see rest of the points disappear. You may now perform any other analysis on this layer and only the features that match our expression will be used. You will notice that the points still appear in yellow. This is because they are still selected. Find the Deselect Features from All Layers button under the Attributes toolbar and click on it.
../_images/1525.png
  1. You will see that the points are now de-selected and rendered in their original color.
../_images/1624.png
comments powered by Disqus

This work is licensed under a Creative Commons Attribution 4.0 International License