qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.53k stars 2.99k forks source link

Relation reference filter expression not able to access the parent geometry #44499

Open garci66 opened 3 years ago

garci66 commented 3 years ago

What is the bug or the crash?

When trying to use a reference relation filter expression, the filter fails (nothing is returned) if trying to use the @current_geometry, @current_parent_geometry, @current_feature or @current_parent_feature objects.

In particular, the objective was to have the reference relation only show objects from other layers overlapping/intersecting the currently-being-edited feature.

trying any of the following filter expressions always returns an empty filter-set:

intersects($geometry,geometry( @current_parent_feature ))
intersects($geometry , @current_parent_geometry )
intersects($geometry,geometry(@parent))
intersects($geometry,@current_geometry)

Additionaly, purely for testing, I've used a test filter expression such as the following: floor($x)%2=0 and I see that the FILTERED object's geometry can be accessed. It seems that the parent's geometry or the "current_geometry" is unaccessible for the proper evaluation of the filter.

if using the "default value" setting and using an expression such as overlay_intersects('poste',"fid")[0] (where poste is the "related" layer), works fine but I haven't found a way to filter the list by any form of geometry relation between the filtered feature and the currently-being-edited feature.

This happens both on new features (yet unsaved) and also upon editing existing features.

If using the value relation widget instead of the reference relation it works but I was trying to use the mapping / graphical capabilities of the reference relation widget.

Looking at the commit that added the original "relation reference widget" https://github.com/qgis/QGIS/commit/a853f2643df7d35f0980e8f92acb688fe3f15344 it seems that the code is adding highlights on the expression builder for the current_geometry, current_parent_geometry, etc variable. See:

https://github.com/qgis/QGIS/blob/0283cb6b4f47ce87ac60a2cd08fc04f37e492e00/src/gui/editorwidgets/qgsrelationreferenceconfigdlg.cpp#L85-L90

which would hint as those variables being usable.

Steps to reproduce the issue

  1. Create two layers (for example for point features) posts and boxes, both with a fid and name field
  2. Create a relation between the layers, where the boxes layer has a post_fk field that points to a specific post's fid
  3. Populate the posts layer with a few posts on the map (simple point features with a name)
  4. On the layer properties for the boxes layer, go the the form editor, using the default auto-built form. The post_fk field should automatically be set as a "reference relation" type widget. In this widget, set the filter to the following expression:

Either:

  1. using snapping, create a boxes feature overlapping a posts feature. The post_fk dropdown will be completely empty (meaning the filter returned false for all evaluation)
  2. As a work around, if using the "default value" setting configured to the following expression: overlay_intersects('posts',"fid")[0], a value (a post fid) will be returned. But the expression filter could allow to do things like intersects($geometry,buffer(@current_geometry),20) for example to get all nearby objects.

Versions

QGIS version 3.16.6-Hannover QGIS code revision bfd36fddc9 Compiled against Qt 5.11.2 Running against Qt 5.11.2 Compiled against GDAL/OGR 3.1.4 Running against GDAL/OGR 3.1.4 Compiled against GEOS 3.8.1-CAPI-1.13.3 Running against GEOS 3.8.1-CAPI-1.13.3 Compiled against SQLite 3.29.0 Running against SQLite 3.29.0 PostgreSQL Client Version 11.5 SpatiaLite Version 4.3.0 QWT Version 6.1.3 QScintilla2 Version 2.10.8 Compiled against PROJ 6.3.2 Running against PROJ Rel. 6.3.2, May 1st, 2020 OS Version Windows 10 (10.0) Active python plugins networks; openlayers_plugin; QuickOSM; db_manager; MetaSearch; processing

Also tested on 3.16.3 and 3.20.0

Additional context

No response

dd-a commented 1 year ago

Hi, Any news/update for this bug ? I just tested with QGIS 3.30.2 and it still doesn't work :-(