Trigger actions on features
QGIS has a powerful feature called Actions. Actions are triggered for each feature.
The data for this exercise is the China Administrative Divisions, that we already downloaded from GDA CHN_adm_gpkg.zip or alternatively from http://mapmaking.info/images/files/CHN_adm_gpkg.zip.
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:
- 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:
- 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:
https://www.google.com/search?q=Wuhan http://en.wikipedia.org/w/index.php?search=Wuhan&title=Special:Search&go=Go http://www.baidu.com/#wd=Wuhan
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:
|Open||Search on Google|
|Open||Search on Wikipedia|
|Open||Search on Baidu|
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.
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.