Questions tagged [expression]

Expressions are SQL-like statements that are used to evaluate dynamic properties.

Filter by
Sorted by
Tagged with
20
votes
2answers
24k views

How to select features containing specific text string using an expression in QGIS

I need to style a survey parcel polygon shapefile, based on whether the polygon is a mineral claim or not. Unfortunately, the only information on whether a polygon is a mineral claim or not is ...
20
votes
3answers
20k views

Learning to use expressions in QGIS?

Is there any resource recommendations in general for getting past the basics of QGIS and going into the deep dark secrets? Specifically in relation to expression coding for labeling, queries, etc.
13
votes
3answers
4k views

How to set transparency per polygon in a shapefile in QGIS?

How to set transparency per polygon in a shapefile in QGIS? For example: a polygon with field "value" = 1 should be fully transparent whereas field with field "value" = 0.4 should have a 40% ...
11
votes
1answer
1k views

QGIS query syntax differs between attribute table and feature filter

Using QGIS 2.16.2, I can successfully select records from a shapefile attribute table using the following expression: left("start_time", 10) = '2015-08-01' Please note that start_time is a string ...
11
votes
1answer
442 views

Using some 'temporary variables' in QGIS Geometry generator symbol layer type expression?

Making use of the Geometry generator symbol layer type, I draw rectangles of dimensions @nv_bg_w (width) and @nv_bg_h (height) (project variables) to line features, either at coordinates text_x, ...
9
votes
1answer
321 views

Using transform function in QGIS layer geometry generator?

I'm trying to use the following expression in the geometry generator in a QGIS layer to show a 1-mi boundary around points: buffer(transform($geometry, 'EPSG:4326', 'EPSG:102654'), 5280) However, the ...
8
votes
3answers
1k views

Difference between quotation marks ('single' vs “double”) in QGIS

I am not a new QGIS user, however, I am still confused concerning the quotation marks syntax ('single' vs "double"). I know something about the quotation marks and the way they are applied in Python ...
8
votes
3answers
4k views

Extracting part of string from field in QGIS Field Calculator?

