[Qgis-user] QGIS custom python function with zero or more args

Frank Broniewski hallo at frankbroniewski.com
Fri Mar 9 02:25:28 PST 2018


Hi Benjamin,

I don't have a recipe for no argument, but you can pass an empty string as a workaround:

@qgsfunction(args="auto", group="Custom")
def myfunc(value, feature, parent):
	if not value:
		value = "Wert"
	return value

Dipl. Geogr. Frank Broniewski
Waldhölzbacher Str. 51
66679 Losheim am See
06872 509 068 4
0176 611 26 9 2 6
www.frankbroniewski.com

-----Ursprüngliche Nachricht-----
Von: Qgis-user <qgis-user-bounces at lists.osgeo.org> Im Auftrag von Fuenfer-Koenigstein.Benjamin2 at swm.de
Gesendet: Freitag, 9. März 2018 09:19
An: Qgis-user at lists.osgeo.org
Betreff: [Qgis-user] QGIS custom python function with zero or more args

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
Qgis-user at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


More information about the Qgis-user mailing list