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

Ivan Mincik ivan.mincik at gmail.com
Thu Nov 29 05:15:33 PST 2012


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()


Do you know better way to solve this problem ? If not, is it worth to
put it in to plugin ?




-- 
Ivan Mincik


More information about the Qgis-developer mailing list