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
3 votes
1 answer
153 views

QGIS Attribute Form -> Value Relation -> Filter expression: expressions or functions to get the names of current layer and current field

Shortcut to the core question: How to write a custom function to get the name of a field in an Attribute Form? I would like to use it as a variable in a Filter expression of a field with a Value ...
Bernd V.'s user avatar
  • 3,179
1 vote
1 answer
41 views

PyQGIS expression not working from script but working with GUI

I'm working on some automation with QGIS. From two polygon layers (buildings and areas) I want to extract the max value of a field in areas touching the building. So far this is what I have: def ...
pfrud's user avatar
  • 81
9 votes
1 answer
141 views

"'QgsPyExpressionFunction' object is not callable" when using custom function within QgsPyExpressionFunctions in PyQGIS

I created a function force_numeric_list in my QGIS Expression "Function Editor" (see image below) to reuse it in other functions there, e.g. as shown below in the function ...
Honeybear's user avatar
  • 2,386
2 votes
1 answer
142 views

Finding maximum possible distance of point to polygon boundary using QGIS Expression

Points layer is structured as below Polygons layer also has code as a field For each point, I want to get maximum possible distance to the edge of the polygons listed with code in the overlap column. ...
B Alexander's user avatar
2 votes
1 answer
34 views

Populating new field with data from old field such that new field at fid was equal to old field at fid -1 in QGIS

In QGIS there is a layer 'Layer' with its attribute table: fid Oldfield Newfield 1 cat ----- 2 horse cat 3 dog horse 4 swan dog I tried ...
ujjwal basnet's user avatar
0 votes
0 answers
56 views

Expression works in one QGIS project, but not another

I have an expression in a Print Layout that populates a label with an attribute, based on which polygons are selected in map view. In the QGIS project that I made, it works perfectly. I tried copying ...
Winet's user avatar
  • 34
4 votes
1 answer
90 views

Aggregate expression seems to be calculating the first value only

I have 2 vector layers: a point layer (named Messedatei, with 5 columns named field_1-5) and a line layer (each feature is build with only 2 vertex points). I want to calculate the 'z value' of a ...
Szymon Piotr Jerzy Czwart's user avatar
5 votes
2 answers
224 views

Converting column with category names to numeric codes in QGIS Field Calculator

I use the Field Calculator in QGIS to transform an attribute column with category names to numeric codes. I use the following expression: CASE WHEN "category" = 'Foo' THEN 1 WHEN &...
winnewoerp's user avatar
  • 1,508
1 vote
1 answer
70 views

Expression for numbers displayed to 1 decimal place in QGIS

I am having an attribute table in a layout with one of the columns being % values using the expression: to_string("input data_1_ant_care") + to_string('%') The challenge is the numeric ...
Stephen Okiya's user avatar
0 votes
0 answers
49 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 ...
dmjf08's user avatar
  • 1,233
2 votes
1 answer
136 views

Counting polygons with multiple filters in QGIS

I am using the aggregate expression in QGIS to count how often my polygon name appears in another point layer. The 'Polygon_zone_name' exists on both my polygon layer and my points layer, I can ...
Hibernian3's user avatar
4 votes
1 answer
241 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 ...
Janko's user avatar
  • 185
4 votes
1 answer
224 views

Using underscore when concatenating fields with expression in QGIS Field Calculator

I am creating a new field with two existing fields and the result has to be like 1234_Abcd. I used the string concatenation in the Field Calculator but it gives me 1234Abcd. How can I insert the ...
OscarGuerraRea's user avatar
4 votes
1 answer
175 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 ...
MightyRavendark's user avatar
2 votes
2 answers
104 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(...
dmjf08's user avatar
  • 1,233
2 votes
1 answer
72 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 == ...
MrXsquared's user avatar
  • 33.8k
7 votes
4 answers
757 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") =...
Jessica's user avatar
  • 73
2 votes
1 answer
290 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 ...
Paulo Matias Montecinos Medel's user avatar
3 votes
1 answer
284 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 ...
David's user avatar
  • 31
0 votes
2 answers
108 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 ...
enzo cocca's user avatar
1 vote
1 answer
548 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 ...
janavaarro's user avatar
3 votes
1 answer
219 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, ...
Giene's user avatar
  • 669
1 vote
0 answers
37 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(...
dmjf08's user avatar
  • 1,233
4 votes
1 answer
89 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 '...
Marin Mirošević's user avatar
4 votes
1 answer
109 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 &...
user191847's user avatar
3 votes
0 answers
66 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(@...
bugmenot123's user avatar
  • 11.2k
3 votes
0 answers
203 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'...
user107128's user avatar
3 votes
2 answers
5k 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 ...
Geographos's user avatar
  • 4,077
2 votes
1 answer
595 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 ...
grego's user avatar
  • 1,023
4 votes
1 answer
85 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 ...
Mark's user avatar
  • 955
1 vote
0 answers
49 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" = ...
Pierre's user avatar
  • 161
5 votes
3 answers
1k 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 ...
caro's user avatar
  • 53
6 votes
1 answer
543 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 ...
Raj's user avatar
  • 487
0 votes
0 answers
44 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 ...
IKindaNeedAHand's user avatar
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 ...
Sean Jarrett's user avatar
6 votes
3 answers
928 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 ...
timdub's user avatar
  • 61
7 votes
2 answers
821 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 ...
Jiinglelocks's user avatar
7 votes
4 answers
778 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. '...
Tommaso Se's user avatar
5 votes
2 answers
968 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, ...
kartographinya's user avatar
3 votes
3 answers
619 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
kartographinya's user avatar
1 vote
1 answer
596 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 ...
swiss_knight's user avatar
  • 10.1k
3 votes
1 answer
404 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 ...
Babel's user avatar
  • 70.4k
5 votes
2 answers
235 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('...
BERA's user avatar
  • 71.2k
3 votes
2 answers
399 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 ...
ddomizia's user avatar
  • 648
3 votes
1 answer
267 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 ...
jpinilla's user avatar
  • 3,230
3 votes
1 answer
636 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 ...
jake9wi's user avatar
  • 333
4 votes
1 answer
136 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 ...
Bellis1511's user avatar
2 votes
1 answer
691 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., ...
Gokul Anand's user avatar
1 vote
0 answers
159 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, ...
christoph's user avatar
  • 5,440
9 votes
1 answer
234 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 ...
Encomium's user avatar
  • 3,103