[Qgis-developer] QgsFeatureRequest::FilterType are mutually exclusive

Alessandro Pasotti apasotti at gmail.com
Mon Apr 27 23:45:47 PDT 2015


2015-04-27 17:55 GMT+02:00 Matthias Kuhn <matthias at opengis.ch>:

> Hi all,
>
> I am currently working on an "expression compiler". This will allow to
> execute (some) expressions server side. Currently postgres is the main
> target but it can be adapted to others as well. This makes it very easy
> to write provider-independent code that is able to make use of database
> indexes, reduce network traffic and relocate CPU usage to a server. I
> will write more about this later.
>
> One thing that I am currently working on is to apply this to the
> rule-based renderer. Especially for small-scale situations where a lot
> of features are in the visible extent but only a small fraction meeting
> certain criteria shall be rendered this can improve rendering speed.
>
> The problem that I am currently facing is, that the feature request does
> not allow combining a filterRect (extent) and an expression, since you
> can either set the request to filter by extent OR by expression.
>

> I thought about removing the FilterRect type and instead always combine
> it with the active filter type. E.g. if the filterType is
> filterExpression "class = 2" and a rect is set the two clauses will be
> joined by an AND. This may change the behavior of existing code in some
> cases but probably not much. Worse is that all providers will need to be
> revised to change this behavior...
> Another option would be to set the filterType to Expression and append
> an "AND INTERSECTS ..." to the expression. Probably this has to be done
> conditionally only for providers that can compile expressions because
> such a solution would bypass spatial indexes that work with filterRect
> (but not with the INSERSECTS operator).
>
> I am trying not to overcomplicate this. Are there any opinions, ideas,
> caveats, etc. that others can think of?
>
> Thank you for any feedback,
> Matthias
>
>

Hello Mathias,

Given the two options (and ignoring how much effort is required to change
the providers accordingly), I would suggest the first one, this is the way
most ORM work, you can add several filters and they are combined with AND
to create the final one. It might be worth ordering the filters by type, I
would expect that the expression filter is applied after the spatial filter.
I don't know if it makes much sense in this context but most of the times,
the filtering mechanism I'm talking about allows for multiple filters to be
added in sequence, for example:

QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1))
QgsFeatureRequest().setFilterExpression("country = 'IT'")
QgsFeatureRequest().setFilterExpression("region = Piedmont'")

that would mean filtering first by bbox and then by "country = 'IT' and
region = 'Piedmont'"

BTW, is there any reason why the filter by expression is not listed in the
details of the class documentation?

http://qgis.org/api/classQgsFeatureRequest.html#details

-- 
Alessandro Pasotti
w3:   www.itopen.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150428/7d6c7a32/attachment.html>


More information about the Qgis-developer mailing list