Bug report #10900

python filter expression don't work on "value relation"

Added by Mathieu Bossaert about 5 years ago. Updated over 2 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Edit widget
Affected QGIS version:2.18.4 Regression?:Yes
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:worksforme
Crashes QGIS or corrupts data:No Copied to github as #:19265

Description

Good morning,

trying to filter the entries of a "Value relation" with the extent of the current map canvas, I get a empty list of values.

The same expression used to update a column of the table works fine...

Here is the expression I use :

  intersects(  $geometry ,  geomFromWKT( $current_canvas_extent ))

and here is the function providing $current_canvas_extent :

from qgis.utils import qgsfunction
from qgis.utils import iface

@qgsfunction(0, "Python")
def current_canvas_extent(values, feature, parent):
    """ 
       retourne l etendue courante de la carte
   """ 
    extend = iface.mapCanvas().extent().asWktPolygon() 
    return extend

It woks fine on 2.2

Thanks a lot,

Mathieu Bossaert


Related issues

Related to QGIS Application - Feature request #16040: Filter relation reference widget by expressions Open 2017-01-05

Associated revisions

Revision ae19eefb
Added by Matthias Kuhn about 5 years ago

Allow expressions with geometry on value relation widget
Fix #10900

History

#1 Updated by Giovanni Manghi about 5 years ago

  • Priority changed from Normal to Severe/Regression
  • Operating System deleted (Windows and Linux)
  • OS version deleted (Seven Pro)

#2 Updated by Matthias Kuhn about 5 years ago

  • Status changed from Open to Closed

#3 Updated by Matthias Kuhn about 5 years ago

  • Status changed from Closed to In Progress

Can you please check if this really fixes the issue.

#4 Updated by Matthias Kuhn about 5 years ago

  • Status changed from In Progress to Closed

#5 Updated by Mathieu Bossaert about 5 years ago

Hi Matthias,

It works fine on QGis Master. Thanks a lot.

Matthias Kuhn wrote:

Can you please check if this really fixes the issue.

#6 Updated by Giovanni Manghi about 5 years ago

  • Resolution set to fixed/implemented

#7 Updated by Mathieu Bossaert over 2 years ago

  • Target version set to Version 2.16
  • Status changed from Closed to Reopened

Good evening,

time have passed, and this worked well until QGIS 2.14.
Since 2.16, same bug appears, expression value is ok but the list stay empty.

Maybe you would have prefer that I opened a new ticket ?

Thanks a lot for your your help and the work you do on our prefered GIS tool !

#8 Updated by Giovanni Manghi over 2 years ago

  • Target version changed from Version 2.16 to Version 2.18
  • Resolution deleted (fixed/implemented)
  • Affected QGIS version changed from 2.4.0 to 2.18.4

Unless I'm doing something wrong it seems to me that 2.18.4 is still affected.

#9 Updated by Giovanni Manghi over 2 years ago

  • Regression? set to Yes

#10 Updated by Giovanni Manghi over 2 years ago

  • Priority changed from Severe/Regression to High

#11 Updated by Giovanni Manghi over 2 years ago

  • Easy fix? set to No

#12 Updated by Matthias Kuhn over 2 years ago

  • Resolution set to worksforme
  • Description updated (diff)
  • Status changed from Reopened to Closed

$current_canvas_extent

needs to be replaced with

current_canvas_extent()

(it's a function, not a special column)

Works perfectly fine for me like this on 2.18.

You might also be interested in reading this recent blog posts about needsGeometry and referencedColumns ;)

http://www.opengis.ch/2017/05/10/best-practices-for-writing-python-qgis-expression-functions/

Also available in: Atom PDF