[Qgis-developer] How to get Provider default values for each attribute using Python

vinayan vinayan123 at gmail.com
Tue Feb 5 18:42:47 PST 2013


Hi Alexandre,

I recently used provider default values in a plugin like this..

provider = layer.dataProvider()
        f = QgsFeature()
        
        #On the Fly reprojection.
        if layerCRSSrsid != projectCRSSrsid:
            geom.transform(QgsCoordinateTransform(projectCRSSrsid,
layerCRSSrsid))
                                    
        f.setGeometry(geom)
        
        # add attribute fields to feature
        fields = layer.pendingFields()

        # vector api change update
        if QGis.QGIS_VERSION_INT >= 10900:
            f.initAttributes(fields.count())			
            for i in range(fields.count()):
                f.setAttribute(i,provider.defaultValue(i))
        else:
            for i in fields:
                f.addAttribute(i,  provider.defaultValue(i))



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/How-to-get-Provider-default-values-for-each-attribute-using-Python-tp5032168p5032343.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list