New answers tagged

0 votes

Moving (snap) lines to nearest features in QGIS

The idea is to snap all the vertices of Layer_A to Layer_B and then create the line_substring() of Layer_B from one to the next of these snapped points. To do so, use the expression below on Layer_A ...
Babel's user avatar
  • 67.2k
3 votes
Accepted

Classifying in QGIS into arbitrary number of percentiles instead of quantiles, based on attribute field value

Another answer is to make a custom python function in the advanced field calculator: from qgis.core import * from qgis.gui import * import numpy as np @qgsfunction(args='auto', group='Custom') def ...
eagleadmiral's user avatar
4 votes

Classifying in QGIS into arbitrary number of percentiles instead of quantiles, based on attribute field value

You can use the following expression to categorize your field values into any arbitrary number of percentile (n-tiles, so to say), like e.g. into 7 categories: when you have 140 features, the 20 ...
Babel's user avatar
  • 67.2k
1 vote

Showing attribute field of date type with years in four digits in QGIS

Explanation: First, let me clarify the meaning of the code in the brackets (de_CH): This code refers to Unicode (ICU) Locale Formats, a database that stores local information such as date format, ...
eagleadmiral's user avatar
6 votes

Labeling count points within dissolved buffers in QGIS

This isn't a complete answer but might provide you or others some ideas to combine with other suggestions. Considerations: Assumes you are OK with clustering algorithm approach (not necessarily same ...
she_weeds's user avatar
  • 10.8k
1 vote
Accepted

Showing attribute field of date type with years in four digits in QGIS

Under Layer Properties -> Attributes Form You can select the field and control the Widget that it uses to display that field. In the case of Date fields, this includes controlling the format. I'm ...
Tom Brennan's user avatar
  • 3,715
6 votes
Accepted

QGIS Aggregate expression Function with GroupBy argument

Use this expression: with_variable( 'sedid', sed_id, array_sum( array_agg( sum_in_kW, group_by:=group, filter:=sed_id<=@sedid ) ...
Babel's user avatar
  • 67.2k
3 votes

Labeling count points within dissolved buffers in QGIS

If you want indeed to create one label per buffer, it is easier to indeed create dissolved buffers with the box Keep disjoint features separate checked to get one separate feature per "cluster&...
Babel's user avatar
  • 67.2k
6 votes
Accepted

Labeling count points within dissolved buffers in QGIS

What is a bit tricky: expressions work on a per-feature basis, so there is no direct way to only label the dissolved buffer (and any indirect way would be too complicated for the task, an overkill). ...
Babel's user avatar
  • 67.2k
7 votes

QGIS Aggregate expression Function with GroupBy argument

You can create a virtual layer that will compute this field. You can then export it to a new permanent layer if you wish to persist the result. Go to the menu Layer > Add Layer > Add/Edit ...
JGH's user avatar
  • 40.8k
3 votes

Test whether layer exists using expression in QGIS

If the problem is just the discrepance between @layer_id an the layer's name, you can use operator ~ to perform a regular expression match: @layer_id ~ 'point' Or, if it is not just the current layer,...
Babel's user avatar
  • 67.2k
3 votes
Accepted

Test whether layer exists using expression in QGIS

You can use function try() together with any other function that uses a layer's name as argument (e.g. overlay_nearest()): if the layer is not found, the function returns an error. try() returns if ...
Babel's user avatar
  • 67.2k
3 votes

Test whether layer exists using expression in QGIS

You can use is_layer_visible, it should return false if the layer is not visible or if there is no such layer in the project. Example: is_layer_visible('road') add that as the condition in your CASE ...
Dror Bogin's user avatar
  • 3,380
3 votes

Test whether layer exists using expression in QGIS

Create an array of all layer names in a project with variable @layers() (all the map layers in the current project as a list) and function layer_property(), then test if a certain layer name (here: '...
Babel's user avatar
  • 67.2k
0 votes

QGIS Map Atlas Expression - How to refer to atlas_pagenumber in an expression for elevation symbology

What you want is @atlas_featurenumber. It is accessible whenever the atlas is active. The @atlas_pagename is the name generated by the Page name expression in the atlas-tab of the print-layout. Note: ...
peter's user avatar
  • 765
7 votes
Accepted

Is there a way, in QGIS, with an expression, to convert a color to hexadecimal value?

There is no direct function to convert from decimal to hex using QGIS expressions afaik. But using some math, you can create an expression that does the job. The following expression works for numbers ...
Babel's user avatar
  • 67.2k
1 vote
Accepted

Selecting multiple points from an attribute table in QGIS, based on uncategorized field value

Best way to use Select by expression to select, based on an arbitrary array of numbers from the attribute field foto, is to use this expression: "foto" in (84,46,78,97,18) You can't ...
Babel's user avatar
  • 67.2k
0 votes

Selecting multiple points from an attribute table in QGIS, based on uncategorized field value

If you hace already selected your desired objects, you can use the Extract by expression tool. Simply check the Selected objects checkbox and put a 1 in the Expression box.
jpinilla's user avatar
  • 3,180
6 votes

Capturing all matches (occurences) with QGIS regular expressions

Unfortunately there is a bug(?) in regexp_matches() function. It returns only first occurence of provided pattern. regexp_matches( 'QGIS is the best GIS solution in the universe!', '(s.)') returns ...
rychlik's user avatar
  • 219
7 votes
Accepted

Capturing all matches (occurences) with QGIS regular expressions

I believe the global matching flag is not (yet) supported, but there is a workaround. regexp_replace comes to the rescue as it will replace any occurrence of the pattern. The key trick is that ...
JGH's user avatar
  • 40.8k
2 votes
Accepted

Find angle of segment of line geometry nearest to point

If you specifically do not want to use line_locate_point and line_interpolate_angle, you can do it like so: First create an array of the segments as geometries. The distance from each segment to your ...
Matt's user avatar
  • 14.7k
1 vote
Accepted

How to extract polygon attribute based on point location using QGIS expressions

Solved it using the following: aggregate( layer:='CDD', aggregate:='max', expression:="Value", filter:=contains($geometry, geometry(get_feature('Site Location', 'fid', 1))) )
davehughes87's user avatar
2 votes

Formatting string with QGIS Expression builder: separate groups of fours digits with hyphens

For splitting inputs with fixed length (here: 12 characters), use this expression ("input_text" is the name of the field containing the string you want to format): array_to_string ( ...
Babel's user avatar
  • 67.2k
3 votes

Formatting string with QGIS Expression builder: separate groups of fours digits with hyphens

You are incorrectly using double quotes instead of single quotes for string literals. Please read the QGIS user manual about writing expressions https://docs.qgis.org/3.28/en/docs/user_manual/...
Andrea Giudiceandrea's user avatar
4 votes

Formatting string with QGIS Expression builder: separate groups of fours digits with hyphens

This expression here splits any string you insert in line 3 in groups of 4, connected with hyphen -. In line 3, you can also use a fieldname instead to convert the string in this input field: ...
Babel's user avatar
  • 67.2k
0 votes
Accepted

Dynamically filtering feature count in QGIS Atlas, Legend

Use the following expression. Delete your expression from the header, but insert it directly to the legend of the categorised entries if you want to create the number of feautures dynamically in the ...
Babel's user avatar
  • 67.2k
3 votes
Accepted

QGIS expressions: creating an array based on integer fields returns 0 for field value NULL

For some reason, a explicit cast to the desired type is needed to avoid the conversion: array(to_int("no"), to_string("txt")) I don't know if the implicit cast is being performed ...
Gabriel De Luca's user avatar
1 vote

Moving substring from end to beginning of string in QGIS Attribute table

Another option: Use regular expressions to look for the space between 1) the weekdays part and 2) the time range part. Then split up the string at this position. Use this expression (see below for ...
Babel's user avatar
  • 67.2k
1 vote

QGIS field calcuator expression distance between centroid and point feature of another layer

You need to operate on layer where you will want to have the results. In your case layer 1. You will use the functions distance, closest_point, get_feature_by_id, array_to_string, overlay_nearest. ...
Mauro_F's user avatar
  • 33
1 vote

Moving substring from end to beginning of string in QGIS Attribute table

Solution: Regular expressions Use twice regexp_matches(), once to get the time range part, the second time to get the weekdays part, then concatenate them (replace timestring with your input fieldname)...
Babel's user avatar
  • 67.2k
4 votes

QGIS expressions: creating an array based on integer fields returns 0 for field value NULL

It seem that java and PHP (and maybe other langage as well…) revert to 0 for null integer value as the default behavior in array. QGIS likely do the same. To bypass this default behavior you have to ...
J.R's user avatar
  • 15.3k
4 votes
Accepted

Creating a concatenated field with conditions, changing a numeric field to 4 digits

Simply use lpad() function to change COND field value to 4 digits/characters (using 0 as fill character to the left) and use pipes operator || to concatenate: ID || lpad (COND,4,0) || CDC1 || CDC2 If ...
Babel's user avatar
  • 67.2k
3 votes

Creating a concatenated field with conditions, changing a numeric field to 4 digits

Update your field CONCATENATE via Field Calculator with: CASE WHEN length("COND")=1 THEN "ID" || '000'|| "COND" ||"CDC1"|| "CDC2" WHEN length(...
sn1ks's user avatar
  • 2,862
2 votes

Animating travelled path in QGIS without temporal information and temporal controller

A great possibility to create animations in newer QGIS versions (since 3.26) without any temporal information is using the new „Animation Settings“ option in the symbol widget’s Advanced menu: To ...
Babel's user avatar
  • 67.2k
4 votes
Accepted

Updating filter expression or filter value from one layer to another layer in QGIS

As you mentioned, you want the second layer to be a copy of the first one, with another style, but the same Provider Feature Filter. I don't think you can access fields from another layer there, but ...
Babel's user avatar
  • 67.2k

Top 50 recent answers are included