7.2. Lesson: Analyse Vectorielle¶
Les données vectorielles peuvent aussi être analysées pour révéler comment les différentes entités interagissent entre elles dans l’espace. Il existe beaucoup de fonctions liées à l’analyse dans les SIG, ainsi nous n’allons pas toutes les explorer. Nous allons plutôt poser une question et essayer de la résoudre en utilisant les outils que QGIS prévoit.
Objectif de cette leçon : Poser une question et la résoudre en utilisant les outils d’analyse.
7.2.1. Le processus SIG¶
Avant de commencer, il serait utile de donner un bref aperçu d’un processus qui peut être utilisé pour résoudre les problèmes en SIG. Les étapes à suivre à ce sujet sont :
Énoncer le problème
Obtenir les données
Analyser le problème
Présenter les résultats
7.2.2. The Problem¶
Nous allons commencer le processus en décidant d’un problème à résoudre. Par exemple, vous êtes un agent immobilier et vous recherchez une propriété résidentielle à Swellendam pour des clients dont les critères sont les suivants:
It needs to be in Swellendam
It must be within reasonable driving distance of a school (say 1km)
It must be more than 100m squared in size
Closer than 50m to a main road
Closer than 500m to a restaurant
7.2.3. The Data¶
Pour répondre à ces questions, nous aurons besoin des données suivantes:
The residential properties (buildings) in the area
The roads in and around the town
The location of schools and restaurants
The size of buildings
All of this data is available through OSM and you should find that the dataset you have been using throughout this manual can also be used for this lesson.
If you want to download data from another area jump to Introduction Chapter section to read how to do it.
Note
Bien que les données OSM en téléchargement ont des champs cohérentes, la couverture et le détail varie. Si vous trouvez que votre région choisie ne contient pas d’informations sur les restaurants, par exemple, vous devriez peut-être choisir une région différente.
7.2.4. Follow Along: Start a Project and get the Data¶
We first need to load the data to work with.
Start a new QGIS project
If you want you can add a background map. Open the Browser and load the OSM background map from the XYZ Tiles menu.
In the
training_data.gpkg
Geopackage database load all the files we will use in this chapter:landuse
buildings
roads
restaurants
schools
Zoom to the layer extent to see Swellendam, South Africa
Before proceeding we should filter the roads layer in order to have only some specific road types to work with.
Some of the roads in OSM dataset are listed as unclassified
, tracks
,
path
and footway
. We want to exclude these from our dataset and focus on
the other road types, more suitable for this exercise.
Moreover, OSM data might not be updated everywhere and we will also exclude
NULL
values.
Right click on the roads layer and choose Filter….
In the dialog that pops up we can filter these features with the following expression:
"highway" NOT IN ('footway','path','unclassified','track') OR "highway" != NULL
The concatenation of the two operators
NOT
andIN
means to exclude all the unwanted features that have these attributes in thehighway
field.!= NULL
combined with theOR
operator is excluding roads with no values in thehighway
field.You will note the icon next to the roads layer that helps you remember that this layer has a filter activated and not all the features are available in the project.
The map with all the data should look like the following one:
7.2.5. Try Yourself Convertir le SCR des couches¶
Because we are going to be measuring distances within our layers, we need to change the layers” CRS. To do this, we need to select each layer in turn, save the layer to a new one with our new projection, then import that new layer into our map.
You have many different options, e.g. you can export each layer as a new
Shapefile, you can append the layers to an existing GeoPackage file or you can
create another GeoPackage file and fill it with the new reprojected layers. We
will show the last option so the training_data.gpkg
will remain clean.
But feel free to choose the best workflow for yourself.
Note
Dans cet exemple, nous utilisons le SCR WGS 84 / UTM zone 34S, mais vous pouvez utiliser un SCR UTM qui est plus approprié pour votre région.
Right click the roads layer in the Layers panel;
Click Export –> Save Features As…;
In the Save Vector Layer As dialog choose GeoPackage as Format;
Click on … of File name parameter and name the new GeoPackage as vector_analysis;
Change the Layer name as roads_34S;
Change the CRS parameter to WGS 84 / UTM zone 34S;
Finally click on OK:
This will create the new GeoPackage database and fill it with the roads_34S layer.
Repeat this process for each layer, creating a new layer in the
vector_analysis.gpkg
GeoPackage file with_34S
appended to the original name and removing each of the old layers from the project.Note
When you choose to save a layer to an existing GeoPackage, QGIS will append that layer in the GeoPackage.
Une fois que vous avez terminé ce processus pour chaque couche, faites un clic droit sur une couche et cliquez sur Zoom sur la couche pour focaliser la carte sur la zone d’intérêt.
Maintenant que nous avons converti les données OSM en une projection UTM, nous pouvons commencer nos calculs.
7.2.6. Follow Along: Analyse du problème : Distances des écoles aux routes¶
QGIS vous permet de calculer des distances depuis tout objet vecteur.
Make sure that only the roads_34S and buildings_34S layers are visible, to simplify the map while you’re working
Click on the
to open the analytical core of QGIS. Basically: all algorithms (for vector and raster) analysis are available within this toolbox.We start by calculating the area around the roads_34S by using the Buffer algorithm. You can find it expanding the group.
Or you can type
buffer
in the search menu in the upper part of the toolbox:Double click on it to open the algorithm dialog
Set it up like this
The default Distance is in meters because our input dataset is in a Projected Coordinate System that uses meter as its basic measurement unit. You can use the combo box to choose other projected units like kilometers, yards, etc.
Note
If you are trying to make a buffer on a layer with a Geographical Coordinate System, Processing will warn you and suggest to reproject the layer to a metric Coordinate System.
By default Processing creates temporary layers and adds them to the Layers panel. You can also append the result to the GeoPackage database by:
clicking on the … button and choose Save to GeoPackage…
naming the new layer roads_buffer_50m
and saving it in the
vector_analysis.gpkg
file
Click on Run and then close the Buffer dialog.
Maintenant, votre carte devrait ressembler à peu près à ceci:
If your new layer is at the top of the Layers list, it will probably obscure much of your map, but this gives you all the areas in your region which are within 50m of a road.
However, you’ll notice that there are distinct areas within your buffer, which correspond to all the individual roads. To get rid of this problem:
Uncheck the roads_buffer_50m layer and re-create the buffer using the settings shown here:
Note that we’re now checking the Dissolve result box
Save the output as roads_buffer_50m_dissolved
Click Run and close the Buffer dialog again
Once you’ve added the layer to the Layers panel, it will look like this:
Il n’y a maintenant plus de subdivisions inutiles.
Note
The Short Help on the right side of the dialog explains how the algorithm works. If you need more information, just click on the Help button in the bottom part to open a more detailed guide of the algorithm.
7.2.7. Try Yourself Distance depuis les écoles¶
Utilisez la même approche qu’en haut et créez un tampon pour vos écoles.
It needs to be 1 km in radius. Save the new layer in the
vector_analysis.gpkg
file as schools_buffer_1km_dissolved.
7.2.8. Follow Along: Chevauchement des zones¶
Now we have areas where the road is 50 meters away and there’s a school within 1 km (direct line, not by road). But obviously, we only want the areas where both of these criteria are satisfied. To do that, we’ll need to use the Intersect tool. You can find it in group within .
Configurez-la comme ceci :
The input layers are the two buffers
The saving location is, once again, the
vector_analysis.gpkg
GeoPackageAnd the output layer name is road_school_buffers_intersect
Click Run.
Dans l’image ci-dessous, les zones bleues nous montrent où les deux critères de distance sont satisfaits en même temps !
Vous pouvez enlever les deux couches de tampon et garder seulement celle qui montre où elles se croisent, étant donné que c’est ce que nous voulons vraiment savoir en premier lieu :
7.2.9. Follow Along: Extract the Buildings¶
Now you’ve got the area that the buildings must overlap. Next, you want to extract the buildings in that area.
Look for the menu entry
withinSet up the algorithm dialog like in the following picture
Click Run and then close the dialog
You’ll probably find that not much seems to have changed. If so, move the well_located_houses layer to the top of the layers list, then zoom in.
The red buildings are those which match our criteria, while the buildings in green are those which do not.
Now you have two separated layers and can remove buildings_34S from layer list.
7.2.10. Try Yourself Filtrer davantage nos bâtiments¶
Nous avons maintenant une couche qui nous montre tous les bâtiments à 1km d’une école et à 50m d’une route. Nous devons maintenant réduire la sélection pour ne montrer que les bâtiments qui sont à 500m d’un restaurant.
Using the processes described above, create a new layer called houses_restaurants_500m which further filters your well_located_houses layer to show only those which are within 500m of a restaurant.
7.2.11. Follow Along: Sélection des bâtiments de la bonne taille¶
To see which buildings are of the correct size (more than 100 square meters), we first need to calculate their size.
Select the houses_restaurants_500m layer and open the Field Calculator by clicking on the button in the main toolbar or within the attribute table
Set it up like this
We are creating the new field AREA that will contain the area of each building square meters.
Click OK. The AREA field has been added at the end of the attribute table.
Cliquez à nouveau sur le bouton du mode d’édition pour finir l’édition, et sauvegardez vos modifications quand on vous le demande.
Build a query as earlier in this lesson
Cliquez sur OK.
Your map should now only show you those buildings which match our starting criteria and which are more than 100m squared in size.
7.2.12. Try Yourself¶
Save your solution as a new layer, using the approach you learned above for doing so. The file should be saved within the same GeoPackage database, with the name solution.
7.2.13. In Conclusion¶
En utilisant l’approche de résolution de problèmes SIG ainsi que les outils QGIS d’analyse vectorielle, vous avez été capable de résoudre rapidement et facilement un problème avec de multiples critères.
7.2.14. What’s Next?¶
Dans la prochaine leçon, nous verrons comment calculer la plus petite distance par la route d’un point à un autre.