[英]How to add fields to postgis layer loaded in qgis
I have loaded the layer from Postgis in qgis and i am adding the fields to the layer using the follo code snippet: 我已经从qgis中的Postgis加载了该层,并使用以下代码段将字段添加到了该层:
canvas = qgis.utils.iface.mapCanvas()
aLayer = canvas.currentLayer()
field_name = "test"
aLayer.startEditing()
if not field_name in fieldnames:
res = aLayer.dataProvider().addAttributes([QgsField(field_name, QVariant.String)])
aLayer.updateFields()
aLayer.commitChanges()
but it is not adding the field to the layer. 但它不会将字段添加到图层中。 What i have to do if i want to add the fields to the layer.
如果我想将字段添加到图层,该怎么办。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.