test.py
1 |
from qgis.core import * |
---|---|
2 |
from qgis.gui import * |
3 |
from qgis.utils import * |
4 |
|
5 |
"""
|
6 |
fun1() works. All features are selected.
|
7 |
Usage: fun1(1)
|
8 |
"""
|
9 |
@qgsfunction(args='auto', group='Custom') |
10 |
def fun1(value1, feature, parent): |
11 |
return value1
|
12 |
|
13 |
"""
|
14 |
fun2() works. All features are selected.
|
15 |
Usage: fun2(2)
|
16 |
"""
|
17 |
@qgsfunction(args='auto', group='Custom') |
18 |
def fun2(value1, feature, parent): |
19 |
return value1 + 45 |
20 |
|
21 |
"""
|
22 |
No features are selected on executing fun3().
|
23 |
Usage: fun3()
|
24 |
"""
|
25 |
@qgsfunction(args=0, group='Custom') |
26 |
def fun3(value1, feature, parent): |
27 |
if feature['osm_id']: |
28 |
return True |
29 |
else:
|
30 |
return False |
31 |
|
32 |
"""
|
33 |
fun4() is a workaround I tried to select features.
|
34 |
It is slow and not a good solution to the problem.
|
35 |
Usage: fun4()
|
36 |
"""
|
37 |
@qgsfunction(args=0, group='Custom') |
38 |
def fun4(value1, feature, parent): |
39 |
layer=iface.activeLayer() |
40 |
iter=layer.getFeatures() |
41 |
for feature in iter: |
42 |
return feature['osm_id'] |