Mastering Geospatial Development with QGIS 3.x
上QQ阅读APP看书,第一时间看更新

Custom QGIS variables

A new feature of QGIS since version 2.12 is custom variables. Variables can be set at several different scopes or levels:

  • Global
  • Project
  • Layer

Global variables are available at the application level in any QGIS Desktop instance. These can be managed from Settings | Options | Variables. Examples of what you might set as global might be a company/organization name that you can then later use in expressions, Print Layouts, or when editing data to autopopulate fields. 

Project variables are available throughout a given project. These can be set from the Project Properties window on the Variables tab. Examples may include project names, reference numbers, or client names.

Layer level variables are available from Layer Properties on the Variables tab, and are available only for that layer.

In each instance, variables can be added using the green plus button found in the bottom-right corner of the variables screens.

The other important aspect of these variables is that they cascade from most specific scope to least specific scope. In other words, @my_var set at the Global level will be overwritten by @my_var set at the Project level.

Variables are still a very new feature, but have a lot of potential for creating more efficient workflows. Once you begin using them, you will undoubtedly discover many other use cases.