Selection and Queries Exercise 1#

🔙Back to Homepage

Aim of the exercise#

Data#

Download all the datasets here, save the folder on your computer, and unzip the file. The zip folder includes:

  • som_admbnda_adm2_ocha_20230308.shp: This file contains information about the Somali administrative level 0-2, state, and operational zone level 1 and 2 boundary as shapefiles. The data can also be found on HDX.

  • GF2_20231123_FloodExtent_BeledweyneCity_HiraanRegion.shp: This shapefile illustrates satellite-detected surface waters in Beledweyne City, Beledweyne District, Hiraan Region, Somalia, on 12th of November 2023 at 07:32 UTC. The data is also available on HDX.

  • Buildings_Belete_Weyne.geojson: This dataset is downloaded using HOT Export Tool and contains information about buildings in the Beledweyne district.

The folder is called Modul_3_Exercise_1_Queries_Somalia and contains the entire standard folder structure with all data in the input folder.

Note

The naming of the districts and states is not consistent across the different datasets. You will find different spellings for the district name Beledweyne which we will be focusing on. Other spellings might be Belet Weyne or Belete Weyne.

Tasks#

  1. Open QGIS and create a new project by clicking on Project –> New.

  2. Once the project is created, save the project in the project folder of the exercise Modul_3_Exercise_1_Queries_Somalia. To do that click on Project –> Save as and navigate to the folder. Name the project Somalia_flood_affected_Beledweyne_2023.

  3. To load the following files into your project, drag and drop them (Wiki Video). Or click on Layer –> Add Layer –> Add Vector Layer. Click on the three points and navigate to the file. Select the file and click Open. Back in QGIS click Add (Wiki Video).

    • som_admbnda_adm2_ocha_20230308.shp

    • GF2_20231123_FloodExtent_BeledweyneCity_HiraanRegion.shp

    • Buildings_Belete_Weyne.geojson: A pop-up window will appear for this file and you will need to decide which data to import. Select the polygons.

  4. First, we want to export the district Beledweyne from the Hiraan region from som_admbnda_adm2_ocha_20230308.shp to have it as a stand-alone vector layer. To do that:

    1. Open the attribute table of som_admbnda_adm2_ocha_20230308.shp by right clicking on the layer –> Open Attribute Table(Wiki Video).

    2. Find the row of Belet Weyne and mark it by clicking on the number on the very left-hand side of the attribute table. The row will be highlighted in blue and the district will turn yellow on the map canvas. You can right-click on the row and click Zoom to Feature(Wiki Video).

    3. Now right-click on the layer in the Layer Panel and click on Export -> Save Selected Features as. We want to save Beledweyne as a GeoPackage, so adjust Format accordingly. Click on the three points and navigate to your temp folder. Here you can give the layer the name AOI_Beledweyne and click Save. Now click OK(Wiki Video). In this exercise, we will not reproject the layers and work with the data in ESPG:4326 - WGS84.

  5. In the following steps, we want to identify all buildings that are likely to be affected by the recent flooding. To do that we will use the tool Extract by Location.

    1. In the Processing Toolbox –> Search for Extract by Location

    2. Extract features from: Buildings_Belete_Weyne.geojson

    3. Where the features (geometric predicate): are within

    4. By comparing to the features from: GF2_20231123_FloodExtent_BeledweyneCity_HiraanRegion.shp

    5. Under Extracted click on the three points –> Save to File... and navigate to your temp folder and save the new layer under the name Beledweyne_buildings_affected and click Save.

    6. Now click Run

    7. Adjust your layers in a way that you only see the flooded areas and your new layer Beledweyne_buildings_affected. Remove the som_admbnda_adm2_ocha_20230308.shp and Buildings_Belete_Weyne.geojson layer.

    Attention

    The tool Select by Location is very similar. This tool functions in the same way, but instead of directly extracting the features, it selects them.

../../_images/Extract_by_location_Belet_Weyne.png

The extract by extraction window in QGIS 3.36#

  1. In the next step, we want to identify special buildings among the affected buildings. Open the attribute table and check what kind of buildings can be found in the layer. This information can be found in the column “building”. You can sort this column. To extract “hospitals”, “schools”, and “mosques”, we can use the tool Extract by Expression.

    1. Find the tool Extract by Expression in the Toolbox.

    2. Expression: click on .

    3. The window “Expression” will open. Here we can build a very specific query. In the central panel open Field and values. Here you can see all the columns oft he the layer. Click on building. On the right-hand side, you should now see the option All unique. Click on it. Here you can see now all unique values in the column „building“.

    4. In the Expression field, enter the following expression (see extract_by_expression1):

      "building" = 'hospital' or
      "building" = 'school' or
      "building" = 'mosque' 
      
    5. Click Ok. The window will close and you will see the expression you created in the Expression-field in the Extract by Expression window (see extract_by_expression2).

    6. Click Run. A new temporary layer called Matching Features will be added to your QGIS-project. Close the Extract by Expression window.

../../_images/en_extract_by_expression_som.png

The expression window in QGIS 3.36 with an expression to extract the polygons with the “buildings” value ‘hospital’, ‘school’, and ‘mosque’.#

../../_images/en_extract_by_expression_som2.png

The Extract by Expression window in QGIS 3.36#

Attention

A temporary layer will not be saved to your QGIS-project, even after saving the project. Temporary layers are marked by a . In order to save the layer permanently, Right Click on the layer you wish to make permanent. Then, select the save location for the new layer. Make sure you to save it in the correct folder (see standard folder structure).

  1. Explore the new layer by opening the attribute table, activating and deactivating the layer in the Layers panel.

  2. Right Click on the Matching Features layer and save it to your project folder under /data/output/ with the name Belet_Weyne_POI_affected.gpkg.

Congratulations! The extracted information can now be used to perform further analyses or create comprehensive maps of the affected points of interest.