Skip to main content
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,307
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
  • 12.6k
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.8k
24 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
  • 73.1k
23 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
  • 82.1k
22 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
  • 73.1k
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
  • 41.1k
21 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
  • 73.1k
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,858
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
  • 42.3k
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
  • 73.1k
18 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
  • 73.1k
17 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
  • 12.6k
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

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
  • 73.1k
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
  • 41.1k
15 votes
Accepted

Projection transformation of a shapefile

What went wrong: If you transform, only the vertices are transformed, not the connecting line: this is always drawn as a straight line on the projected map canvas. So it's "path" will differ ...
Babel's user avatar
  • 73.1k
15 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
  • 73.1k
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
  • 73.1k
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
  • 73.1k
15 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
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.9k
14 votes
Accepted

QGIS expression with overlay-fuction: filter-condition based on comparison of attributes from two layers

I tested some configurations, tried to understand how it works. So ! I figure it out. The scope of the filter parameter in the expression function of overlay_nearest is purely the layer set in the ...
J. Monticolo's user avatar
  • 15.8k
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
  • 34.9k
13 votes
Accepted

Getting values from adjacent polygons or nearest point

You can use QGIS expressions with the new overlay_nearest function, availble since QGIS 3.16 and the array_mean() function, available since QGIS 3.18. If you already have an attribute in the polygon ...
Babel's user avatar
  • 73.1k
13 votes
Accepted

Removing leading zero from string in QGIS

The following should be working : regexp_replace("field_to_modify",'\\A0','') Only if your aim is to strip a (=one) leading zero ...
Snaileater's user avatar
  • 5,743
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
  • 34.9k

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