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

2018-03-09 Thread Fuenfer-Koenigstein.Benjamin2
Hi Frank,

thanks for your answer! Yes looks like there is no other way but passing empty 
strings. That’s what I wanted to avoid but anyway.

Regards
Benjamin



-Ursprüngliche Nachricht-
Von: Frank Broniewski [mailto:ha...@frankbroniewski.com] 
Gesendet: Freitag, 9. März 2018 11:25
An: Fuenfer-Koenigstein.Benjamin extern IT-LN; Qgis-user@lists.osgeo.org
Betreff: AW: QGIS custom python function with zero or more args

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-boun...@lists.osgeo.org> Im Auftrag von 
fuenfer-koenigstein.benjam...@swm.de
Gesendet: Freitag, 9. März 2018 09:19
An: Qgis-user@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@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

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

2018-03-09 Thread Frank Broniewski
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-boun...@lists.osgeo.org> Im Auftrag von 
fuenfer-koenigstein.benjam...@swm.de
Gesendet: Freitag, 9. März 2018 09:19
An: Qgis-user@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@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

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

2018-03-09 Thread Stefan Giese (WhereGroup)

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

stefan.gi...@wheregroup.com
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 fuenfer-koenigstein.benjam...@swm.de:

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

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

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

2018-03-09 Thread Fuenfer-Koenigstein.Benjamin2
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@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user