Is it possible to save layer as dbf? Or even better convert .csv to .dbf? I have some .csv files, no geometry just attributes and I need it as .dbf as I want to edit them (I found that Qgis doesn't support editing .csv files). And I need to do it in pyQGis. I can do it in QGIS (simple Save layer as...)
So I solved it. It wasn't that hard. I open csv as "delimitedText" layer. Then I save this layer as "ESRI Shapefile". There is a trick. It fails to save, but it creates a .dbf file. Then I load it back as "ogr" file.
pos_csv = QgsVectorLayer("file:///"+folder_name+'/pos_file.csv',"Layer Name","delimitedtext") QgsVectorFileWriter.writeAsVectorFormat(pos_csv, folder_name+'/pos', "System", None,"ESRI Shapefile") new_pos = QgsVectorLayer(folder_name+'/pos.dbf',"Layer Name","ogr") QgsMapLayerRegistry.instance().addMapLayer(new_pos)
there are few (paid and free) third party programs you can use to convert csv to dbf (just google csv to dbf) and a few (free) online tools.
last depending on your level of comfort with python there are a few resources https://stackoverflow.com/questions/3897694/python-convert-csv-to-dbf https://stackoverflow.com/questions/4440791/convert-csv-file-into-dbf-using-python converting csv to dbf