[Qgis-developer] Get list of dirty features and their attributes

Ivan Minčík ivan.mincik at gmail.com
Wed Dec 5 13:17:06 PST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/30/2012 03:45 PM, Martin Dobias wrote:
> Hi Ivan
> 
> On Thu, Nov 29, 2012 at 2:15 PM, Ivan Mincik
> <ivan.mincik at gmail.com <mailto:ivan.mincik at gmail.com>> wrote:
> 
> Hi, sure you know this - when editing/adding multiple features to
> layer and pressing 'save' button an error message appears because
> of some database constraint violation or invalid data type in
> attribute table. There is very hard to find out a problematic
> features when many of them where changed or added.
> 
> We wrote a small Python console script to print all dirty features
> with their attributes and WKT geometry:
> 
> # QGIS 1.7, 1.8, author: Marcel Dancak, Gista s.r.o. layer =
> qgis.utils.iface.activeLayer() map = qgis.utils.iface.mapCanvas() 
> layer.select(map.fullExtent(), False) fields =
> layer.dataProvider().fields() features = layer.selectedFeatures()
> 
> # filter only new features features = [f for f in features if f.id
> <http://f.id>() < 0] for f in features: attribs =
> dict([(unicode(fields[k].name().toUtf8()), 
> unicode(v.toString().toUtf8())) for k, v in 
> f.attributeMap().iteritems()]) print f.id <http://f.id>(), attribs,
> f.geometry().type(), f.geometry().exportToWkt()
> 
> 
> Are you interested just in newly added features or any "dirty"
> features, i.e. also changed features and removed features? Because
> the above would work just for new features. Currently it's not
> possible to access uncommitted changes... but in theory you could
> still iterate over vector layer and then iterate through its data
> provider and compare the results to detect all changes.
> 
> If you decide to create a plugin, you could listen to signals from 
> QgsVectorLayer (featureAdded, featureDeleted and others) to
> immediately detect any changes.
> 
> In general, any tools that would lead to easier detection of
> problems would be welcome.

Martin, thanks for Your comments. So we have two possibilities:
1. Check features for id < 0 and add changed features by comparing
current state to data provides which can be very expensive in case of
big layers.

2. To listen to signals of all existing layers in canvas which can be
very tricky in case of removing and adding layers.

Ivan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJQv7nSAAoJEPfdLsR5UpoeXYAH/229Eh746Tr4EVVQJw/q4lY3
CYnS9vzQxJ71Hy2jlLGKo1t3BTUTbl3SVQ7M6F3VVJO0c3RqYZw8RZj/GL/wBH94
8KeMpZZtW7pG0MY7AT/zV0r8XpIrwhf0n90q/xiCl+HtovnJG7uNl417fLpoOqqX
7MiuWZdW1nxMhhTQImWbldqNgrY4kRufyPkn5xyXqffJLZ3N8AL3KAvrCorjMk3s
qZzR7Fl+J19qSVEg9VgvXzp/K4woHaPpU1bXkYcPnXMcHNAraFyxvJE09PBHzSs0
LZ5emOvLu1u6dmfEc6Z0/VcHB53XNpH7wzUy7DUwbyEvbcrrzfs3gzBb2a7m3DI=
=6NE7
-----END PGP SIGNATURE-----


More information about the Qgis-developer mailing list