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.
94
questions
1
vote
0
answers
38
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 ...
1
vote
0
answers
60
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 ...
1
vote
0
answers
28
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 ...
8
votes
1
answer
117
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 ...
3
votes
1
answer
47
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 ...
0
votes
0
answers
136
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 ...
3
votes
1
answer
58
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 ...
1
vote
0
answers
64
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 ...
1
vote
0
answers
46
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 ...
5
votes
1
answer
155
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 ...
5
votes
1
answer
370
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, ...
0
votes
1
answer
95
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 ...
1
vote
1
answer
69
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 ...
1
vote
0
answers
83
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 ...
2
votes
0
answers
81
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 ...
2
votes
1
answer
475
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&...
4
votes
0
answers
173
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=...
2
votes
1
answer
92
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 ...
7
votes
1
answer
428
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'...
4
votes
2
answers
154
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 ...
1
vote
0
answers
420
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 ...
1
vote
2
answers
62
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) )...
0
votes
2
answers
809
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 -> ...
0
votes
1
answer
207
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 ...
6
votes
1
answer
272
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....
4
votes
2
answers
956
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 ...
-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 ...
1
vote
0
answers
76
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 ...
5
votes
0
answers
148
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) ...
14
votes
3
answers
791
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 / ...
2
votes
1
answer
390
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 ...
3
votes
1
answer
226
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(...
6
votes
1
answer
680
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/...
1
vote
2
answers
546
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 ...
3
votes
1
answer
199
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 ...
4
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, ...
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 ...
2
votes
0
answers
123
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=...
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 ...
2
votes
0
answers
198
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 ...
8
votes
1
answer
930
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 ...
2
votes
1
answer
297
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='...
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 ...
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/...
12
votes
2
answers
970
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 ...
4
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 ...
5
votes
1
answer
509
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 ...
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, ...
2
votes
1
answer
901
views
Calling QGIS functions via Function Editor?
I am trying to write function in QGIS via function editor and the problem is to call QGIS built-in functions e.g. azimuth, centroid... etc. When I run my script, I get
'global name 'azimuth' is not ...
5
votes
1
answer
187
views
Documenting custom Python functions in QGIS using styles?
This question shows how to document a custom function. However, I'd like to document my function in the same way the rest of the functions are.
So far, I just can manage to create the highlited part ...