0

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...)

underdark
84.9k22 gold badges237 silver badges419 bronze badges
asked Aug 21, 2015 at 16:23

2 Answers 2

2

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)
answered Sep 3, 2015 at 18:21
-1

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.

Online: http://www.files-conversion.com/spreadsheet-converter.php http://dbfconv.com/

programs: http://www.dbf2002.com/csv-converter/convert-csv-to-dbf.html http://dbfview.com/csv-dbf.html

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

good luck

answered Aug 21, 2015 at 16:36
1
  • Thanks, but not exactly what I was looking for. I need it in plugin, so any online tools aren't acceptable. I could use dbf modul, but it isn't standart python modul, so it would complicate things. I thought that when QGIS can do it directly, why shouldn't I in pyQGis. There is option in Save layer as "dbf"... Commented Aug 21, 2015 at 18:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.