4

I have a large quantity (200+) of GeoPackage files, and I want to export the attributes table of all of them to CSV's. Is there a way I can do that in the GUI or with a Plugin for QGIS 3.16.15?

Alternatively, is there a Python script I can use to export them? I'm not too comfortable with Python so would prefer a Plugin if it exists, but if not I can run the Python script & input the file path/destination folder.

1

2 Answers 2

6

To export all layers opened in QGIS i created this little Python script:

from qgis.core import *

#Put your folder where you want your CSV exported to here
 pathToFile = "C:/Path/To/Export/Folder/"
 layers = QgsProject.instance().mapLayers().values()
 for lyr in layers:
     newName = lyr.name() + ".csv"
     save_options = QgsVectorFileWriter.SaveVectorOptions()
     save_options.driverName = "CSV"
     save_options.fileEncoding = "UTF-8"
     transform_context = QgsProject.instance().transformContext()
     ret = QgsVectorFileWriter.writeAsVectorFormatV2(lyr, pathToFile + newName, transform_context,save_options)
1
  • This works, is there a way to adapt this to keep only certain fields in the layer?
    – DoubleD
    Jan 24 at 15:35
3

Try Convert format, executed with "Run as Batch Process"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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