Saturday, December 6, 2025

CASE expression in QGIS

Understanding QGIS Expressions

A QGIS Expression is a combination of one or more values, operators, and functions that is evaluated dynamically within the context of a QGIS project.

The syntax for the QGIS Expression language is derived from Structured Query Language (SQL).

QGIS Expressions are utilized extensively throughout the QGIS environment, making familiarity with them essential for a wide range of geospatial tasks. Their applications include, but are not limited to:-

  1. Mapping and Symbology: Manipulating symbology and labels to create sophisticated, data-driven visual representations.
  2. Data Analysis and Management: Selecting features based on specific criteria, and generating new columns or updating existing ones in the attribute table.
  3. Feature Management: Creating new geometries using the Geometry Generator tool or calculating spatial attributes.
  4. Data Exploration: Filtering and querying data for rapid exploration and analysis.


The Syntax

  • (1) 'name' means a string text name
  • (2) "name" means a attribute column called name for the curent feature
  • (3) @name means a variable value called name. This used to be $name in older version of QGIS.
  • (4) name() means a function called name





The CASE expression in QGIS provides conditional logic, allowing the assignment of different values or the execution of different actions based on whether specified conditions are met. This is particularly useful in the Field Calculator, for data-defined properties, or within expressions used for labeling and symbology.


CASE

WHEN "NAME" IN ('New Caledonia', 'Jamaica', 'Bolivia', 'Suriname', 'Dem. Rep. Congo', 'Iraq') THEN "WB_A3" 

END






No comments:

Post a Comment