Questions tagged [expression]

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

Filter by
Sorted by
Tagged with
12 votes
1 answer
9k views

Use QGIS expressions to create geometries: difference between geometry generator and geometry by expression

QGIS has a powerful expression machine that can be used (between other things) to create new geometries, based on existing layers. Basically, there are two options: Geometry generator (introduced in ...
Babel's user avatar
  • 71.2k
8 votes
1 answer
561 views

Projection transformation of a shapefile

I am using QGIS 3.18.1. I am working on a map around Alaska. I added a world basemap, then added DEM and finally drew a few polygon shapefiles on top. I then tried to find a projection more ...
Mario Westphal's user avatar
6 votes
1 answer
946 views

Buffer is too small (OSM Data, EPSG 3857)

I buffered some lines with 100 m in QGIS. When I measured it turns out instead of 100 m its 62. I understand the issue could relate to the CRS. I used EPSG 3857 because the OSM map in the background ...
BAE_23's user avatar
  • 667
6 votes
3 answers
4k views

Calculating interior angles of polygons or lines in QGIS

The problem In QGIS, it's easy to calculate areas of polygons or lengths of lines using QGIS expressions with area ($geometry) / $area or length($geoemtry) / $length respectively. However, there is no ...
Babel's user avatar
  • 71.2k
16 votes
4 answers
14k views

Creating perpendicular lines on line using QGIS

In QGIS I want to create perpendicular Lines on another Line (River). The Lines should be created on points on the Line and should have a length of 40 Meters. I want to create the red lines in the ...
KartenLappen's user avatar
13 votes
3 answers
3k views

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

I am confused concerning the quotation marks syntax ('single' vs "double") in QGIS. I know something about the quotation marks and the way they are applied in Python scripting (i.e. comments,...
Taras's user avatar
  • 32.9k
12 votes
3 answers
2k views

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

In QGIS 3.18, I have two point layers: layer_1 with attribute id_1 and layer_2 with id_2. I want to use the overlay_nearest function: overlay_nearest(layer[,expression][,filter][,limit=1][,...
Babel's user avatar
  • 71.2k
11 votes
1 answer
2k 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 ...
Stu Smith's user avatar
  • 8,302
10 votes
1 answer
865 views

Re-locating points randomly at certain distance in QGIS

I have GPS coordinates which identify aid projects in Africa. Now, I want to re-locate these projects, such that each project is re-located by 100 km in a random direction from its original location. (...
Franziska's user avatar
  • 119
8 votes
2 answers
4k 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 ...
Andy Harfoot's user avatar
  • 3,367
7 votes
1 answer
2k views

Refering to the input-layer of a QGIS model in field calculator expression

The setting In a QGIS model, I have an input layer polygon from which a grid is created. On this grid-layer, a new attribute field should be created based on an expression that refers to the input ...
Babel's user avatar
  • 71.2k
4 votes
2 answers
1k views

Colouring points in the same colour as their nearest point/polygon from another layer in QGIS

I got two files, a multi-polygon file with polygons and points (File 1) and a file with points only (File 2). Our task is to fill the color of the points from File 2 with the respectively nearest ...
Nokturius's user avatar
  • 119
28 votes
2 answers
24k views

What is the difference between != NULL and IS NOT NULL in QGIS filter expressions?

I have a shape layer with an attribute containing NULL values to which I would like to apply a filter for values different from NULL. Using the available GUI for such query construction, one would ...
Jochen Schwarze's user avatar
7 votes
1 answer
3k views

Labeling only one duplicate attribute without editing original data in QGIS

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 labels showing all the same ...
MrXsquared's user avatar
  • 34.4k
6 votes
2 answers
4k views

Getting lat/long for centroids using QGIS

I have a series of polygons (lakes) in Kansas, Oklahoma and a few in Texas. I created centroids for each lake, which I needed for distance measurements. These centroids have derived lat/long ...
gwfami's user avatar
  • 123
2 votes
1 answer
105 views

Assigning specific feature in expression builder

I have a question regarding "Making tiny objects visible for their location when zooming out" in QGIS: Making tiny objects visible for their location when zooming out or more specifically ...
Niklas's user avatar
  • 35
15 votes
4 answers
4k views

Rendering dashed lines between adjacent polygons correctly in QGIS

I have adjacent polygons that I want to be marked out with dashed or dotted lines. This sometimes works but there appears to be a problem where the pattern isn't always synchronised on the shared ...
John K's user avatar
  • 213
11 votes
2 answers
11k views

How to get attribute values of another layer with QGIS expressions

The question: How is it possible to get the value of an attribute in another layer? What is clear: When using QGIS expressions on a layer, it is possible to relate to features of another layer with ...
Babel's user avatar
  • 71.2k
10 votes
2 answers
36k 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; ...
Wes Kent's user avatar
  • 201
10 votes
0 answers
337 views

Performance-limits of QGIS expressions

I use quite often QGIS expressions and I am wondering how performant they are compared with other possibilities. In many cases, the same problem can be resolved using different approaches like using ...
Babel's user avatar
  • 71.2k
8 votes
1 answer
2k 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 ...
Skye's user avatar
  • 1,043
7 votes
2 answers
2k 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 ...
Egidi's user avatar
  • 3,738
7 votes
2 answers
2k views

Extracting text within parenthesis in a QGIS attribute table

I have a shapefile of data for Japan, and I need to extract the English character names in my "name" field in order to label the layer. Much of the data is all in Japanese, but some of the names have ...
Christy Heaton's user avatar
6 votes
2 answers
645 views

Saving frequently used expressions in QGIS

Is there any way to save frequently used expressions in the selection or field calculator dialogs? Obviously I can cut and paste them into a file where I might save them, but I mean within the context ...
Llaves's user avatar
  • 5,963
5 votes
1 answer
13k 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 ...
Gabriel De Luca's user avatar
4 votes
1 answer
781 views

QGIS vector layer interactions: calculate percentage of polygon intersection area

I am new to QGIS and have two vector layers (the green one, displayed in graduated symbology, and separately the orange layer - see image pasted below). I want to create a new field in the attribute ...
em.popcorn2's user avatar
3 votes
1 answer
1k views

QGIS Geometry Generator: make_line once per grouped geometries

I am using a Geometry Generator symbol layer to draw lines between grouped points. I am grouping points based on two fields letter and number, which I concatenate to make the groups (GeoPackage ...
Matt's user avatar
  • 16.9k
3 votes
1 answer
469 views

Can the ArcGIS solution for uneven buffering be achieved in QGIS? version 2 - uneven tree canopies

I want to create tree canopies with uneven canopy extents. A previous solution is below: Representing uneven tree canopy spread around point in QGIS A solution for uneven buffering has been provided ...
user163808's user avatar
2 votes
3 answers
1k views

Extract by expression - N first

How can I "extract by expression" the N first (10 highest values of one column, for example) I need it for the graphical modeler.
Adrian Alonso-Frontela's user avatar
20 votes
3 answers
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
3 answers
18k 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( ...
abrobia's user avatar
  • 137
11 votes
2 answers
1k views

Applying labelling with obstacles in QGIS

I'm working with QGIS 3.16 Hannover and I'm quite confused with the option Features act as obstacles. According to QGIS documentation (13. The Style Library » 13.3. Setting a label » 13.3.2.3.4.4. ...
jpinilla's user avatar
  • 3,230
9 votes
2 answers
5k views

Is there an escape option for single quotes & apostrophes in QGIS?

I'm trying to use the Data Defined symbology in QGIS ver 2.2. Some of my data has single quotes/apostrophes. Since the string must use single quotes, is there an escape option I can use for the field ...
mike's user avatar
  • 981
6 votes
3 answers
955 views

Calculating distance between multiple points within buffer using QGIS

I am very new to QGIS. Attached is an image of my QGIS project so far. In this, you have the pinkish points of the "Point_centers" layer and green points labeled "Point_trees" ...
Charles Paulino's user avatar
5 votes
1 answer
2k 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 ...
PieterB's user avatar
  • 5,287
5 votes
2 answers
207 views

Counting number of points in one layer within fixed distance to points in another layer in QGIS

In QGIS 3.22.7 I want to count the number of points on point 'layer B' within 60m of each point on point 'layer A' and add a column to the data on point 'layer A'. What is wrong with the following ...
osakanatengoku's user avatar
5 votes
1 answer
2k views

Use field calculator to check for intersection

Ultimate goal I plan to retrieve attributes from layers using the field calculator where they intersect with a geometry. Current step Checking whether the current $geometry intersects with the layer ...
Erik's user avatar
  • 16.3k
5 votes
2 answers
443 views

Creating line between point layer and line layer in QGIS

My goal is to create a line layer that is derived from the distance between a point layer and a line layer. An example could be using a line layer representing a road and a point layer representing a ...
sudofizz's user avatar
  • 195
5 votes
1 answer
280 views

Hiding layer for N seconds in QGIS: animate symbols with custom intervals

This is a follow-up to Making geometry blink in QGIS, for which I couldn't find any answer online. It is relatively simple, using the Time Manager plugin or the Temporal Controller native tool in QGIS,...
Trikelians's user avatar
5 votes
3 answers
643 views

Define a unique ID (serial number) based on values in a field

I'm trying to generate a unique serial number for a dataset I have, for example, something like this: As shown, I would like to have a serial field, called SERIAL in this case, that increments based ...
Rodrigo Suárez Castaño's user avatar
4 votes
2 answers
9k views

How to convert decimal point to comma in QGIS?

I am working with data in Colombia where decimal points are written as commas. I would love to create a new column in QGIS that would convert all decimal points (periods) to commas for the purpose of ...
robint's user avatar
  • 71
4 votes
2 answers
2k views

Optimizing 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()....
okorkut's user avatar
  • 268
4 votes
1 answer
1k views

Summing up the area on a polygon by a certain attribute result

I wish to know if there's a tool on QGIS equivalent to the Excel's "SUMIF". I have a shapefile of a land use and cover that's classified by the attribute with the name of the classes, for example: "...
Eric Lino's user avatar
  • 394
4 votes
1 answer
2k views

Extracting GeoTIFF colours and adding to equal geometry shapefile

I have the following map in .png-format that I would like to replicate, but I cannot obtain the original data. The map shows the current water supply vulnerability for local municipalities in South ...
JohnGIS's user avatar
  • 505
4 votes
0 answers
2k views

QGIS expression for label text to display vertex coordinates of polygons

This question is inspired by Displaying vertex coordinates of a polygon or line without creating a new layer and especially by the answer by @JGH: https://gis.stackexchange.com/a/381130/88814 The ...
Babel's user avatar
  • 71.2k
4 votes
1 answer
812 views

Create an inscribed square inside a polygon

I have polygons of the administrative boundaries and want to create a square polygon inside of them, which will have the maximum area and will be fully covered by these boundaries. In other words: how ...
sailestim's user avatar
  • 217
4 votes
2 answers
842 views

Numbering points per polygon group with QGIS expressions

In QGIS, I have a point and a polygon layer. I want to number the points ascending from left to right (from smallest to highest x-coordinate value - West to East). However, counting should be made ...
Babel's user avatar
  • 71.2k
4 votes
1 answer
667 views

Calculating the percentage of overlapping areas from different layers in QGIS

I work with QGIS 3.16 Hannover and I have three polygon layers 'A', 'B', 'C' with multiple geometries in each. In the image, layer 'A' has the bold polygons and, for each of them (meaning within each ...
jpinilla's user avatar
  • 3,230
3 votes
1 answer
930 views

Using QGIS expression with overlay_nearest() function to create line connecting point to two nearest points of other layer

I have in QGIS ver 3.22 two point layers named: source_p target_p I want to point automatically with a line from the source_p layer to the two nearest points on the target_p layer. Manually, I was ...
Rii Pii's user avatar
  • 425
3 votes
2 answers
2k views

Limiting available values in dropdown field of QGIS form according to value selected in previous field?

I'm building a rather complex entry form for a layer stored in a PostGIS database. I am following this usage scenario: On several occasions I have dropdown fields which lets the user select a type of ...
Grgoje's user avatar
  • 43