[QGIS-Developer] QgsFeatureRequest spatial filter reprojection

Sandro Santilli strk at kbt.io
Tue Oct 26 00:11:04 PDT 2021


Update on the issue: I've brought PR
https://github.com/qgis/QGIS/pull/45384
to a state in which it passes CI.

What I did was adding an updateRequestToSourceCrs method to
the QgsAbstractFeatureIterator class to replace the currently used
filterRectToSourceCrs method which does a partial job
in reprojection and makes the callers too easily change
the QgsFeatureRequest's spatial filter.

I had QgsVectorLayerFeatureIterator make use of this new method
to avoids changing the QgsFeatureRequest spatial filter.

The change proves to fix the bug, which is now guarded by a testcase.

Could anyone please take a look at the PR to finally merge it ?

NOTE: I've also opend another PR which contains less changes
(the initial one also adds some utility equality/inequality operators
to base classes and some more unit tests for them). The second PR
could be discarded if the first one is merged, but might be easier
to review.

--strk;


On Wed, Oct 20, 2021 at 12:01:19PM +0200, Sandro Santilli wrote:
> I've finally found the bug I've been chasing for two weeks now [1]
> 
> What's happening is that a QgsFeatureRequest object initialized
> with a DistanceWithin spatial filter, switches to a Rectangle spatial
> filter when used to construct a QgsVectorLayerFeatureIterator.
> 
> This is because QgsVectorLayerFeatureIterator constructor tries to
> reproject the QgsFeatureRequest's rectangle filter from destination
> CRS to source CRS, probably aiming at improving performance from
> vector layers which may have indices.
> 
> Such attempt to reproject is done using methods of QgsFeatureRequest
> which *change* the spatial filter (setFilterRect).
> 
> Now I've a few questions:
> 
>   1. Shouldn't such optimizations be performed by each specific
>      provider's class rather than by the base class ?
>      (projecting the Request filters to the source CRS)
> 
>   2. Shall we see a need to reproject spatial filter references,
>      shouldn't this be done by a method of QgsFeatureRequest class
>      directly ? 
> 
> Note that QgsFeatureRequest doesn't ONLY possibly have a QgsRectangle
> as a reference, but could also have a QgsGeometry and a *distance*,
> "reprojecting" which is not really obvious...
> 
> 
> [1] https://github.com/qgis/QGIS/pull/45384
> 
> 
> --strk; 
> 
>   Libre GIS consultant/developer
>   https://strk.kbt.io/services.html


More information about the QGIS-Developer mailing list