Skip to main content

Questions tagged [qgis-custom-function]

Use this tag for topics related to custom functions, which are user-defined expression functions usable from the Field Calculator in QGIS.

Filter by
Sorted by
Tagged with
3 votes
1 answer
423 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,199
0 votes
0 answers
26 views

QGIS Custom function for report names

When working with regular layouts the @layout_name is available to use the layout name within the layout. For reports @layout_name does not work. Can the layout name be made available using a custom ...
Sethinacan's user avatar
  • 1,726
1 vote
0 answers
40 views

Representing buffer (e.g., +/-10%) around object and displaying predefined "straight" scale in object's representation

I am working on a mapping project in QGIS with the Atlas feature, and I'm facing a specific challenge. I need to generate map representations of individual features in a way that includes a dynamic ...
eagleadmiral's user avatar
1 vote
0 answers
119 views

Highlighting local maxima of an attribute in a layer in QGIS

I have two layers from the same track measured at a different time, and would like to highlight where they have moved the most. I can use closet point function to work out regular separations along ...
Campbell Smith's user avatar
1 vote
0 answers
43 views

Othogonal Dimensions in QGIS

I wonder if there is a solution for Orthogonal Dimensions in QGIS. At the moment i have to export my projects to AutoCAD and make the dimensioning process there. As i could fully change my workflow to ...
Toby's user avatar
  • 135
9 votes
1 answer
190 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,524
3 votes
1 answer
54 views

QGIS Extract by Expression - Only subgroups w/ time duration between consecutive observations < 4h

I have several point layers with the attributes CLUSTER_ID (groups points in different clusters by unique ID) and datetime_lcl (timestamps). In each layer, I'd like to extract only the clusters in ...
Barbara Perez de Araújo's user avatar
0 votes
0 answers
169 views

Python code location for QGIS functions

Is the Python Code accessible for QGIS function definitions? My knowledge of Python is limited but I have had success tweaking code in Ruby. So I am willing to give it a try but would like to see the ...
Mike's user avatar
  • 91
3 votes
1 answer
72 views

Select text field associated with maximum numeric field during QGIS aggregate process

I have a site layer and a grid layer and want to add attributes to the site layer which include a new area (the intersection) and the grid reference (a text field) associated with the maximum ...
benj's user avatar
  • 145
1 vote
0 answers
115 views

QGIS: Hashed lined - advanced symbology and styling. 90*degree cornering and flexible widths

TL;DR: How do i set up a symbology with hashed lines, that is not turning fluently around corners, but turns sharply at a 90 degree angle and stops overlapping. The corners are for all purposes close ...
Kristoffer Grandjean's user avatar
1 vote
0 answers
52 views

QGIS 3.22 Labeling Previews show expected result, but is not shown on canvas

I created a function to label rasters whose boundaries are the same but represent different features. To do so, I have a set of rasters and a point vector layer with one field representing each of ...
Rafael Pinheiro Machado's user avatar
5 votes
1 answer
187 views

Avoiding eval() function when using custom function

CONTEXT I have several raster layers which overlap. I created a point layer with labels that represent different values for each of these raster layers. I created a function that lists all layer ...
Rafael Pinheiro Machado's user avatar
5 votes
1 answer
654 views

Getting color of feature using PyQGIS

QGIS offers the @symbol_color-variable in some places. But it is missing at various places of data-defined-override/field-calculator dialogues. I tried to create a own function, but it returns wrong, ...
user191847's user avatar
0 votes
1 answer
128 views

QGIS Custom variable or Function to extract image "compass direction" from image url/path

I would like to create custom variable or a custom function to extract only "EXIF Camera Direction" of image from URL/path (field) of JPG images into QGIS. So i can directly write the ...
Grevardo Laheba's user avatar
1 vote
1 answer
76 views

I want to slightly randomise the values of integers within an atribute in QGIS

I have a map with height data, but the height data is not very fine and detailed and the map is quite large. For my purposes, which is fantasy cartography, I can simply randomize data a little. My ...
Meep the Changeling's user avatar
1 vote
0 answers
97 views

Spatial sorting using Hilbert Curve in custom function in QGIS results in unpacking error

I am trying to implement spatial sorting using a Hilbert Curve. I have taken the code for calculating the Hilbert Curve distance from https://en.wikipedia.org/wiki/Hilbert_curve and converted it to a ...
George of all trades's user avatar
2 votes
0 answers
93 views

generate sequential value across multiple layers in QGIS

Running QGIS 3.16, relative beginner in q I am trying to make an auto-generated id number that: is a sequential integer, starting at 1 can be used in 2 or more different layers without duplication Is ...
Swordnut's user avatar
2 votes
1 answer
638 views

