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

Alexandre Neto senhor.neto at gmail.com
Fri Feb 8 08:38:44 PST 2013


Thank you Vinayan.

Based on your code, I was able to make it work like this:

new_attributes = layer.pendingFields()
for j in new_attributes:
    if provider.defaultValue(j).isNull():
        new_attributes[j] = feature.attributeMap()[j]
    else:
        new_attributes[j] = provider.defaultValue(j)

And I will try to use On Fly Reprojection too.

Thanks again,

Alexandre Neto

On Wed, Feb 6, 2013 at 2:42 AM, vinayan <vinayan123 at gmail.com> wrote:

> 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.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130208/1147c7bd/attachment.html>


More information about the Qgis-developer mailing list