Hi Benjamin,
you can do it like this example which only makes a sum of 2 values. Two
aruments or only one...:
----------------------
@qgsfunction(-1, 'Python')
def add_values( values, feature, parent):
if len(values) == 2:
return values[0]+values[1]
elif len(values) == 1:
return values[0]+5
------------------------
@qgsfunction(-1, 'Python') says that you will pass a list of arguments
and the function will be in the Python rider.
In the code, you can check the number of arguments with getting the
length of the list, and then use your default values...
hope this helps
stefan
---
Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant
***********************************
Treffen Sie uns auf der
FOSSGIS Konferenz 2018
21.-24. März 2018 in Bonn
https://fossgis-konferenz.de/2018/
***********************************
WhereGroup GmbH & Co. KG
Schwimmbadstr. 2
79100 Freiburg
Germany
Fon: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11
[email protected]
www.wheregroup.com
Amtsgericht Bonn, HRA 6788
-------------------------------
Komplementärin:
WhereGroup Verwaltungs GmbH
vertreten durch:
Olaf Knopp, Peter Stamm
-------------------------------
Am 2018-03-09 09:18, schrieb [email protected]:
Hi all,
I would like to write a custom python function for QGIS 2.18 that
takes zero or one argument. The reason is that in most cases I can use
a default value in the function, in some cases I would like to enter
the value as argument. For python I know that you can prefix args in
functions to make them optional, e.g. def func(*arg). For QGIS
functions this will not work because there always have to be the args
feature and parent in last two positions. Has anyone experience with
QGIS functions that take zero or more arguments? Thanks for any help!
Regards
Benjamin
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user