I want to create a new field in my attribute table. My goal: returning all digits between the / and _ characters of the field named "location" by applying the next expression: regexp_substr( ...
8
votes
1answer
233 views

Place label along line near start and end of line in QGIS

I have four fields managing the numbering of the start and end of road sections. I created two label rules, one for the start and one for the end of the road sections. I set the position of the ...
8
votes
2answers
2k views

How to build QgsExpressions in python?

How can I build a feature request expression using variable inside expression? For example values = [1, 2, 3] for j in range( y ): it = vl.getFeatures( QgsFeatureRequest().setFilterExpression ( u'"...
8
votes
1answer
285 views

Accessing QGIS map canvas as a variable for expressions

Is it possible to access the QGIS Map Canvas as a variable or expression value to be used in the field calculator or labelling engine? (i.e. so that you can create an expression that selects/...
7
votes
1answer
1k views

How to build a query/expression to select specific points within a buffer? (in QGIS)

I have a point layer in QGIS. Each point represents a tree and each tree has information about its height as an attribute. I would like to build a query/expression to select all those trees that have ...
7
votes
1answer
375 views

Expression in field calculator to pick out multiples of x

I have an attribute table of contours at intervals of 10m but I wish to label the layer at intervals of 50m. My method was to create a new field with an expression which would copy the entries in the ...
7
votes
2answers
1k views

QGIS using project variables in filter queries

In QGIS 2.14.11 LTR I have to apply the same (or similiar) filter query to various layers. I have the road name to filter for in a project variable and try to apply the following query: "road_name" = ...
7
votes
2answers
366 views

QGIS 3.4 calculate date, add month

I want to add a number of months to a date to get a new date. I have a date-field "date", an integer-field "months" and a date-field "new_date". I want to calculate the "new_date" by adding the "...
7
votes
1answer
2k views

Aggregating with attribute($currentfeature) filter in QGIS

Why doesn't the filter work (4th variable passed into the aggregate function) when I try to use in the field calculator an expression of this type: aggregate( 'Layer', 'sum', "Field1" , "Field2" = ...
7
votes
3answers
269 views

Set background or text color depending on expression in an attribute table in QGIS composer

I am using QGIS 3.0.2. I am working on a print composer including an attribute table. I would like to set different colors to each rows, depending on an expression, refering to an attribute. I didn't ...
6
votes
2answers
1k views

Getting currentfeature's color in Expression Builder of QGIS?

In QGIS Expression builder. I want to obtain the color code of the current feature. I mean: My layer contains lines, each one is painted with a different color. Now I want to assign that color to ...
6
votes
3answers
1k views

How to select specific rows of polygons from a grid in QGIS?

I have a polygon layer. I would like to select every second row of the polygons but not manually. Is there an expression to select every second row as seen on the picture with Select by expression in ...
6
votes
2answers
179 views

Getting text name of current project CRS in QGIS Layout

I'm want to display the current project projection in a QGIS layout. Right now I can get QGIS to display the current EPSG number like below: But what I want to do is get QGIS layout to print the ...
6
votes
2answers
69 views

Assign values to points according to a pattern

I'm making a map of trees in QGIS (3.10). Each point represents a tree and the attribute table has a column that should contain the tree species. For now this column is empty, but I would like to fill ...
6
votes
1answer
165 views

Expression to change an attribute each X number of rows

I'm using QGIS and I need an expression to change an attribute each X number of rows. For instance I have the next attribute data: I want to create an attribute (C) that assigns an ordered value each ...
6
votes
1answer
684 views

Set expression in QGIS edit widget relation reference with PyQGIS

I've setup an edit widget for a field as a relation reference like shown below and save the configuration as a QGIS layer style file (*.qml): With PyQGIS I do the following steps load the vector ...
6
votes
3answers
2k views

Achieving Super or Subscript graticule labels in QGIS Composer windows?

It is quite common for paper topographic maps to label the map graticule with ordinate values in a mixture of superscript and standard digits, eg. ⁴123⁰⁰⁰ to emphasise the significant digits. The ...
6
votes
2answers
186 views

Is it possible to distribute custom python expressions along with .qgs file?

I have a QGIS project I'm working on with a few other users. The print composer and map tips use custom python expressions in the expression builder. I know the expressions are store in .qgis2/python/...
6
votes
1answer
60 views

Find out what Expression has been used to populate an attribute column in QGIS

I need to find out what expression has been used in the field calculator to populate a number of columns in the the attribute table in QGIS. Does anyone know how to get it to display this info? Like ...
6
votes
1answer
209 views

Updating shared custom functions / expression code in QGIS

All the QGIS documentation I've seen on custom functions (used in expressions) says that the code is saved in the user's local expressions directory, e.g. ~/.local/share/QGIS/QGIS3/profiles/default/...
5
votes
2answers
243 views

Find lower/upper case letters in QGIS

Is there a possibility to find lower and/or upper case letters in QGIS? I know that it is possible to convert all lower to upper: upper('hello WOrld') → 'HELLO WORLD' and all upper case to lower: ...
5
votes
3answers
759 views

How to escape percent in a LIKE expression in qgis?

How can we escape a percent character in a LIKE expression in QGIS? For example, if I have the following column: 123% , 15% , albert, greg, 15% How do I select all the values with % in it without ...
5
votes
2answers
1k views

QGIS atlas, add picture with path from attribute

I love working with the atlas generator and I came up with a new case to use it for. I want to add a picture to my map from URL. I am allowed to add a picture if I type in the full url path. eg. http:/...
5
votes
2answers
15k views

QGIS Multiple CASE WHEN/THEN Statements for Expression Based Labels

I am trying to label a single point with multiple labels, based on the attributes for that point. For example, if one of the attributes is equal to 1, I want to label it with a specific text string; ...
5
votes
1answer
136 views

Rule-based labeling with optional second field

I need to label some polygons with 2 fields using only one label: The first being a field in the attribute table named "Bio-Code" the second one being optional if a cell in the field "BBT-Code" is ...
5
votes
1answer
718 views

Labeling only one duplicate attribute in QGIS without editing original data

I have several points (e.g. 4 bus stop positions) in one area. They all belong to the same station, so they all have the same name attribute. To avoid a mess of lables showing all the same name I only ...
5
votes
1answer
5k views

How to create an Arcade Expression that excludes empty field values

In ArcGIS Online, I have a point layer with attributes Provider1, Provider2, Provider3.....Provider13. The values are text consisting of people's names. I would like to configure the popup to ...
5
votes
1answer
181 views

Test for (curly) brackets in expressions in QGIS 2.14.14 with strpos() weird results

When trying to find a strpos() of a substring containing curly brackets (or brackets anyway as far as I can see) I get 0 as a result. Test for substring without {} works fine: Test for substring ...
5
votes
3answers
14k views

If-Then Label Expression

I'm trying to create a VB label expression on streets such that streets with an alternate name (ACS_ALIAS) will be labeled with the LABEL name and the alternate name in parentheses; streets with no ...
5
votes
1answer
2k views

Using round function in QGIS expression?

I created a grid of rectangular polygons with the Create Grid function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2. The rectangles measure half a degree of longitude by ...
5
votes
1answer
514 views

Using a loop in a python expression to stack labels while avoiding zero value attributes

I have a number of point features in a map in ArcMap 10.6 that I would need to label based on information form three fields (Test1, Test2 and Test3) with numeric values. The labels from these 3 fields ...
5
votes
1answer
1k views

referencing to features geometry in an expression

I have a layerA with roads and a layerB with one shortest path. If I put an aggregate function into a virtual field in layerB to calculate the sum of fieldAA where the shortest path contains features ...
4
votes
3answers
368 views

Automating citation of data source in QGIS print composer?

I have 20 thematic maps with different sources like CITY PLANNING OFFICE, ENVIRONMENT OFFICE, AGRICULTURE OFFICE etc. Since I have many maps, I want to automate the data source citation of my ...
4
votes
2answers
185 views

QGIS: Use 'replace' expression for 2 characters in one field calculation

I have a field of currency values in an attribute table. As an example, I'm attempting to replace £10,000.00 to 10000.00 so QGIS can run graduated styles on the new field. The following replaces the £ ...
4
votes
3answers
153 views

Hiding points in shapefile layer using QGIS

I am using QGIS 3.4 I would like to hide all points that end with "5". For example, I would like to hide: 55, 65, 75, 85 and any point ending in "5". What method can be use to make this possible?
4
votes
2answers
1k views

How to optimize QgsFeatureRequest with filter expression

I have a point PostGIS layer (my_layer) which has more than 66000 features. I am getting the features I want but it takes too long. My code is: resultList = [] req = QgsFeatureRequest()....
4
votes
2answers
3k views

How can I get features that satisfy a QgsExpression using PyQGIS?

I have two fields say "State" and "name" which would be get from the two comboboxes. After which, based on the current text in the combo box, I want to make QgsExpression and feature that satisfies ...
4
votes
3answers
4k views

Using 'max()' in expression with QGIS?

I want to make a rule-based style on the maximum value from a field. I set my expression like: max("fieldname") It returns every value instead of only the maximum one. Can anyone tell me the right ...
4
votes
2answers
76 views

Nested if statement in QGIS label expression

I'm trying to create labels for features, based on the value (or missing value) of three different columns and combinations can be possible. I have three columns: Veg_dom, Veg_codom and Veg_onderg. ...
4
votes
2answers
350 views

QGIS how to select entries not in another layer

I have 2 layers of polygons in QGIS which are layer1 and layer2. they both have column id. The goal is to select items in layer1 that not appear in layer2 using unique field id. For example: layer ...
4
votes
2answers
282 views

Correct SQL expression when looping different fields

I'm having trouble with the follow lines of code. Practically what I am doing is a 10 shapefile loop in which field represents the name of the field that I want to be calculated( the name differs by ...
4
votes
1answer
4k views

Adding text to end of existing value in QGIS

I have a column in a large attribute table. The values in this column are numeric value. Example entries in this case would be: 1, 2.0512, 8.5744, 8.944 How can I add the word 'm' to the end of ...
4
votes
2answers
161 views

Dropping & inserting specific characters within a field being used for labeling

I would like to find out how to properly format a conditional expression in labeling, so as to only get specific characters back out of a field that has 9 characters in it, but don't wish to label ...

1
2 3 4 5
9