Questions tagged [qgsexpression]

class for parsing and evaluation of expressions in QGIS API. Don't use this tag for non programming related questions, if you are talking about QGIS expressions use qgis-expression tag instead.

Filter by
Sorted by
Tagged with
0 votes
0 answers
13 views

Format gradient legend with thousands separator

Is it possible to format the gradient legend with the thousands separator ? I'm using QgsClassificationMethod.setLabelFormat but it doesn't accept expressions, only basic formatting. If ...
  • 1,023
4 votes
1 answer
101 views

QGIS-Atlas get feature with multiple values

I am looking for an expression to get_feature with two values from two different fields. At its core is the question: How can I transform a chain of values which define a point into a valid geometry ...
  • 99
4 votes
1 answer
85 views

QGIS Print Composer only label with visible features

I am curious if there is a way to get all features from a certain layer that are visible in the current map. I am aware that this could be done using the checkbox in the attribute table object but I ...
2 votes
2 answers
62 views

Open QgsColorDialog and modify feature in @qgsfunction from expressions

Is it possible to open a QDialog (here a QgsColorDialog) and modify layer's feature when executing a QgsExpression with a qgsfunction such as : @qgsfunction(args="auto") def label_annotation(...
  • 1,023
1 vote
1 answer
52 views

Requesting features where expression result equals a given variable

