I'm trying to add the attribute $area. I made a intersection and Tot_aera isn't the good one, so I want to add a new.
I made that :
from PyQt4.QtCore import *
try:
if ind==-1:
if caps & QgsVectorDataProvider.AddAttributes:
res=provider.addAttributes( [ QgsField(nameattr,QVariant.Double) ] )
except:
print "FALSE"
So I have a new attribute but NULL. So my question : How put "$area" in nameattr?
addAttributeonly creates a new field, it doesn't fill it. I suggest you have a look at this post: Add area column using PyQGIS. – ArMoraer Mar 15 '16 at 10:24