[Qgis-developer] python plugins - how to subset a layer

Martin Dobias wonder.sk at gmail.com
Mon Dec 7 12:38:45 EST 2009

Hi Ricardo

On Sun, Dec 6, 2009 at 8:52 PM, Ricardo Filipe Soares Garcia da
<ricardo.garcia.silva at gmail.com> wrote:
> I'd like to ask some questions:
> 1 - Can I subset a vector layer so that only some features get loaded?
> What I mean is using the same kind of functionality that the "subset"
> text area on the "general" tab of the "layer properties" dialog
> allows. I have searched the API for something like this, but couldn't
> find it. Maybe I'm not well familiarized with it yet. can someone
> point me to the right classes/methods?

Yes, you can use QgsVectorLayer::setSubsetString() string. That's
exactly what's used for setting subsets in vector layer properties
dialog. It however works currently only with layers from PostGIS,
SpatiaLite and OGR providers.

> 2 - Alternatively, can I selectively hide some features from the
> canvas? I have seen that there is a class called QgsFeatureRendererV2
> that has a renderFeature member function. Will I be able to use this
> through the python plugins interface?

Hiding features by not drawing them is also an option, though I
wouldn't recommend it to you as it would bring many new problems (e.g.
there are currently two implementation of vector layer renderers -
QgsRenderer and QgsFeatureRendererV2). I think you don't want to go
this way...

> I hope my plugin turns out to be not very crappy and that I can
> release it to the world!

Good luck and don't forget to give us a note about the plugin once it's ready!


More information about the Qgis-developer mailing list