I want to get the features of a layer, where the evaluated expression equals an already evaluated expression. Can I somehow do this directly using layer.getFeatures(QgsFeatureRequest(expr == ...
  • 30.4k
7 votes
4 answers
291 views

Filtering date field on year using QGIS

In QGIS I'm trying to filter a specific year out of my field dates (type = QDate). It should not be so hard, still I'm unable to make it work. I've tried for instance: year("surveys_date") =...
  • 73
2 votes
1 answer
126 views

Selecting layer by expression with two variables using PyQGIS

I would like to filter a column coming from a layer with the command layer.selectByExpression(). I would like to leave the name of the column as a variable (not fixed). I made a conditions inside the ...
3 votes
1 answer
87 views

Adding point feature with Geometry by Expression in QGIS

I am trying to use "Geometry by Expression" to add a point feature in a layer but I am getting unexpected results. I added the expression make_point(0,0) but it just takes all the existing ...
  • 31
0 votes
2 answers
69 views

PyQGIS QGSExpression translate nothing happen

I'm trying to use this expreission and apparently works if I print the result, but nothing happen in the map canvas. Do you have some suggestions? from qgis.core import * from qgis.utils import ...
1 vote
1 answer
263 views

QGIS aggregate expression to filter selected features in 2nd layer

I´m working with two layers in QGIS: First one with point geometries representing water quality sampling places (LAYER A). The second is a spreadsheet (no geometries) that contains pollution values ...
3 votes
1 answer
147 views

Changing symbol by expression in QGIS [duplicate]

The same way we can define the color of symbols using expressions, do you know if we can change the symbol itself in QGIS 3.24? In my situation, I use a layer 'OPTIONS' to change values on the map, ...
  • 387
1 vote
0 answers
35 views

Style rule based on qgsfunction not working in QGIS 3.22 #92

I'm using a QGIS style based on a function which returns the value of a layer variable passed through a pyqgis plugin : @qgsfunction(args="auto", group="toto") def color_trajecto(...
  • 1,023
4 votes
1 answer
78 views

Creating new attribute field gained by areal intersection in QGIS

I am trying to make a new attribute field which will differentiate points, vector layer, which lie inside and outside of a polygon layer. I tried like this: CASE WHEN '...
3 votes
1 answer
76 views

Getting line length of geometry of parent feature as default value in child feature in QGIS

I have: a parent line-layer 'MyParentLineLayer' (referenced layer) with a field "parent_uuid" (referenced field). a child geometryless-layer 'MyChildLayer' (referencing layer) with a field &...
2 votes
0 answers
43 views

Increasing the smoothness of a wave

I wrote a Geometry Generator expression to create a sine wave in the canvas (don't ask, just having fun): with_variable( 'points', map( 'point_middle_left', make_point(x(@...
  • 9,967
3 votes
0 answers
172 views

case statement two string fields interacting

I have situation where the values from two fields (both strings) interact to create the value of a third (also a string). This is from a simple flowchart. I've tried using the CASE statement but I can'...
2 votes
2 answers
2k views

Removing duplicates from the Attribute table by expression in QGIS

I have some duplicates in my data attribute table, you can see below: I used the following formula: count(1, "Site ID") > 1 based on this question: Identifying duplicate attributes in ...
  • 3,763
1 vote
1 answer
272 views

Match label color to polygon color

I have a polygon layer in which I'm labelling each polygon on the map. I am trying to figure out how to make the label colour match that of the underlying polygon (with a white buffer around the label ...
  • 963
4 votes
1 answer
66 views

Exctract one record from duplicates values

I'd like to exctract only one record from duplicates records (for example in a field "test") using "exctract by expression" in qgis. Some records could be not duplicates, and ...
  • 809
1 vote
0 answers
47 views

FilterExpression only work in form

I make a QGIS plugin for 3.10. and use Relational value but my key is 2 thing. a string a int So I use the key colonne as my int and add a filter expression to add key "TYPE_MAT" = ...
  • 161
5 votes
3 answers
553 views

Selecting features containing specific text string using an expression in PyQGIS

I'm trying to select features with a specific text that I have in an attribute. I used the expressions from the PyQGIS Cookbook but I'm having trouble with the selection because the functions I'm ...
  • 53
6 votes
1 answer
294 views

QGIS label: expression to show the maximum value to label in the map irrespective of the scale

I have the following attribute. I would like QGIS to prioritise only the maximum value from field1 while labelling. In other words, on the figure 2 (zoomed out version of figure 1), I would like to ...
  • 477
0 votes
0 answers
43 views

Specific ID attribution pattern past 100 entities

I have an ID attribute which looks like this on the attribute table of a given layer: A00 A00 A00 A01 A02 A03 ... A98 A99 A00 is specifically given based on a certain attribute manually given (for ...
0 votes
0 answers
37 views

Calculating polygon areas using Field Calculator in PyQGIS [duplicate]

I am trying to calculate areas for polygons in QGIS 3.16.10 using PyQGIS 3 as you would with the Field Calculator. I am trying to use QgsExpression to create the necessary expression. However, the API ...
6 votes
3 answers
482 views

Calculating cumulative SUM in QGIS Attribute table

I'm trying to get the cumulative sum of the column "uren_duur" in a new column "uren_tot" based on the recorded water height "NUMERIEKEWAARDE". The water height ranges ...
  • 61
7 votes
2 answers
470 views

Creating field with 1/0 values depending if point sits inside polygon in QGIS

I have a layer with a single polygon and a layer with multiple points. Some of the points are inside the polygon. How can I create/update a field with a value of 1 (true) or 0 (false) depending if a ...
7 votes
4 answers
462 views

Labelling with first letter taken from each word in string using QGIS

I have a field called "Species" which is composed by two words (e.g. 'Robinia pseudoacacia') and I would like to extract the first letter of both the words in order to get two letters (e.g. '...
5 votes
2 answers
534 views

Selecting only one minimum value by expression in QGIS

If there are two values that are equal and minimum, the minimum function in "Select by expression" returns both of them. Is there any way to select by expression only one of them? If not, ...
3 votes
3 answers
447 views

Removing the time zone from datetime field in QGIS

How can I get rid of the time zone in the date/time field? So I have a GeoPackage with the following data: and want to get just 2021-06-07 16:25:40
1 vote
1 answer
359 views

How to use a QGIS expression using a Python function with custom named argument(s)

I have a Python function that I simply use as a label expression in a print layout. Its objective is to render elements from a json object stored as a field in a vector layer. This vector layer is ...
  • 9,111
3 votes
1 answer
242 views

Getting fieldnames with QGIS expressions in same order as in attribute table (not alphabetical order)

Context I want to get a list of field names of a layer using QGIS expressions. The function attributes() returns a key:value map of the attribute names and values. By default, the result is sorted ...
  • 55.3k
5 votes
2 answers
179 views

Expression to fetch polygon value intersecting end of line

I have a line layer and a polygon layer. I'm trying to create an expression to fetch a polygon attribute and add it to the line, based on in which polygon the line ends. array_last(overlay_intersects('...
  • 61k
3 votes
2 answers
317 views

Query for rendering all possible combinations of array of values in QGIS

How can I query the symbology of a layer so that I have as many symbols as all possible combinations of "chrono1", "chrono2", "chrono3"? I'm looking for an automatic way ...
  • 628
3 votes
1 answer
164 views

Select an attribute value with the Expression String Builder in QGIS

I'm working with QGIS 3.16 Hannover and this should be very straightforward but I'm unable to solve it. I'm producing different maps, filtering the features of a layer. In the composer manager, I'm ...
  • 2,698
3 votes
1 answer
373 views

"No feature was found..." when making custom grid coordinate format

I'm in QGIS layouts trying to make a custom grid coordinate format but get the error: No feature was found on this layer to evaluate the expression. This error does not appear if I have a single ...
  • 323
4 votes
1 answer
82 views

Is it possible to filter the attribute table in several years at the same time?

I have a very extensive attribute table (see screenshot) and would now like to filter the objects according to certain years (1997, 2002, 2009, 2014 and 2018) and, after that, biotope types. I think ...
2 votes
1 answer
404 views

Getting the mean value of each row for the final column in QGIS

I am trying to calculate the mean/average of all the values in a row to obtain the final value i.e., "IRAT". How can I calculate it automatically using a field calculator in QGIS? for e.g., ...
1 vote
0 answers
120 views

Reading @map_id expression variable using PyQGIS

When I try to read the expression variable @map_id using a Python expression function (see code below) inside a label text, it always returns "canvas" as result. When I use @map_id directly, ...
  • 4,651
9 votes
1 answer
172 views

Regex_replace in the Field Calculator: unexpected duplication of replacement elements

After testing things out for a different question, I found something unexpected about the way regex_replace works in the Field Calculator, compared to PostgreSQL. The suggested insert ends up ...
  • 2,952
1 vote
1 answer
237 views

In QGIS Atlas how to get the index and the number of features grouped/filtered by an Attribute with expression?

Using a QGIS Expression in the Layout Editor, how can one return the count of features matching a particular attribute value for an atlas feature, for example, "AREAS_Area". In this ...
  • 2,659
10 votes
1 answer
178 views

Selecting NULL or date values by Expression in QGIS

How can I select by expression from a date field in a shapefile, dates that are NULL or >= 2020-01-01? This doesn't work, it only selects those with dates >= 2020-01-01, not the NULLs "...
  • 61k
5 votes
2 answers
1k views

QGIS expression on layer that refers to intersects on same layer

Let's say I have the scenario where: Polygons A and B intersect polygon C There are also polygons X,Y and Z which do not intersect C. Polygon C has an attribute value 'Priority' which I need the ...
  • 3,200
2 votes
1 answer
64 views

Print out centroid coordinates of a polygon in layout text box

I wanted to put the coordinates of the centre of a polygon in a text box in the print composer. When I run the expression in the labelling panel on the canvas it works, like below However, when I run ...
1 vote
1 answer
281 views

Buffer by field value in the processing modeler in QGIS

I am using the processing modeler in QGIS 3.10. I want to buffer polygons by individual field attributes. This is not a problem when I am not using the processing modeller since one can simply choose ...
3 votes
0 answers
123 views

Populating row numbers with Field calculator using PyQGIS

I have the following code, which is creating a new column called "group" without issue, but not populating it with a row number 1-n, as I'm intending it to. pv = layer.dataProvider() pv....
  • 657
2 votes
1 answer
262 views

Filtering features outside features of another layer using QGIS geometry generator

I am trying to filter features in one layer outside features in another layer using geometry generator. I have a buildings layer and an area layer and now I want to only show the buildings outside the ...
  • 389
0 votes
0 answers
138 views

How to handle NULL values in QgsExpression()?

When I try to add multiple conditions in QgsExpression() eg: QgsExpression(f"input='{abc}' OR value='{def}'") here abc = 1 and def = NULL. Even though abc is having value I am getting NULL ...
1 vote
1 answer
47 views

QGIS Fieldcalculator

I have a QGIS layer with points and the column 'name'. This column contains names like "AS 10450 to 1045" or "BAS 1045B100 to AS 1457745". Now I want to create another column with ...
5 votes
3 answers
652 views

Creating line from points and counting the number of points on that line

I have a shapefile that contains a number of points, each point represents a tree. I would like to calculate how many trees there are per row. Hence my question (I think this is the best method), how ...
  • 59
3 votes
6 answers
381 views

Listing IDs of all selected features with expression in QGIS

I would like to get an array with IDs of all selected features of layer 'LayerB' (field-name: "id_of_layerB") as a default value in a QGIS Attribute form of 'LayerA'. I tried something like: ...