I have created my first ever plugin in QGIS 2.10.1 Pisa, and the layer loads fine, but after two days of trying, I cannot get the plugin to also add a field. The following code in the "def run(self):" section doesn't cause any error, but also does not add the field. Can anyone tell me what I'm doing wrong here, please?

filename = self.dlg.lineEdit.text()
uri="file:///"+filename+"?"+"delimiter=%s&xField=%s&yField=%s"%("\t", "Set Grid Easting", "Set Grid Northing")
vlayer = QgsVectorLayer(uri, "SpreadTests", "delimitedtext")

vpr = vlayer.dataProvider()
vpr.addAttributes([QgsField("Testing", QVariant.Double)])
  • 1
    Do delimited text data providers support attribute additions? I think you can check by printing capabilities : "vlayer.dataProvider().capabilitiesString()" Commented Oct 11, 2015 at 18:08

1 Answer 1


CSV layers are note editable (due to OGR driver limitations). You can check the source of the Editable GeoCSV plugin to see what they are doing to work around this.

  • Thanks for your help with that, Jono and Underdark - I guess I may look at using python to edit the file before import, or would another workaround possibly be to save it as a shapefile and edit that?
    – AlPhuket
    Commented Oct 12, 2015 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.