Filtering attribute data

“QGIS allows you to filter, sort and manipulate attribute data”

Behind every vector layer in QGIS you will find a data table (attribute table). The data in this table describe the attributes of each feature. With QGIS you can manipulate the table display by filtering and sorting these attributes. You can also use queries to search for features with specific characteristics. In this exercise we will try out some of these capabilities.

You try:

Goal: To query and filter attributes

  • Load the Countries layer from the exercise data.
  • Open the attribute table for the layer.
  • Enable the form based filter tool.
  • Filter the table based on the specification in the table below.
  • Scroll down if needed and use the 'Filter Features' button to filter the table

Check your results

How many records were listed once the filter was applied?

Name Expectation

Filter field

type

Filter text

Disputed

More about filtering attribute data

When you filter features in the attribute table, the filter only applies to the table – the map canvas will still show all the features. If you use the 'select features' button rather than the 'filter features' button, the matching rows will be selected – you can zoom to the selected features on the map or raise the selected features to the top of the table.

Once there is a table filter in place, you can easily update all the filtered features by placing the table in edit mode and using the quick formula bar. Note that, as of QGIS 2.18, you need to force a refresh of the table to see your updates applied to the table.

There are also ways to filter your layer for both geometries and attribute data in QGIS. For example, you can:

  • do a 'subset' filter on a layer (via the layer properties dialogue) which will hide any features (including from the attribute table) that do not match the query criteria
  • use virtual layers to create a 'view' of a subset of layers
  • use DB manager to query data from a database that meets your specific criteria

You can also use 'soft' approaches to filter features shown in the map canvas - for example using a rule-based renderer to exclude certain features from the map render.

There is another way to filter the records shown in the QGIS table view - you can limit the list of features shown to only those that are also visible in the map canvas by using the filter button on the bottom left corner of the attribute table and setting it to 'Show features visible on the map'.

Check your knowledge:

  1. True or false: Applying a filter in the attribute table will result in only those features being shown on the canvas:

    1. True
    2. False
  2. What is the purpose of filtering the attribute table - choose all that apply:

    1. to quickly view a list of records that match your criteria
    2. to create a selection of features
    3. to be able to quickly update the attributes of a subset of features