Geodata Selection and Queries#

Geodata selection and queries in QGIS allow targeted parts of geospatial datasets to be selected. This can be utilized for filtering and analyzing geospatial information, which are essential tasks when working with spatial data.

Three general types of selection/queries in QGIS that will cover the majority of your needs include:
1. Manual Selection: Selection by manually choosing features with one of various selection tools offered by QGIS.

2. Attribute based Selection: Selection based on attribute values stored in the attribute table.

3. Layer based spatial Selection: Selecting features in one layer based on specified geometric relationships with features in another layer.

Now it’s your turn!

Querying data is essential to understand and manipulating your datasets. You can follow the steps outlined below by downloading this dataset.

Download World Bank Official Boundaries

Manual Selection#

Manual selection is done mostly using one of the click-based selection tools available under in your project toolbar (alternative: Edit > Select). These include Select Feature(s), Select Feature by Polygon, Select Feature by Freehand and Select Feature by Radius.

Example: Select Feature(s)

  1. Click Select Feature(s) in the drop down menu of

  2. Select features by clicking on the or drawing a rectangle overlapping them

  3. Use the tool outside of selectable features to end your selection

Tip

Holding down “Shift” during click-based selection allows you to select multiple features

Example: Manually select country polygons by click

The other options of function in a similar way, selecting all features overlapping with the respective geometry generated by the tools.

  1. Click Select Feature(s) by Polygon in the drop down menu of .

  2. Select features by left clicking around the features you want to select

  3. Right-click when you are done drawing the polygon.

Example: Manually select countries by drawing a polygon

Note

Selected features are highlighted in bright yellow in the geospatial view and blue in the attribute table.

Attribute Based Selection#

A query based on specific Attributes can be done utilizing the Select Features by Expression tool available under in the project toolbar and the attribute table (alternative: Edit > Select > Select Features by Expression).

  1. In the tool interface, expand Fields and Values in the right hand panel

  2. Choose the field you want to base your selection on by double clicking it (it should now appear in the expression panel on the left-hand side)

  3. Use a expression with specific operators to specify your selection in the left hand panel (e.g “”continent” LIKE ‘Asia’” to select all features with the value “Asia” in the field “continent” )

Tip

Click on Show Values in the top right corner when a field is selected to get a overview over the different values of the respective field by clicking All Unique/10 Samples. Double click values to use them in the expression panel on the left.

operator

functionality

=

equals

!=

not equal

<

less than

>

greater than

<=

less than or equal to

>=

greater than or equal to

Operators such as AND, OR can be used to combine different queries or criteria

operator

functionality

AND

logical AND

OR

logical OR

NOT

logical NOT

operator

functionality

LIKE

pattern matching

IN

checks if a value is in a list of values

IS NULL

checks for null values

BETWEEN

checks if a value is within a specified range

CASE WHEN

conditional expressions

Example: Select all country polygons that share the value “Asia” in the field “continent”

Layer Based Spatial Selection#

Spatial selection of features enables selecting parts of a layer based on their relationship with features in another geospatial layer (e.g. the selection of all point features in layer A that are located within a polygon feature in Layer B). It can be achieved by using the tool “Select by Location” available under in the project toolbar or (alternative: Vector > Research Tools > Select by Location)

  1. In the tool interface, choose the vector layer you want to select features from using “Select features from” and the layer you want to base the selection on using “By comparing to the features from”.

  2. Choose the geometric operator that will be used to select features (see bottom paragraph)

  3. In the bottom prompt, choose how you want to proceed with the newly selected features. The options include:

    1. Creating a new selection

    2. Adding to the current selection

    3. Selecting within the current selection

    4. Removing from the current selection

Selected features are again highlighted in bright yellow in your geospatial interface.

Example: Select Cities (Point features) that intersect with the polygon “China”

Example 2: Select all country polygons that touch the polygon “China”

Geometric Operators#

The geometric operators define the conditions of the relationship between your source and target layer that the selection will be based on. There are eight total options:

Operation

Description

Example

Intersect

Features from the target layer are selected if they intersect with any features in the source layer.

Selecting all roads that cross a polygon representing a national park.

Contain

Features from the target layer are selected if they completely contain features in the source layer.

Selecting a country polygon that completely contains smaller polygons of cities.

Disjoint

Features are disjoint if they do not share any common point or area.

Selecting administrative districts that have no common boundary or area.

Equal

Features are equal if their geometries are identical.

Selecting two line segments with the exact same set of coordinates.

Touch

Features from the target layer are selected if they touch features in the source layer.

Selecting parks that touch a specific road.

Overlap

Features from the target layer are selected if they share any common space with features in the source layer.

Selecting land parcels that overlap with a proposed construction zone.

Are within

Features from the target layer are selected if they are completely within features in the source layer.

Selecting building polygons that are entirely within a polygon of a city boundary.

Cross

Features from the target layer are selected if they cross features in the source layer.

Selecting rivers that cross a road.