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 ...
karpfen's user avatar
  • 2,295
25 votes
Accepted

Concatenating labels in QGIS

This is because concatenate() is an aggregate function (i.e. it looks up the values for that attribute across all features), so when you try for example concatenate("GROUP") you'll still end ...
she_weeds's user avatar
  • 10.8k
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 ...
Midavalo's user avatar
  • 29.6k
21 votes
Accepted

Extracting part of string from field in QGIS Field Calculator?

Since the number of characters is the same, you can use the substr() function on a new field as in the following expression: substr( "Location" ,17,6) In the above example, I used Path ...
ahmadhanb's user avatar
  • 40.5k
21 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 ...
Ian Turton's user avatar
  • 80.5k
21 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 (...
Babel's user avatar
  • 67.4k
20 votes

Creating perpendicular lines on line using QGIS

Edited answer: My first solution (see below) was for visualisation purposes only. But as you mentioned afterwards, you need the actual geometry. So this here is how to do it: Go to Menu Processing / ...
Babel's user avatar
  • 67.4k
20 votes
Accepted

Re-locating points randomly at certain distance in QGIS

This answer has been updated several times to get a solution that gradually adds complexity to the expression. For the final solution, you should go directely to the very bottom (step 5). The history ...
Babel's user avatar
  • 67.4k
18 votes

Rendering dashed lines between adjacent polygons correctly in QGIS

To this kind of interesting but recurring cartographic question, there is different approaches (some suggested in the comments): The classic approachs is to use dashed lines with a white solid line ...
gisnside's user avatar
  • 7,798
18 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)]
JGH's user avatar
  • 40.9k
18 votes
Accepted

Making ellipse based on ellipse-like polygon in QGIS

Apply the "Oriented minimum bounding box" (see documentation) From these, create ellipses with values from the attribute table calculated in the first step: make_ellipse(centroid($geometry),...
Babel's user avatar
  • 67.4k
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' ...
Kadir Şahbaz's user avatar
16 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 ...
Nathan W's user avatar
  • 34.6k
16 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.
neogeomat's user avatar
  • 8,320
16 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 ...
she_weeds's user avatar
  • 10.8k
16 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/...
Babel's user avatar
  • 67.4k
15 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 ...
Matthias Kuhn's user avatar
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, ...
ahmadhanb's user avatar
  • 40.5k
15 votes
Accepted

Calculating interior angles of polygons or lines in QGIS

The short answer: To get the left-hand angle of any line or polygon at a vertex n, use this expression and replace 20 on line 3 with the index of the vertex at which you want to calculate the angle. ...
Babel's user avatar
  • 67.4k
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 ...
Babel's user avatar
  • 67.4k
15 votes
Accepted

Applying labelling with obstacles in QGIS

Why obstacles do not work The setting Features act as obstacles only works for features of the same layer. Use Geometry generator to define label placement Go to Label / Placement tab and use Geometry ...
Babel's user avatar
  • 67.4k
14 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" ...
csk's user avatar
  • 24.5k
14 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, ...
Babel's user avatar
  • 67.4k
14 votes

Faster calculation of cumulative sum in attribute table in QGIS

You can use the script below in QGIS Python Editor. It takes about 45 seconds (including saving to the source file) for 1.5 million features in SSD or HDD. Select the layer first. import time from ...
Kadir Şahbaz's user avatar
13 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 ...
MrXsquared's user avatar
13 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(...
Emma's user avatar
  • 422
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( ...
Kadir Şahbaz's 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 ...
MrXsquared's user avatar
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
Noura's user avatar
  • 3,409
13 votes
Accepted

Buffer is too small (OSM Data, EPSG 3857)

Measurements in EPSG:3857 are always wrong. To create correct buffer sizes and thus to cope with the problem, there are different ways - depending on your use case: In your case (small buffer size), ...
Babel's user avatar
  • 67.4k

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