QGIS: how to convert html formatted text in attribute table?

In my attribute table there's a lot of html formatted text. Is there a quick way to convert that html to 'normal' UTF-8 text other than using replace() for every html special character? replace('<p&...
maxwhere's user avatar
  • 1,158
4 votes
0 answers
193 views

Defining a custom Python Expression function with default parameters

Is it possible to use a variable with default value (value2) defined in a custom Python expression function? @qgsfunction(args='auto', group='UserFunction') def my_test(value1, feature, parent, value2=...
NEM's user avatar
  • 91
2 votes
1 answer
124 views

Creating custom function Left()

I have data originating from a central registry for drilling wells. Each well may have a date attached to it and I want to create a layer which differentiates wells drilled by a certain year. Problem ...
Erik's user avatar
  • 23
7 votes
1 answer
489 views

Writing custom QGIS function that works without a feature given as input

Lets say I have created a custom QGIS function, like for example from qgis.core import * from qgis.gui import * import urllib.request import urllib import json @qgsfunction(args='auto', group='Custom'...
MrXsquared's user avatar
  • 34.9k
4 votes
2 answers
176 views

Copying the standard HTML design of function descriptions in the Function editor

I am creating my own function in the function editor and want to copy the HTML design of the standard function description, but I can't find it anywhere. Where can I find it? UPDATE: I found a ...
Comrade Che's user avatar
  • 7,271
1 vote
0 answers
495 views

QGIS Vertex Tool not working on some layers

I am making a map in QGIS 3.16. I have made a custom function with the function editor. I have used the function in the styles of 5 layers of my map. When I start QGIS all layers load correctly with ...
Leif Birch's user avatar
1 vote
2 answers
71 views

Make custom function using dynamic variable

In the function editor, I am trying to make this function : @qgsfunction(args='auto', group='Custom') def size_reduction( x, feature, parent): s = @map_scale/1000/x y = if( s<1, s, 1+ln(s) )...
Leif Birch's user avatar
0 votes
2 answers
1k views

QGIS: Custom formatting coordinate grid to reduce number of decimals

I am making a coordinate grid system of a map I have made, but now I would like to reduce the number of decimals of the seconds (of the latitude and longitude). So instead of 36°54'0.000"E -> ...
user178341's user avatar
0 votes
1 answer
252 views

QGIS custom Python expressions not loading on startup

My custom Python expressions are not loading at startup and I dont know why. Its a real pain because I have virtual layers depending on those expressions, so after I load them I have to manually ...
Opazo's user avatar
  • 363
6 votes
1 answer
311 views

QGIS custom function error when trying to get color of feature on another layer

In QGIS 3.16.2 (same on 3.16.0) on Win 10, I created a custom function get_color to get a feature's color by layer name\id and feature ID as proposed in this answer by @Dror Bogin: https://gis....
Babel's user avatar
  • 73.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
-2 votes
1 answer
2k views

Enabling and disabling a QAction depending on feature selection

I made a button and wanted it to stay on only if iface.activeLayer() had some features selected; I saw that you can use the QAction.setEnabled(False) function. Example: #from PyQt5.QtCore import ...
Victor Ramos Pereira's user avatar
1 vote
0 answers
82 views

Creating custom function in QGIS with self intersects

I'm trying to create some customs functions in QGIS to automate some works I'm doing in my job. I have some experience using QGIS expression but I'm trying to create some custom functions now. I have ...
Eduardo Silva's user avatar
5 votes
0 answers
158 views

PyQGIS: What objects need to be destroyed in a custom expression

I'm using a custom (PyQGIS) function in expressions to make little detailed minimaps around each feature in a layer, and store it in the layer (gpkg) as a png. My code works but makes QGIS (3.12) ...
Houska's user avatar
  • 8,196
15 votes
3 answers
919 views

Providing QGIS expression within a plugin

I have written a custom function in the field calculator in QGIS. How do I distribute this function to other QGIS installations the best way? I can of course instruct the user what to type or copy / ...
MortenSickel's user avatar
  • 3,834
2 votes
1 answer
426 views

Replace Part of String with a different String in QGIS using Python [closed]

I am trying to fix a field that has Street Names. Some of the features' Street Names have abbreviation rather than the full name of the type of street like for example 'PRESTON LAKE DR' when it should ...
ar-siddiqui's user avatar
  • 1,768
3 votes
1 answer
231 views

Custom function in expression editor

I am trying to make a custom function in the QGIS expression editor that takes three arguments. Below is the tested standalone function, which I would like to integrate: import math def qfull_circle(...
Sebastian's user avatar
6 votes
1 answer
769 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/...
tomfumb's user avatar
  • 3,688
1 vote
2 answers
579 views

Calculate geographic location of point display offset in QGIS

I have a point layer in which some symbols are displayed offset from the feature's true location by a given number of millimetres. As the map's zoom changes the offset symbol's geographic location ...
tomfumb's user avatar
  • 3,688
3 votes
1 answer
207 views

Custom function works in "Zoom to Features" but not "Select Features"

I'm trying to update the Using Custom Functions tutorial to QGis 3 and Python 3 and I've run into an interesting issue. With the following code I can create an expression GetUtmZone()='33N' and it ...
Ian Turton's user avatar
  • 82.2k
5 votes
2 answers
1k views

How do I declare a QGIS custom expression function and use it in a single python script?

I would like to create and populate a virtual field in a QGIS vector layer attribute table using a python script. I think the easiest way to do this is to create a custom expression function, and, ...
Philip Whitten's user avatar
3 votes
2 answers
1k views

Why different results of mean calculations with focal in R and Esri ArcGis

I want to calculate the ratio of two different classes in a raster with a circular moving window. My classes are 0 and 1 (I do not want to include the NAs). The radius should be 5 meter. I thought my ...
Li12's user avatar
  • 307
2 votes
0 answers
126 views

Why python function not work in custom function in QGIS 3.2?

in QGIS atlas I use a custom function to find the first file containing texts : import os, fnmatch from PyQt5.QtCore import QFileInfo from qgis.core import * from qgis.gui import * @qgsfunction(args=...
vidarusny's user avatar
  • 305
7 votes
1 answer
2k views

Update/change/commit an attribute/a field value "on the fly" in QGIS 3

I'm using QGIS 3.2. I have 4 fields ("kk1"-"kk4") where at least one of the fields contains a number (real). I want to calculate the mean of these 1-4 fields and save the result (the average) in ...
9ls1's user avatar
  • 1,427
2 votes
0 answers
202 views

How to access clicked coordinates in a Custom Python Expression Function?

My final goal is to be able to digitize a point layer (create new point features) and to have as a default for one of the attributes an attribute from another layer that is at the same location. Up ...
Andrei's user avatar
  • 774
8 votes
1 answer
1k views

Styling shared boundaries in QGIS?

I have 2 polygon layers, 1 showing roads and another showing parking restrictions on those roads (no parking, residents only, etc). I'm trying to style the layer according to the markings that would ...
firefly-orange's user avatar
2 votes
1 answer
302 views

Adding new python expressions on QGIS?

I just tried creating the following function on the function editor on the select by expression from qgis.core import * from qgis.gui import * from qgis.utils import * @qgsfunction(args=0, group='...
Luffydude's user avatar
  • 2,328
3 votes
0 answers
295 views

Ordnance Survey grid reference in QGIS print composer [duplicate]

Is there a way of inserting Ordnance Survey grid reference in a print composer? I know that a grid can be created but I don't wish to insert a grid, I just to need to include the eastings and ...
user27726's user avatar
2 votes
2 answers
3k views

Import a custom function from the python console

I'm trying to import a custom function from the python console, but it return the error: 'QgsExpressionFunction' object is not callable My example function (saved as function.py file in /.qgis2/...
Domenico Fuoco's user avatar
12 votes
2 answers
998 views

Styling specific layer by using polygon mask in QGIS?

I have a line layer and a polygon layer in QGIS: I would like to style the part of the line layer outside the polygon using one style and the part inside using a different style: I don't want to ...
Chau's user avatar
  • 4,490
5 votes
3 answers
1k views

Using lookup from CSV in Field Calculator?

Is it possible to access a CSV in order to feed a certain value from the CSV into an attribute's field calculator expression? Ex.: CSV will be as such: ITEM COST FOOT 100 THING 200 My ...
Metalgearmaycry's user avatar
6 votes
1 answer
587 views

Is there a way to use windowing functions (lag, lead) within the QGIS Field Calculator?

I am keen to compute a windowing function on values in QGIS. I was not able to find a lag/lead function. I think this could be emulated using @rownumber and $currentfeature, but I am not expert in ...
MartinT's user avatar
  • 876
1 vote
2 answers
3k views

Non-ASCII characters not displaying correctly after Python manipulation

I'm using QGIS 2.18 on a Mac (Sierra). I'm doing some pretty extensive data manipulation using a virtual column, and using the function editor (so Python) to do so: one of my functions, for example, ...
Josef M. Schomburg's user avatar