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

Martin Dobias wonder.sk at gmail.com
Fri Nov 30 06:45:49 PST 2012


Hi Ivan

On Thu, Nov 29, 2012 at 2:15 PM, Ivan Mincik <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() < 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(), 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.

Regards
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20121130/3910f940/attachment.html>


More information about the Qgis-developer mailing list