Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature selection using custom python expression functions #24333

Closed
qgib opened this issue Apr 7, 2017 · 2 comments
Closed

Feature selection using custom python expression functions #24333

qgib opened this issue Apr 7, 2017 · 2 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions

Comments

@qgib
Copy link
Contributor

qgib commented Apr 7, 2017

Author Name: Simran Khare (Simran Khare)
Original Redmine Issue: 16424
Affected QGIS version: 2.18.5
Redmine category:expressions


This is regarding selecting features by expression in QGIS 2.18.x. The selection does not seem to work when we try to access the feature attributes in our custom expression function.

For example, we would expect the following function to select all features with non-null osm_ids. Upon executing the function in the expression engine, the output preview is 'true', but no features are selected.

@qgsfunction(args=0, group='Custom')
def fun3(value1, feature, parent):
if feature['osm_id']:
return True
else:
return False

The above function works fine in QGIS 2.14.12, but not in 2.18.5.

Attached is the pbf file and some Python functions I tested with. Please add the point vector layer from 'tulersee.pbf' and call fun3() to reproduce the error.


@qgib
Copy link
Contributor Author

qgib commented Apr 30, 2017

Author Name: Giovanni Manghi (@gioman)


  • easy_fix was configured as 0
  • regression was configured as 0

@qgib
Copy link
Contributor Author

qgib commented May 2, 2017

Author Name: Simran Khare (Simran Khare)


This is not a bug, but a slight difference in custom python expression functions in QGIS 2.18.
In version 2.18, any feature attribute that we intend to use within the function must be passed as an argument to the function.

So, for example, a function that accesses the 'osm_id' field should be modified as follows and called as fun("osm_id"). In this case the features are selected.

@qgsfunction(args='auto', group='Custom')
def fun(field, feature, parent):

if feature['osm_id']:

return True
else:
return False

Thanks to this answer: https://gis.stackexchange.com/a/238226/94852


  • status_id was changed from Open to Closed

@qgib qgib closed this as completed May 2, 2017
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions
Projects
None yet
Development

No branches or pull requests

1 participant