[Qgis-developer] How to get feature frome deleted feature?

Jürgen E. Fischer jef at norbit.de
Tue May 19 07:08:02 PDT 2015


Hi Enrico,

On Tue, 19. May 2015 at 14:38:35 +0200, Enrico Fiore wrote:
> layer.committedFeaturesRemoved.connect(ConfirmTratDeleted)
> 
> def ConfirmTratDeleted(layer,fids):
>         for fid in fids:
>             iter = layer.getFeatures(QgsFeatureRequest().setFilterFid(fid))
>             feat = iter.next()
>             geometry = feat.geometry()
> 
> but it returned thi error:
> 
>     An error has occured while executing Python code:
> 
>     Traceback (most recent call last):
>      File "", line 234, in ConfirmTratDeleted
>      StopIteration
> 
> I suppose because the features are committed and don't exist anymore.
> 
> Somebody can help me to understand how to get features that were deleted?

committedFeaturesRemoved notifies you that the feature were actually removed -
so they don't exists anymore.  But you can use the featureDeleted signal
that provides a feature id of a (to be) deleted feature and use that
to fetch it from the provider (layer.dataProvider().getFeatures...)

If you actually need the features after the are actually deleted, you can
store them in the featureDeleted slot and use the saved copy to in your
committedFeaturesRemoved slot.



Jürgen

-- 
Jürgen E. Fischer           norBIT GmbH             Tel. +49-4931-918175-31
Dipl.-Inf. (FH)             Rheinstraße 13          Fax. +49-4931-918175-50
Software Engineer           D-26506 Norden             http://www.norbit.de
QGIS release manager (PSC)  Germany                    IRC: jef on FreeNode                         
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150519/787fc451/attachment.pgp>


More information about the Qgis-developer mailing list