Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
2answers
71 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
2answers
66 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 ...
1
vote
0answers
56 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=...
6
votes
1answer
198 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
0answers
63 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 ...
7
votes
1answer
232 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 ...
1
vote
1answer
141 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
0answers
171 views

Ordnance Survey grid reference in QGIS print composer

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
2answers
721 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/...
10
votes
2answers
348 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 ...
3
votes
1answer
163 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
1answer
138 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
2answers
638 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
1answer
233 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
1answer
92 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 ...
11
votes
3answers
767 views

Generating attributes in an automatic way with QGIS?

I want to autogenerate IDs while I create new features. So every time I create a new point, its ID will increase by 1 like the following: Feature 1: id 1 Feature 2: id 2 Feature 3: id 3 How can I ...
7
votes
2answers
345 views

QGIS Expression function

I would like to write a Python expression function which calculates the average of columns (variable length parameters), skipping NULL values. @qgsfunction(args=-1, group='Custom') def col_avg(vals, ...
1
vote
0answers
91 views

QGIS drag-and-drop forms: move cursor to other field without mouse

When I create a form by 'drag and drop' design, the only way to go to another field is by mouseclicking in that field. Is it possible to do the same action with the tab-button, as it does in an ...
5
votes
1answer
227 views

Getting the height and width of labels in QGIS?

Is there a way to get the height and width of labels in the field calculator? Perhaps with the help of the function editor? Units are in meters. See also: Creating leader lines for moved labels
9
votes
1answer
889 views

Shifting display of overlapping lines in QGIS?

When points are overlapping, there is this property which allow to automatically display the lot of them separately around where they are, called 'Point displacement'. But it doesn't work for lines, ...
2
votes
2answers
339 views

Feature Selection Using Custom Python Expression Functions in QGIS 2.18

I'd like to write an expression function in QGIS 2.18 to select features based on the value of their attributes. How can I access attribute values within my function? I have noticed that in QGIS 2....
2
votes
0answers
486 views

How to change attribute value in drop down list with constraint and/or Function Editor in QGIS?

I'm usig QGIS 2.18.6. UPDATE2: I've mangaged to get (assign/find) the actual widget (value Map) for my attribute (field) "ibruk" with calls from the python console in QGIS: >>>layer = qgis....
3
votes
1answer
114 views

Setting globals in PyQGIS?

I'm working on this script in PyQGIS to take points from a layer called LEK_ALL and snap them to the closest feature of a line layer called LEID_filtered which fulfills a certain request. In order to ...
2
votes
1answer
519 views

Get value of Variable in custom python expression function

I am writing a custom python expression function to return the value of a variable. By variable, I mean the layer, project, or global variables. I looked at this answer https://gis.stackexchange.com/a/...
5
votes
2answers
329 views

Increasing marker size based on number of points at same location in QGIS

I have a dataset that contains many points (representing specimens) with GPS locations taken at the same point. When I map these points as a vector layer, only the uppermost point shows - so, at one ...
3
votes
2answers
512 views

Using list of values for custom function in QGIS Field Calculator?

I'm writing a custom function in the Field Calculator (QGIS 2.18.5). Creating a new function from Function Editor > New file, I'm able to start using a default function called func: """ Define new ...
7
votes
2answers
549 views

If two symbols in same QGIS layer are too close, show only one?

I have a shapefile layer with different underwater, over water and water surface stones. These are often too close to each other to be shown nicely on the print composer generated map. I use svg ...
9
votes
1answer
168 views

Documenting custom Python functions in QGIS

How can I document my custom Python functions in QGIS? I would like to offer users help for functions I wrote for them: I've tried adding a docstring: But whenever I click Load an error message is ...
5
votes
1answer
301 views

Deleting custom functions in QGIS Field Calculator

Is there a way to delete custom functions (e.g. extractZipCode in the screenshot below) from the QGIS Field Calculator without having to look into the expressions folder on disc? I know I can simply ...
6
votes
2answers
376 views

Can't select using a custom function in QGIS 2.18.3

I'm following this tutorial on custom expressions and all goes well - my function shows up in the custom section and seems to work for the preview giving 21S for the first feature. When I extend the ...
3
votes
1answer
248 views

QGIS : how to do elegant multiple replace string?

In QGIS I need to do a string conversion, from serbian latin to serbian cyrilic. In field calculator, i have only this inelegant solution : replace(replace(replace(replace( etc... )))) It's long ...
3
votes
1answer
490 views

Identify duplicate attributes (followup)

I am processing a large map with several hundred thousand building polygons in QGIS 2.18. Unfortunately I had to puzzle this map together from several smaller and overlapping pieces and so quite a few ...
8
votes
3answers
428 views

Changing to alternate label if first label does not fit in QGIS?

I'm trying to create a map to print out and the size of my polygons varies greatly. As this will be a reference map I need to label every polygon, but some of the names will not fit in the polygon. In ...
9
votes
2answers
946 views

Splitting text from a string field before each delimiter to new fields

I'm trying to extract text data from a string field containing text delimited by dots and placing it in new fields using the field calculator. Im using this python function (Taken from How to extract ...
3
votes
0answers
123 views

Custom QGIS expression to filter atlas pages

I want to filter my atlas pages based on a list returned by a custom function but it won't work. This is my function: from qgis.core import * from qgis.gui import * from qgis.utils import * @...
1
vote
1answer
420 views

Geometry generator and calling an expression from a custom function

I am using geometry generator symbol layer type and some expressions that makes the result a line that is shorter then the original line. The expression works and looks like this: make_line(...
1
vote
1answer
237 views

Getting parent layer of feature in QGIS PyQGIS Custom Function?

I am writing a custom function in PyQGIS to use in expression editor: the aim of the function is to retrieve the first feature that contains the current feature from a polygon layer. def ...
10
votes
1answer
428 views

QGIS-Custom functions not showing in Field Calculator

I'm using Essen and trying to follow Anita Graser's wonderful tutorial Illuminated contours. I've created the azimuth function and loaded it but there is nothing showing in the expression tab - not ...
5
votes
1answer
775 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 ...
3
votes
2answers
223 views

Summarizing Fields based on content in QGIS?

already read many answers for similar questions, but i didnt find a solution for my problem. Dont know how to start. Problem: shp with about 50 fields. Each field contain NULL, 1 or 2. Now i need ...
1
vote
1answer
610 views

Custom Python Expression Functions (QGIS Tutorial)

I'm having trouble finishing the QGIS tutorial for Using Custom Python Expression Functions: http://www.qgistutorials.com/de/docs/custom_python_functions.html I get to the point where I write the ...
1
vote
0answers
105 views

Custom pyQGIS function returns NULL

I've made a python function that returns the user logged in a postgis layer: from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def getUser(lay, feature, parent)...
3
votes
1answer
324 views

QGIS right of string

I've been trying to use the Function Editor in QGIS to create a function to return the end of a string following some kind of delimiting character (as I can't find a right-sided equivalent to strpos), ...
3
votes
1answer
400 views

QGIS Calculate Field with Function Editor invalid expression

I have some data which is built like this: a,bbb,ccc where bbb and ccc vary in length. I want to extract the last segment of the string, after the second ",". Using the Function Editor: from qgis....
2
votes
0answers
532 views

Local variable 'value' referenced before assignment: qgis function editor

I customized a function to edit my attribute table. It was working well but now when I used it again my QGIS crash or I receive a bad answer. The answer of QGIS: My code: from qgis.core import * @...
7
votes
1answer
502 views

Register custom qgsfunction in pyqgis

I'm using pyqgis within an standalone application. Now I wanted to create a custom expression to to use as filterExpression in rule of ruleBasedRendererV2. (I tried the renderer with existing ...
1
vote
2answers
148 views

How to populate one column of a table by extracting the match of a Regular Expression?

I Have a CSV table where one of the columns has names of the post offices with the type given in brackets like this: Sri venkateswara puram (Sub Office) I want to extract the post office type, by ...
5
votes
1answer
737 views

Specifying input layer in custom QGIS function to rank features

How do I specify the input layer so it refers to the layer from which the function was called (without having to explicitly identify it by name)? I have written a custom function to use in the ...
6
votes
1answer
165 views

Why do I need to use labelling when setting fill colour with a python expression in QGIS?

I'm having problems using a Python function in the expression editor to style a polygon fill in QGIS. I'm trying to use a random colour scheme. However, I need to do this over a series of different ...
2
votes
1answer
113 views

Function editor can i use string-operators

In the Function editor I'm trying to edit a string something like: from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def testfunc2(value1, value2, feature, ...