Video - Selecting Features by Attributes in QGIS

Catalogue number: Catalogue number: 89200005

Issue number: 2020007

Release date: February 18, 2020

QGIS Demo 7

Selecting Features by Attributes in QGIS - Video transcript

(The Statistics Canada symbol and Canada wordmark appear on screen with the title: "Selecting Features by Attributes in QGIS")

Today we'll introduce attribute-based selection tools, which are used to select features with common entries like classes, categories or value ranges within a specified fields. They help select and sub-set data by specific criteria, whereas the interactive selection tools explored earlier help select by areas of interest. Specifically we'll cover:

The Select by Value and Expression tools, covering general Expression syntax for the latter. Then we'll export our selection to a new layer, demonstrating how to subset datasets by attributes of interest.

So the attribute selection tools are found beside the interactive tools on the Attribute Toolbar and also default for the selected layer in the Layers panel.

Let's start with the Select by Value tool using the Grain Elevators layer. This tool is the easier of the two to use as it does not require expression syntax, but is best suited to creating simple selections.

Fields are listed on the left, attributes of interest can be specified in the centre and the operators applied to create the selection are chosen from the drop-downs on the right.

We'll start with a simple selection isolating grain elevators in British Columbia – with 13 returned features.

We could add additional criteria as desired, such as specifying only elevators with railways operated by CN, that are Terminal elevators, with a capacity in metric tons greater than 50000. Now only 5 features are selected.

If we want to use a field more than once, such as selecting features within or outside a value range we can remove the other parameters, change the value and operator and expand the selection options by clicking the drop-down – in this case clicking Add to Selection. These additional selection options facilitate isolating features that match your criteria of interest.

However, the Select by Expression provides more flexibility in using multiple criteria or repeating a specific field. Let's explore tool using the Census Subdivision layer. Expressionxpression are provided on the right.

Expanding the Fields and Values drop-down we can select a field from our dataset, and click the All Unique to return the distinct attributes from within that Field. To add them to the expression we can double left-click. So fields are double-quoted and text-based attributes are single quoted in expressions. Scrollins are written in a SQL-like syntaxand are used in multiple tools. Don't worry if you have no experience – we'll cover the main rules as we work through some examples.

So expressions are written on the left, while the centre columns help construct the queries. If we click a specific function of interest, the format, components and a sample of the eg down to the Operators drop-down we can select the operator – in this case LIKE for text-based entries. As you get more comfortable you can write expressions from the keyboard.

Let's explore some additional expressions using the Census Division layer.

So we could use a Wildcard to isolate features with some overlap in their attributes. The % sign is a wildcard meaning any characters of any length - in this case returning all provinces and territories beginning with the letter N.

If we wanted to define the criteria that is not of interest, which is sometimes easier than specifying all the criteria that are - we could add NOT in front of LIKE, which toggles our selected features. In this case we could have also used the Invert Feature Selectiontool to achieve the same results.

The equivalent of these operators for numeric attributes would be the equal sign (=) and exclamation mark equal sign (!=) for not equals.

Let's explore numeric-based expressions using the Unique Census Division identifier field, such as selecting features within or outside of specified ranges – in this case greater than 2000 and less than 4000.

So as you can see numbers can be entered as-is. The Field Name is repeated for each expression component even when it is the same field. So here we selected all divisions within Ontario and Québec.

Now let's switch the operators to isolate features outside of the range, similar to the selection created with grain elevators at the beginning of the demo.

No features are selected, because the unique identifier cannot simultaneously be less than 2000 and greater than 4000. In this case we would need to use the OR operator, which is used to select outside of value ranges or add additional criteria that are not inherently mutually inclusive. Think critically about the applied operator and its influence on which features are returned.

We can use brackets to compartmentalize different components of an expression, such as combining the AND and OR operators when creating more advanced expressions. We'll switch 4000 to 5000 and add another component specifying AND less than 6000. Here we've returned divisions on the Atlantic and Pacific Coasts.

Finally we can also include different fields within the same expression. In this case adding Census Division Name like Division wildcard, which will return any Census Divisions whose name begins with the word Division.

So as you can see the Select by Expression tool offers more flexibility and capabilities in creating advanced feature selections, enabling repeated use of a specific field or multiple fields and attributes to be incorporated when creating a selection.

Now I'd like to discuss exporting our selection in our Census Subdivisions to a new layer - also known as subsetting. To export our selected features, right-click hit export and - Save Selected Features As. This checks the Save Only Selected box in the Save Vector Layer as box. Subsetting helps remove peripheral features - reducing storage space and processing times. The Save Layer As box can also be used to permanently save temporary layers, change the coordinate reference system or file format of a vector.

Here we will change the CRS to UTM Zone 14 N, the same system used to create our AOI polygon in the previous demo.

We'll also provide the output filename and directoryUsing a distinctive file naming scheme can help organize and quickly find files. Use a scheme that is most intuitive for you. My preference is to apply prefixes to distinguish processes applied to datasets, as they are listed alphabetically in the Browser panel projected.Here, I'll call the subset layer.shp for projected Manitoba census subdivisions.

Click OK. This will save our subset dataset for future use and also load the layer into the Layers Panel.

Congratulations! You have learned the skills to select features by criteria of interest and export them to a new layer. You should now feel confident using drop-downs to help construct expressions and applying the syntax to different field types. We'll advance these skills in the following demo, using expressions in the field calculator to add and update fields, and in conjunction with the Select by Expression tool update the attributes for large feature selections.

(Canada wordmark appears.)

Date modified: