47 votes
Accepted

How to select features containing specific text string using an expression in QGIS

You just gotta use the LIKE operator. For example, "TITLE" LIKE '%MINERAL CLAIM%' The % symbol acts like a wildcard. LIKE is case-sensitive, whereas ILIKE is not.
user avatar
  • 9,921
35 votes
Accepted

What is the difference between != NULL and IS NOT NULL in QGIS filter expressions?

Disclaimer: Because the syntax for filtering in QGIS works with SQL, I'm assuming here that SQL rules apply. I'm not completely sure if that's entirely correct, but it seems logical and it does ...
user avatar
  • 2,271
24 votes

What is the difference between != NULL and IS NOT NULL in QGIS filter expressions?

NULL is not a value, therefore it cannot equal = or not equal != anything. It is not the same as zero 0 which is a value. A NULL indicates that no value has been recorded in the cell you are looking ...
user avatar
  • 29.2k
20 votes
Accepted

Difference between quotation marks ('single' vs "double") in QGIS

Double quotes indicate that the string represents the name of an attribute while a single quote is a literal string. So in your first case you get NULL because you don't have an attribute called ...
user avatar
  • 74.6k
17 votes
Accepted

Extracting part of string from field in QGIS Field Calculator?

Since the number of characters is same, you can use substr() function on a new field as in the following expression: substr( "Location" ,17,6) In the above example I used Path instead of ...
user avatar
  • 36.2k
17 votes

Using CASE statements to sort multiple values in QGIS Field Calculator

Use like this: CASE WHEN "stat_land_" IN ('A1', 'A2', 'A9', 'E', 'E2') THEN 'Residential' WHEN "stat_land_" IN ('C', 'C1') THEN 'Vacant Land' ...
user avatar
16 votes
Accepted

Filling a field with a random string from a list in QGIS

You can build the array, build a random index and extract its value array('a','b','c')[rand(0,2)]
user avatar
  • 34.3k
15 votes

Difference between quotation marks ('single' vs "double") in QGIS

Here is the answer directly from QGIS help: column name "column name" → Value of the field column name, take care to not be confused with simple quote, see below 'string' → a string value, ...
user avatar
  • 36.2k
15 votes
Accepted

Displaying only attributes not zero in QGIS Atlas text box

Manual version With this option, you manually add a row for each attribute, reusing the same expression. See below how to automatize this for all fieldnames at once. Create a condition for each ...
user avatar
  • 40k
14 votes
Accepted

QGIS query syntax differs between attribute table and feature filter

Your observation is correct, The Query Builder does not use the same syntax as the rest of QGIS. Throughout QGIS, the syntax is based on QGIS Expressions a customized SQL dialect. This is portable ...
user avatar
14 votes
Accepted

Getting lat/long for centroids using QGIS

Inserting new fields with the field calculator and the expression $x and $y on the layer with your centroids should do the job. If you use the polygon layer of your lakes, you might include there lat/...
user avatar
  • 40k
13 votes
Accepted

Handling NULL values in labeling?

