Trigger actions on features

From Open source mapmaking technologies
Jump to: navigation, search

QGIS has a powerful feature called Actions. Actions are triggered for each feature.

Module data

The data for this exercise is the China Administrative Divisions, that we already downloaded from GDA or alternatively from

Lets work with the CHN_adm CHN_adm1 any layer.

Deselecting the other layers:

  • CHN_adm CHN_adm0 any
  • CHN_adm CHN_adm2 any
  • CHN_adm CHN_adm3 any

This layer represents the Provincial-level (1st) subdivisions. 31 divisions are displayed.

Review available attributes

Open the attribute table to review the attributes of each feature in this dataset:

  • NAME_1 contains the English name of the division
  • ENGTYPE_1 contains the type of the division:
    • Province
    • Municipality
    • Autonomous Region

Label 1st level divisions

Each province has a unique name, NAME_1. Use this attribute to add a label to each division.

Styling 1st level divisions

There are 3 types of divisions at this 1st level:

  • Province
  • Municipality
  • Autonomous Region

Use the attribute ENGTYPE_1 to create a "Categorized style". Assign random colors. The result should look like:


For foreigners, it would be nice to have more information about each administrative division. To do so, we will associate "actions" to this layer.

Actions allows us to perform an action when we select a feature in QGIS. We will search for more information about the province when we select it on the map. We will use the web to search for such information.

Given a string like 'Wuhan', we can search for it using these URLs:

Defining actions

To define actions, on the layers panel, double click on CHN_adm CHN_adm1 any layer name, or use the context menu and select Properties.

On the layer properties dialog, select the Actions tab.

Add 3 new actions with the following information:

Type Name Action
Open Search on Google[% "NAME_1" %]
Open Search on Wikipedia[% "NAME_1" %]&title=Special:Search&go=Go
Open Search on Baidu[% "NAME_1" %]

QGIS Actions on NAME 1.png

Trigger actions

When you select a layer (in the layers panel) with actions defined, the second button in the attributes toolbar became available, with the actions available on a drop down list. Select one of the two actions we defined.

Attributes toolbar with actions.png

While the is selected, whenever you click on a feature, the action is trigger. The browser opens (or opens a new tab) with the generated URL defined in the action.

Now you can see more information on Google or Wikipedia about each administrative unit.

Beijing action.png