[Qgis-developer] Remove Feature

Martin Dobias wonder.sk at gmail.com
Thu Mar 1 15:28:54 EST 2012

On Tue, Feb 28, 2012 at 5:25 PM, Alexandre Badez
<alexandre.badez at gmail.com> wrote:
> So... I get a look in the C++ code.. here is what I've found in
> src/core/qgsvectordataprovider.cpp.
>    bool QgsVectorDataProvider::addFeatures( QgsFeatureList &flist )
>    {
>       Q_UNUSED( flist );
>       return false;
>    }
>    bool QgsVectorDataProvider::deleteFeatures( const QgsFeatureIds &ids )
>    {
>       Q_UNUSED( ids );
>       return false;
>    }

The actual implementation is in classes derived from
QgsVectorDataProvider. Each data provider that allows adding/deleting
features has its own logic.

> So here is my questions:
>    * My python code hat use the data provider "work" as expected (it
> display something) but if I do this:
>        self._layer.addFeatures([v for v in self._object_map.itervalues()])
>    it do not work (do not display anything).
>    Why ??

Using data providers directly for adding/deleting features should
work. If it does not, please check return values from the functions
and provider's result from errors() method. It is also possible that
the provider you are using does not support adding/deleting - check
its capabilities first.

Using QgsVectorLayer's add/delete features functionality requires you
to first start editing, then do editing calls and finally commit the
changes. Vector layer has a buffer that records the changes and allows
you to do undo/redo or rollback all changes. When committing the
changes the actual add/delete functions from provider are called that
permanently modify the data.

> By the way, I also check the code on SVN, (qgsvectorlayer v15857 and
> qgsvectordataprovider v15197) and the code is similar to the one on
> doxygen.

Wait! We have not been using SVN for quite some time! We are on git now:


More information about the Qgis-developer mailing list