So the way QGIS handles NULL when you join strings is that it will convert the result to NULL if any part is NULL (yes I know it's on going debate on if it should or not) Here is how you handle that ...
user avatar
  • 33.8k
13 votes
Accepted

QGIS - how to use geometry generator to place a centroid in each segment of a multiline?

You can use the following expression for Geometry Generator. with_variable( 'segments', segments_to_lines($geometry), collect_geometries( array_foreach( ...
user avatar
13 votes
Accepted

Proper syntax of expression for selecting rows in QGIS

Try: "binomial" = 'Axis axis' In QGIS, double quotes " are used to reference a field. Single quotes ' are used to contain a string. No quotes for numerical values. The $ sign is used ...
user avatar
  • 24.6k
13 votes
Accepted

Using same color for label with same hour

Use Categorized symbology Value: hour("time"), Color ramp: 'Random colors' In Labels tab, use @symbol_color for the color data-defined override
user avatar
  • 3,469
12 votes
Accepted

Getting currentfeature's color in Expression Builder of QGIS?

In QGIS >= 2.14 you can use the symbol_color variable. Eg, set a data defined override for your label color to the expression @symbol_color
user avatar
  • 26.2k
12 votes

Adding text to end of existing value in QGIS

If your original field is a string-type field, you can update it instead of creating a new field. Use the Field Calculator to update an existing field Check the box next to "Update existing field" ...
user avatar
  • 23k
12 votes
Accepted

Place label along line near start and end of line in QGIS

2020 Oct update - label placement at start/end of lines or with a given offset is now be an inbuilt feature of QGIS 3.16 ! Link shows it in action. QGIS 3.8 to 3.14 Consider using the geometry ...
user avatar
  • 7,304
12 votes

Filling a field with a random string from a list in QGIS

I'm not an expression expert. My solution uses a custom function. Function definition: from qgis.core import * from qgis.gui import * import random @qgsfunction(args=-1, group='Custom') def randstr(...
user avatar
  • 372
12 votes
Accepted

Getting attribute information of multiple polygon intersected by line

Try this expression: array_to_string(overlay_intersects('Layer_A', name)) (assuming the City names are stored in name field in the 'Layer A').
user avatar
  • 29k
12 votes
Accepted

QGIS vector layer interactions: calculate percentage of polygon intersection area

Create a new attribute with Field calculator using this expression (replace orange on line 6 with the name of your "orange" layer): area( intersection( $geometry, ...
user avatar
  • 40k
12 votes
Accepted

Sorting alphanumeric array numerically using QGIS Field Calculator

Create a new function using Function Editor. Copy/paste the following script: from qgis.core import * from qgis.gui import * import re def natural_sort_key(s): ns = re.compile('([0-9]+)') ...
user avatar
11 votes
Accepted

Is there an escape option for single quotes & apostrophes in QGIS?

Using the escaping by simply doubling the single quote works for me: CASE WHEN "NAME" = 'WILSON''S' THEN '0,75,224' END Double quotes in the field value don't need escaping: CASE WHEN "NAME" = '...
user avatar
  • 74.9k
11 votes
Accepted

Creating a label from two Attribute table column titles with a space between them

It should be "First field" || ' ' || "Second field" || is string concatenation operator. Use Single quotes for Space, Double Quotes are for Field.
user avatar
  • 8,119
11 votes
Accepted

How to build a query/expression to select specific points within a buffer? (in QGIS)

This can be done using the Processing Graphical Modeler to set up a custom chain. Here's a pic: From left to right we have three inputs - the tree layer (a Vector Layer Input Object), the buffer size ...
user avatar
  • 51.1k
11 votes

QGIS using project variables in filter queries

Layer filters don't use QGIS expressions, and are instead handed directly off to the underlying data provider. So, for instance, a filter on a postgis layer is passed to postgres to evaluate, and ...
user avatar
  • 26.2k
11 votes
Accepted

Labeling only one duplicate attribute without editing original data in QGIS

You can achieve something like in the picture just below by using some expressions without editing any of your data. Just use them as they are. Follow the steps below and adjust them to your personal ...
user avatar
  • 24.6k
11 votes

Colouring points in the same colour as their nearest point/polygon from another layer in QGIS

You can use the new overlay expressions, available since QGIS version 3.16, see Visual changelog. By the way: I'm not sure what you mean that you have "a multi-polygon file with polygons and ...
user avatar
  • 40k
11 votes
Accepted

Adding new field in point layer with attribute from another layer in QGIS

You can use refFunctions Plugin. It adds custom user functions to QGIS Field Calculator. Then, you can add a new field to the point layer with the id of the polygon that contains it using the ...
user avatar
11 votes
Accepted

Use QGIS expressions to create geometries: difference between geometry generator and geometry by expression

Quick overview how to create new geometries using QGIS expressions with either Geometry generator or Geometry by expression: Geometry generator: Open Layer Styling panel / add additional symbol layer (...
user avatar
  • 40k

Only top scored, non community-wiki answers of a minimum length are eligible