Bug report #18286

cannot filter by $geometry, $length, $area etc.

Added by Mattias Spangmyr about 6 years ago. Updated over 5 years ago.

Status:Closed
Priority:High
Assignee:Hugo Mercier
Category:Attribute table
Affected QGIS version:3.3(master) Regression?:Yes
Operating System: Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:26177

Description

The "Advanced Filter (Expression)" function of the Attribute Table does not seem to be able to filter by comparing the current feature's geometry ($geometry) to NULL.

Applying either of the following expressions filters nothing:
  • $geometry IS NULL
  • $geometry IS NOT NULL

Both of the above expressions work when using "Select features using an expression", so its still possible to find null geometries that way.

test.zip - Simple polygons where one is missing its geometry (1.47 KB) Mattias Spangmyr, 2018-03-01 11:45 AM

atr_bug.jpg (101 KB) Tudor Bărăscu, 2018-10-22 09:25 AM

Associated revisions

Revision d9a10280
Added by Hugo Mercier over 5 years ago

Attribute table filter: force geometry extraction when needed

Fixes #18286

History

#1 Updated by Giovanni Manghi about 6 years ago

  • Status changed from Open to Feedback

What about QGIS 3?

#2 Updated by Mattias Spangmyr about 6 years ago

  • Status changed from Feedback to Open

Giovanni Manghi wrote:

What about QGIS 3?

I tested in QGIS 3.0.0 just now and the behaviour is exactly the same as far as I can see. However, I need to revise my description as the expression "$geometry IS NOT NULL" actually does filter, only it does not show any features either with or without geometry.

My version (on Win 7 64-bit):

QGIS version              3.0.0-Girona     QGIS code revision       001c80b0c3
Compiled against Qt       5.9.2            Running against Qt       5.9.2
Compiled against GDAL/OGR 2.2.3            Running against GDAL/OGR 2.2.3
Compiled against GEOS     3.5.0-CAPI-1.9.0 Running against GEOS     3.5.0-CAPI-1.9.0 r4084
PostgreSQL Client Version 9.2.4            SpatiaLite Version       4.3.0
QWT Version               6.1.3            QScintilla2 Version      2.10.1
PROJ.4 Version            493

#3 Updated by Giovanni Manghi about 6 years ago

  • Subject changed from Advanced Filter (Expression) unable to filter by $geometry IS NULL to Advanced Filter (Expression) in attribute table unable to filter by $geometry IS NULL
  • Affected QGIS version changed from 2.18.16 to 3.0.0
  • Operating System deleted (Windows 7)

#4 Updated by Tudor Bărăscu over 5 years ago

Just filling out a bug report when I noticed this one.
Filtering a line or polygon layer by $length or $area doesn't work:

Steps to reproduce:

- Open attribute table
- Select Advanced Filter (Expression)
- Create a simple expression: length bigger than 10 meters (for my case): $length > 10
- I noticed that in the Output preview window I get 0 or 1 (True or False) but in the attribute table all the rows dissapear (making the expression $length <= 10 does the same)

Tested on QGIS Master (3.3) and 2.18

@Giovanni Maybe the issue name should be changed to "cannot filter by $geometry, $length, $area etc.

#5 Updated by Giovanni Manghi over 5 years ago

  • Subject changed from Advanced Filter (Expression) in attribute table unable to filter by $geometry IS NULL to cannot filter by $geometry, $length, $area etc.
  • Affected QGIS version changed from 3.0.0 to 3.3(master)

#6 Updated by Tudor Bărăscu over 5 years ago

@Giovanni I think this issue should have a High priority as I discovered more problems (consequences) tied to it.
For example, any form constraints that use the geometry in any way work well in feature forms but are not working as expected in the attribute table.

I've attached a screenshot.
For the same feature, the "single" form passes the constraints whereas the same form in the attribute table doesn't so the editors are not guided well from the attribute table.

#7 Updated by Giovanni Manghi over 5 years ago

  • Regression? changed from No to Yes
  • Priority changed from Normal to High

Tudor Bărăscu wrote:

@Giovanni I think this issue should have a High priority as I discovered more problems (consequences) tied to it.
For example, any form constraints that use the geometry in any way work well in feature forms but are not working as expected in the attribute table.

I assume this is a regression(?).

#8 Updated by Hugo Mercier over 5 years ago

  • Assignee set to Hugo Mercier

Confirmed.

When tested with a shapefile, "$" fields do not work. However, when trying with a memory layer it works.

#9 Updated by Nyall Dawson over 5 years ago

This is because attribute table doesn't fetch geometries (for performance reasons).

#10 Updated by Hugo Mercier over 5 years ago

Hmmm, apparently the filter can fetch geometries when needed (this is what I observe with memory layers)

https://github.com/qgis/QGIS/blob/master/src/app/qgsattributetabledialog.cpp#L1106

#11 Updated by Hugo Mercier over 5 years ago

  • Pull Request or Patch supplied changed from No to Yes
  • Status changed from Open to In Progress

#12 Updated by Hugo Mercier over 5 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF