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 ...
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 ...
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 ...
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 ...
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 ...
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 (...
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 / ...
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 ...
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 ...
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)]
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),...
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'
...
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 ...
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.
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 ...
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/...
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 ...
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, ...
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.
...
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 ...
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 ...
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"
...
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,
...
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 ...
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 ...
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(...
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(
...
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 ...
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
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), ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
expression × 936qgis × 763
labeling × 134
field-calculator × 116
attribute-table × 74
qgis-3 × 72
fields-attributes × 54
print-composer × 52
geometry-generator × 49
arcgis-desktop × 41
filter × 39
polygon × 37
atlas × 36
pyqgis × 33
symbology × 33
line × 29
point × 26
string × 24
geometry × 22
select-by-attribute × 21
python × 19
python-parser × 19
qgis-modeler × 19
array × 19
rule-based × 19