I am trying to write out a CSV file from a vector layer made up of points using the python console in QGIS. I've tried the following command:

QgsVectorFileWriter.writeAsVectorFormat(layer_Map, Folder + "my_shapes.csv", "CP1250", None, "delimitedtext")

but it does not like the delimitedtext parameter (if I use ESRI Shapefile it works fine). I have not been able to determine what other options can be used instead of ESRI Shapefile.

I find the Quantum GIS API documentation to be quite confusing, but I hope I will get used to it soon.

Thanks in advance for any help.

  • Are you getting an error message? If so, please edit your question to include the error. – user3461 Mar 20 '13 at 16:17
  • No error message, but the number 1 is returned, meaning that the action was not successful. If I use the ESRI Shapefile option the action returns 0 (i.e. successful) – Dom Mar 20 '13 at 16:22

Just use the "CSV" argument :

currentLayer = qgis.utils.iface.mapCanvas().layers()[0]
QgsVectorFileWriter.writeAsVectorFormat(currentLayer, csvpath, "CP1250", None, "CSV")

I get the 0 exit code, and the CSV file is well created :)

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.